Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When the spec field of the ApisixUpstream resource is empty, it … #794

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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