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 1eee479  fix: nil pointer dereference (#529)
1eee479 is described below

commit 1eee479247404893cf5f4ae5ad78c6714a71f63c
Author: Jintao Zhang <[email protected]>
AuthorDate: Mon Jun 7 18:46:46 2021 +0800

    fix: nil pointer dereference (#529)
    
    Signed-off-by: Jintao Zhang <[email protected]>
---
 pkg/ingress/controller.go                     |  2 ++
 pkg/types/apisix/v1/types.go                  |  4 +++-
 samples/deploy/crd/v1beta1/kustomization.yaml |  1 +
 test/e2e/features/consumer.go                 | 12 +++++-------
 test/e2e/scaffold/k8s.go                      |  3 ++-
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/pkg/ingress/controller.go b/pkg/ingress/controller.go
index 1af6253..25afd2f 100644
--- a/pkg/ingress/controller.go
+++ b/pkg/ingress/controller.go
@@ -198,6 +198,7 @@ func (c *Controller) initWhenStartLeading() {
        c.apisixUpstreamLister = 
apisixFactory.Apisix().V1().ApisixUpstreams().Lister()
        c.apisixTlsLister = apisixFactory.Apisix().V1().ApisixTlses().Lister()
        c.apisixClusterConfigLister = 
apisixFactory.Apisix().V2alpha1().ApisixClusterConfigs().Lister()
+       c.apisixConsumerLister = 
apisixFactory.Apisix().V2alpha1().ApisixConsumers().Lister()
 
        c.translator = translation.NewTranslator(&translation.TranslatorOptions{
                PodCache:             c.podCache,
@@ -230,6 +231,7 @@ func (c *Controller) initWhenStartLeading() {
        c.apisixClusterConfigInformer = 
apisixFactory.Apisix().V2alpha1().ApisixClusterConfigs().Informer()
        c.secretInformer = kubeFactory.Core().V1().Secrets().Informer()
        c.apisixTlsInformer = 
apisixFactory.Apisix().V1().ApisixTlses().Informer()
+       c.apisixConsumerInformer = 
apisixFactory.Apisix().V2alpha1().ApisixConsumers().Informer()
 
        c.podController = c.newPodController()
        c.endpointsController = c.newEndpointsController()
diff --git a/pkg/types/apisix/v1/types.go b/pkg/types/apisix/v1/types.go
index 3c5ff47..9c27333 100644
--- a/pkg/types/apisix/v1/types.go
+++ b/pkg/types/apisix/v1/types.go
@@ -19,6 +19,7 @@ import (
        "encoding/json"
        "errors"
        "strconv"
+       "strings"
        "time"
 )
 
@@ -455,7 +456,8 @@ func ComposeConsumerName(namespace, name string) string {
        p := make([]byte, 0, len(namespace)+len(name)+1)
        buf := bytes.NewBuffer(p)
 
-       buf.WriteString(namespace)
+       // TODO If APISIX modifies the consumer name schema, we can drop this.
+       buf.WriteString(strings.Replace(namespace, "-", "_", -1))
        buf.WriteString("_")
        buf.WriteString(name)
 
diff --git a/samples/deploy/crd/v1beta1/kustomization.yaml 
b/samples/deploy/crd/v1beta1/kustomization.yaml
index 1a2b65c..356b080 100644
--- a/samples/deploy/crd/v1beta1/kustomization.yaml
+++ b/samples/deploy/crd/v1beta1/kustomization.yaml
@@ -20,3 +20,4 @@ resources:
   - ./ApisixUpstream.yaml
   - ./ApisixTls.yaml
   - ./ApisixClusterConfig.yaml
+  - ./ApisixConsumer.yaml
diff --git a/test/e2e/features/consumer.go b/test/e2e/features/consumer.go
index c009d4b..b4eade6 100644
--- a/test/e2e/features/consumer.go
+++ b/test/e2e/features/consumer.go
@@ -23,7 +23,7 @@ import (
 )
 
 var _ = ginkgo.Describe("ApisixConsumer", func() {
-       s := scaffold.NewDefaultScaffold()
+       s := scaffold.NewDefaultV2Scaffold()
 
        ginkgo.It("create basicAuth consumer using value", func() {
                ac := `
@@ -38,8 +38,7 @@ spec:
         username: foo
         password: bar
 `
-               err := s.CreateResourceFromString(ac)
-               assert.Nil(ginkgo.GinkgoT(), err, "creating ApisixConsumer")
+               assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ac), 
"creating ApisixConsumer")
 
                defer func() {
                        err := s.RemoveResourceByString(ac)
@@ -47,15 +46,14 @@ spec:
                }()
 
                // Wait until the ApisixConsumer create event was delivered.
-               time.Sleep(3 * time.Second)
+               time.Sleep(6 * time.Second)
 
                grs, err := s.ListApisixConsumers()
                assert.Nil(ginkgo.GinkgoT(), err, "listing consumer")
                assert.Len(ginkgo.GinkgoT(), grs, 1)
-               assert.Equal(ginkgo.GinkgoT(), grs[0].Username, 
"default_basicvalue")
                assert.Len(ginkgo.GinkgoT(), grs[0].Plugins, 1)
-               _, basicAuth := grs[0].Plugins["basic-auth"]
-               assert.Equal(ginkgo.GinkgoT(), basicAuth, map[string]string{
+               basicAuth, _ := grs[0].Plugins["basic-auth"]
+               assert.Equal(ginkgo.GinkgoT(), basicAuth, 
map[string]interface{}{
                        "username": "foo",
                        "password": "bar",
                })
diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go
index 2fd096d..1412f48 100644
--- a/test/e2e/scaffold/k8s.go
+++ b/test/e2e/scaffold/k8s.go
@@ -303,7 +303,8 @@ func (s *Scaffold) ListApisixConsumers() ([]*v1.Consumer, 
error) {
                return nil, err
        }
        err = cli.AddCluster(&apisix.ClusterOptions{
-               BaseURL: u.String(),
+               BaseURL:  u.String(),
+               AdminKey: s.opts.APISIXAdminAPIKey,
        })
        if err != nil {
                return nil, err

Reply via email to