Skip to content

Commit 2d0b9bb

Browse files
committed
fix: network null pointer exceptions
Signed-off-by: wangyizhi1 <[email protected]>
1 parent e923865 commit 2d0b9bb

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

pkg/apis/kosmos/v1alpha1/cluster_types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ type ClusterSpec struct {
3636
ImageRepository string `json:"imageRepository,omitempty"`
3737

3838
// +optional
39-
ClusterLinkOptions ClusterLinkOptions `json:"clusterLinkOptions,omitempty"`
39+
ClusterLinkOptions *ClusterLinkOptions `json:"clusterLinkOptions,omitempty"`
4040

4141
// +optional
42-
ClusterTreeOptions ClusterTreeOptions `json:"clusterTreeOptions,omitempty"`
42+
ClusterTreeOptions *ClusterTreeOptions `json:"clusterTreeOptions,omitempty"`
4343
}
4444

4545
type ClusterStatus struct {
4646
// ClusterLinkStatus contain the cluster network information
4747
// +optional
48-
ClusterLinkStatus ClusterLinkStatus `json:"clusterLinkStatus,omitempty"`
48+
ClusterLinkStatus *ClusterLinkStatus `json:"clusterLinkStatus,omitempty"`
4949

5050
// ClusterTreeStatus contain the member cluster leafNode end status
5151
// +optional
52-
ClusterTreeStatus ClusterTreeStatus `json:"clusterTreeStatus,omitempty"`
52+
ClusterTreeStatus *ClusterTreeStatus `json:"clusterTreeStatus,omitempty"`
5353
}
5454

5555
type ClusterLinkOptions struct {
@@ -173,9 +173,15 @@ type ClusterList struct {
173173
}
174174

175175
func (c *Cluster) IsP2P() bool {
176+
if c.Spec.ClusterLinkOptions == nil {
177+
return false
178+
}
176179
return c.Spec.ClusterLinkOptions.NetworkType == NetworkTypeP2P
177180
}
178181

179182
func (c *Cluster) IsGateway() bool {
183+
if c.Spec.ClusterLinkOptions == nil {
184+
return false
185+
}
180186
return c.Spec.ClusterLinkOptions.NetworkType == NetWorkTypeGateWay
181187
}

pkg/apis/kosmos/v1alpha1/zz_generated.deepcopy.go

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/clusterlink/network-manager/handlers/pod_routes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,17 @@ func BuildRoutes(ctx *Context, target *v1alpha1.ClusterNode, cidrs []string) {
143143
}
144144

145145
gw := ctx.Filter.GetGatewayNodeByClusterName(n.Spec.ClusterName)
146+
if gw == nil {
147+
klog.Warning("cannot find gateway node, cluster name: %s", n.Spec.ClusterName)
148+
continue
149+
}
150+
146151
gwDev := ctx.GetDeviceFromResults(gw.Name, vxLocal)
152+
if gwDev == nil {
153+
klog.Warning("cannot find the gw dev, nodeName: %s, devName: %s", gw.Name, vxLocal)
154+
continue
155+
}
156+
147157
gwIP, _, err := net.ParseCIDR(gwDev.Addr)
148158
if err != nil {
149159
klog.Warning("cannot parse gw dev addr, nodeName: %s, devName: %s", gw.Name, vxLocal)

pkg/clusterlink/network-manager/handlers/vxlocal_mac_cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ func (h *VxLocalMacCache) Do(c *Context) (err error) {
2020
for _, node := range nodes {
2121
ipTypes := h.getSupportIPTypes(node, c)
2222
gw := c.Filter.GetGatewayNodeByClusterName(node.Spec.ClusterName)
23+
if gw == nil {
24+
klog.Warning("cannot find gateway node, cluster name: %s", node.Spec.ClusterName)
25+
continue
26+
}
2327

2428
for _, ipType := range ipTypes {
2529
fdb, arp, err := h.buildVxLocalCachesByNode(c, ipType, gw)

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kosmosctl/join/join.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (o *CommandJoinOptions) runCluster() error {
215215
Kubeconfig: o.KubeConfigStream,
216216
Namespace: o.Namespace,
217217
ImageRepository: o.ImageRegistry,
218-
ClusterLinkOptions: v1alpha1.ClusterLinkOptions{
218+
ClusterLinkOptions: &v1alpha1.ClusterLinkOptions{
219219
Enable: o.EnableLink,
220220
BridgeCIDRs: v1alpha1.VxlanCIDRs{
221221
IP: "220.0.0.0/8",
@@ -228,7 +228,7 @@ func (o *CommandJoinOptions) runCluster() error {
228228
NetworkType: v1alpha1.NetWorkTypeGateWay,
229229
IPFamily: v1alpha1.IPFamilyTypeIPV4,
230230
},
231-
ClusterTreeOptions: v1alpha1.ClusterTreeOptions{
231+
ClusterTreeOptions: &v1alpha1.ClusterTreeOptions{
232232
Enable: o.EnableTree,
233233
},
234234
},

0 commit comments

Comments
 (0)