Skip to content

Commit

Permalink
fix: When the spec field of the ApisixUpstream resource is empty, it …
Browse files Browse the repository at this point in the history
…will panic
  • Loading branch information
byy committed Dec 13, 2021
1 parent 413e7ca commit 7711f65
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *apisixUpstreamController) sync(ctx context.Context, ev *types.Event) er
}

var portLevelSettings map[int32]*configv2beta3.ApisixUpstreamConfig
if len(au.Spec.PortLevelSettings) > 0 {
if au.Spec != nil && len(au.Spec.PortLevelSettings) > 0 {
portLevelSettings = make(map[int32]*configv2beta3.ApisixUpstreamConfig, len(au.Spec.PortLevelSettings))
for _, port := range au.Spec.PortLevelSettings {
portLevelSettings[port.Port] = &port.ApisixUpstreamConfig
Expand All @@ -135,7 +135,7 @@ func (c *apisixUpstreamController) sync(ctx context.Context, ev *types.Event) er

var subsets []configv2beta3.ApisixUpstreamSubset
subsets = append(subsets, configv2beta3.ApisixUpstreamSubset{})
if len(au.Spec.Subsets) > 0 {
if au.Spec != nil && len(au.Spec.Subsets) > 0 {
subsets = append(subsets, au.Spec.Subsets...)
}
clusterName := c.controller.cfg.APISIX.DefaultClusterName
Expand All @@ -154,7 +154,7 @@ func (c *apisixUpstreamController) sync(ctx context.Context, ev *types.Event) er
return err
}
var newUps *apisixv1.Upstream
if ev.Type != types.EventDelete {
if au.Spec != nil && ev.Type != types.EventDelete {
cfg, ok := portLevelSettings[port.Port]
if !ok {
cfg = &au.Spec.ApisixUpstreamConfig
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (c *Controller) syncEndpoint(ctx context.Context, ep kube.Endpoint) error {
log.Errorf("failed to get ApisixUpstream %s/%s: %s", ep.Namespace(), svcName, err)
return err
}
} else if len(au.Spec.Subsets) > 0 {
} else if au.Spec != nil && len(au.Spec.Subsets) > 0 {
subsets = append(subsets, au.Spec.Subsets...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/translation/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (t *translator) TranslateUpstream(namespace, name, subset string, port int3
if err != nil {
return nil, err
}
if au == nil {
if au == nil || au.Spec == nil {
ups.Nodes = nodes
return ups, nil
}
Expand Down

0 comments on commit 7711f65

Please sign in to comment.