Repository: zalando-incubator/kube-ingress-aws-controller
Pull request #292 (2019-11-12 09:41:25)

Do not ignore empty ingress class
This PR solves #291 

coveralls: 
[![Coverage Status](https://coveralls.io/builds/26932103/badge)](https://coveralls.io/builds/26932103)

Coverage increased (+0.02%) to 49.107% when pulling **9f712bb1ceee497f65d1563736f858bd4964102c on dintel:master** into **5af851ebe943fda510775cbfc3f086355362a2f2 on zalando-incubator:master**.

mikkeloscar: Thanks for the PR. would you mind adding a test case covering this?
dintel: @mikkeloscar Done, please review.
szuecs: Only nits, but please fix them, thanks!
dintel: Also reworded commit messages to reference correct issue number.
mikkeloscar: :+1: 

Patch:
diff --git a/.travis.yml b/.travis.yml
index 06e6c09..6298a3e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,7 +14,7 @@ matrix:
   - go: tip
 
 env:
-  GOLANGCI_RELEASE="v1.19.1"
+  GOLANGCI_RELEASE="v1.21.0"
 
 before_install:
 - GO111MODULE=off go get github.com/mattn/goveralls
diff --git a/README.md b/README.md
index 5e07a58..667817f 100644
--- a/README.md
+++ b/README.md
@@ -420,6 +420,7 @@ This value will be used to tag those resources.
 If you don't pass an ID, the default `kube-ingress-aws-controller` will be used.
 
 Usually you would want to combine this flag with `ingress-class-filter` so different types of ingresses are associated with the different controllers.
+To make `kube-ingress-aws-controller` manage both specific ingress class and an empty one (or ingresses without ingress class annotation) add an empty class to the list. For example to manage ingress class `foo` and ingresses without class set parameter like this `--ingress-class-filter=foo,` (notice the comma in the end).
 
 ## Target and Health Check Ports
 
diff --git a/kubernetes/adapter.go b/kubernetes/adapter.go
index a866f93..9f5903c 100644
--- a/kubernetes/adapter.go
+++ b/kubernetes/adapter.go
@@ -217,11 +217,9 @@ func (a *Adapter) ListIngress() ([]*Ingress, error) {
 		ret = make([]*Ingress, 0)
 		for _, ingress := range il.Items {
 			ingressClass := ingress.getAnnotationsString(ingressClassAnnotation, "")
-			if ingressClass != "" {
-				for _, v := range a.ingressFilters {
-					if v == ingressClass {
-						ret = append(ret, a.newIngressFromKube(ingress))
-					}
+			for _, v := range a.ingressFilters {
+				if v == ingressClass {
+					ret = append(ret, a.newIngressFromKube(ingress))
 				}
 			}
 		}


Test patch:
diff --git a/kubernetes/adapter_test.go b/kubernetes/adapter_test.go
index d4eb934..23da31e 100644
--- a/kubernetes/adapter_test.go
+++ b/kubernetes/adapter_test.go
@@ -306,3 +306,75 @@ func TestAdapter_GetConfigMap(t *testing.T) {
 		t.Error("expected an error")
 	}
 }
+
+func TestListIngressFilterClass(t *testing.T) {
+	for name, test := range map[string]struct {
+		ingressClassFilters  []string
+		expectedIngressNames []string
+	}{
+		"emptyIngressClassFilters": {
+			ingressClassFilters: nil,
+			expectedIngressNames: []string{
+				"fixture01",
+				"fixture02",
+				"fixture03",
+			},
+		},
+		"emptyIngressClassFilters2": {
+			ingressClassFilters: []string{},
+			expectedIngressNames: []string{
+				"fixture01",
+				"fixture02",
+				"fixture03",
+			},
+		},
+		"singleIngressClass1": {
+			ingressClassFilters: []string{"skipper"},
+			expectedIngressNames: []string{
+				"fixture02",
+			},
+		},
+		"singleIngressClass2": {
+			ingressClassFilters: []string{"other"},
+			expectedIngressNames: []string{
+				"fixture03",
+			},
+		},
+		"multipleIngressClass": {
+			ingressClassFilters: []string{"skipper", "other"},
+			expectedIngressNames: []string{
+				"fixture02",
+				"fixture03",
+			},
+		},
+		"multipleIngressClassWithDefault": {
+			ingressClassFilters: []string{"skipper", ""},
+			expectedIngressNames: []string{
+				"fixture01",
+				"fixture02",
+			},
+		},
+		"multipleIngressClassWithDefault2": {
+			ingressClassFilters: []string{"other", ""},
+			expectedIngressNames: []string{
+				"fixture01",
+				"fixture03",
+			},
+		},
+	} {
+		t.Run(name, func(t *testing.T) {
+			a, _ := NewAdapter(testConfig, test.ingressClassFilters, testIngressDefaultSecurityGroup, testSSLPolicy, testLoadBalancerTypeAWS)
+			client := &mockClient{}
+			a.kubeClient = client
+			ingresses, err := a.ListIngress()
+			if err != nil {
+				t.Error(err)
+			}
+			ingressNames := make([]string, len(ingresses))
+			for i, ing := range ingresses {
+				ingressNames[i] = ing.Name
+			}
+			assert.ElementsMatch(t, test.expectedIngressNames, ingressNames, "ingress names mismatch")
+		})
+	}
+}