This is an automated email from the ASF dual-hosted git repository.

tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/master by this push:
     new d4c5b09  fix: When the spec field of the ApisixUpstream resource is 
empty, it will panic (#794)
d4c5b09 is described below

commit d4c5b093e95fca630f9a879111c3394fd1b12ec6
Author: Brhetty <[email protected]>
AuthorDate: Tue Dec 14 09:47:45 2021 +0800

    fix: When the spec field of the ApisixUpstream resource is empty, it will 
panic (#794)
    
    Co-authored-by: byy <[email protected]>
---
 pkg/ingress/apisix_upstream.go     | 6 +++---
 pkg/ingress/controller.go          | 2 +-
 pkg/kube/translation/translator.go | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pkg/ingress/apisix_upstream.go b/pkg/ingress/apisix_upstream.go
index 790ca33..3a1aab2 100644
--- a/pkg/ingress/apisix_upstream.go
+++ b/pkg/ingress/apisix_upstream.go
@@ -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
@@ -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
@@ -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
diff --git a/pkg/ingress/controller.go b/pkg/ingress/controller.go
index dc44239..917fd61 100644
--- a/pkg/ingress/controller.go
+++ b/pkg/ingress/controller.go
@@ -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...)
        }
 
diff --git a/pkg/kube/translation/translator.go 
b/pkg/kube/translation/translator.go
index 8d48bbc..a4d2ad5 100644
--- a/pkg/kube/translation/translator.go
+++ b/pkg/kube/translation/translator.go
@@ -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
        }

Reply via email to