From 56e9022fa7d546a767fca8b5a50cb82ff260fbb7 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Thu, 14 May 2020 13:13:00 +0200 Subject: [PATCH 01/10] Adding flag flags.go --- cli/ingress-controller/flags.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/ingress-controller/flags.go b/cli/ingress-controller/flags.go index f900351884..a8236041cb 100644 --- a/cli/ingress-controller/flags.go +++ b/cli/ingress-controller/flags.go @@ -59,9 +59,10 @@ type cliConfig struct { KongCustomEntitiesSecret string // Resource filtering - WatchNamespace string - IngressClass string - ElectionID string + WatchNamespace string + ForceIngressClass bool + IngressClass string + ElectionID string // Ingress Status publish resource PublishService string @@ -175,6 +176,8 @@ mode of Kong. Takes the form of namespace/name.`) // Resource filtering flags.String("watch-namespace", apiv1.NamespaceAll, `Namespace to watch for Ingress. Default is to watch all namespaces`) + flags.Bool("force-ingress-class", false, + `Forces the usage of ingress-class on Ingresses and Kong CRDs.`) flags.String("ingress-class", annotations.DefaultIngressClass, `Name of the ingress class to route through this controller.`) flags.String("election-id", "ingress-controller-leader", @@ -320,6 +323,7 @@ func parseFlags() (cliConfig, error) { // Resource filtering config.WatchNamespace = viper.GetString("watch-namespace") + config.ForceIngressClass = viper.GetBool("force-ingress-class") config.IngressClass = viper.GetString("ingress-class") config.ElectionID = viper.GetString("election-id") From 71667dc14a49c3aa6356933c473ffa4e295cbc9d Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Thu, 14 May 2020 22:21:36 +0200 Subject: [PATCH 02/10] Added flag --skip-empty-annotation to force usage of the kubernetes.io/ingress.class: 'kong' annotation. --- cli/ingress-controller/flags.go | 14 +++++------ cli/ingress-controller/main.go | 4 ++-- cli/ingress-controller/main_test.go | 2 +- docs/concepts/deployment.md | 1 + go.mod | 2 ++ go.sum | 13 ++++++++++ internal/ingress/annotations/annotations.go | 12 +++++----- .../ingress/annotations/annotations_test.go | 24 +++++++++++-------- internal/ingress/store/fake_store.go | 2 +- internal/ingress/store/store.go | 11 +++++---- 10 files changed, 54 insertions(+), 31 deletions(-) diff --git a/cli/ingress-controller/flags.go b/cli/ingress-controller/flags.go index a8236041cb..0c1cd8a447 100644 --- a/cli/ingress-controller/flags.go +++ b/cli/ingress-controller/flags.go @@ -59,10 +59,10 @@ type cliConfig struct { KongCustomEntitiesSecret string // Resource filtering - WatchNamespace string - ForceIngressClass bool - IngressClass string - ElectionID string + WatchNamespace string + SkipEmptyAnnotation bool + IngressClass string + ElectionID string // Ingress Status publish resource PublishService string @@ -176,8 +176,8 @@ mode of Kong. Takes the form of namespace/name.`) // Resource filtering flags.String("watch-namespace", apiv1.NamespaceAll, `Namespace to watch for Ingress. Default is to watch all namespaces`) - flags.Bool("force-ingress-class", false, - `Forces the usage of ingress-class on Ingresses and Kong CRDs.`) + flags.Bool("skip-empty-annotation", false, + `Skip non annotated Ingresses and Kong CRDs.`) flags.String("ingress-class", annotations.DefaultIngressClass, `Name of the ingress class to route through this controller.`) flags.String("election-id", "ingress-controller-leader", @@ -323,7 +323,7 @@ func parseFlags() (cliConfig, error) { // Resource filtering config.WatchNamespace = viper.GetString("watch-namespace") - config.ForceIngressClass = viper.GetBool("force-ingress-class") + config.SkipEmptyAnnotation = viper.GetBool("skip-empty-annotation") config.IngressClass = viper.GetString("ingress-class") config.ElectionID = viper.GetString("election-id") diff --git a/cli/ingress-controller/main.go b/cli/ingress-controller/main.go index 53d8ec3629..42bebf70a0 100644 --- a/cli/ingress-controller/main.go +++ b/cli/ingress-controller/main.go @@ -287,7 +287,7 @@ func main() { updateChannel := channels.NewRingChannel(1024) reh := controller.ResourceEventHandler{ UpdateCh: updateChannel, - IsValidIngresClass: annotations.IngressClassValidatorFunc(cliConfig.IngressClass), + IsValidIngresClass: annotations.IngressClassValidatorFunc(cliConfig.IngressClass, cliConfig.SkipEmptyAnnotation), } var informers []cache.SharedIndexInformer var cacheStores store.CacheStores @@ -366,7 +366,7 @@ func main() { runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync")) } - store := store.New(cacheStores, cliConfig.IngressClass) + store := store.New(cacheStores, cliConfig.IngressClass, cliConfig.SkipEmptyAnnotation) kong, err := controller.NewKongController(&controllerConfig, updateChannel, store) if err != nil { diff --git a/cli/ingress-controller/main_test.go b/cli/ingress-controller/main_test.go index 44b8a43221..3839e11603 100644 --- a/cli/ingress-controller/main_test.go +++ b/cli/ingress-controller/main_test.go @@ -76,7 +76,7 @@ func TestHandleSigterm(t *testing.T) { KubeClient: kubeClient, }, channels.NewRingChannel(1024), - store.New(store.CacheStores{}, conf.IngressClass), + store.New(store.CacheStores{}, conf.IngressClass, conf.SkipEmptyAnnotation), ) exitCh := make(chan int, 1) diff --git a/docs/concepts/deployment.md b/docs/concepts/deployment.md index 66e1b6c505..1d50b12222 100644 --- a/docs/concepts/deployment.md +++ b/docs/concepts/deployment.md @@ -264,6 +264,7 @@ There are a few different ways of accomplishing this: where any ingress resource that is not annotated is picked up. Therefore with different ingress class then `kong`, you have to use that ingress class with every Kong CRD object (plugin, consumer) which you use. + You can force the honoring of only `kong` ingress class using the flag `--skip-non-annotated=true`. - Namespace based isolation: Kong Ingress Controller supports a deployment option where it will satisfy Ingress resources in a specific namespace. With this model, one can deploy diff --git a/go.mod b/go.mod index 3d0ebad0bb..d3f75c025f 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,9 @@ require ( github.com/tidwall/gjson v1.2.1 github.com/tidwall/match v1.0.1 // indirect github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect + golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e + golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/pool.v3 v3.1.1 k8s.io/api v0.17.4 diff --git a/go.sum b/go.sum index 187450632b..0aea645248 100644 --- a/go.sum +++ b/go.sum @@ -462,6 +462,7 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= @@ -503,10 +504,14 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -532,6 +537,8 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI= golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= @@ -606,10 +613,16 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200115165105-de0b1760071a h1:bEJ3JL2YUH3tt9KX9dsy0WUF3WOrhjtNjK93o0svepY= golang.org/x/tools v0.0.0-20200115165105-de0b1760071a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97 h1:DAuln/hGp+aJiHpID1Y1hYzMEPP5WLwtZHPb50mN0OE= +golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ= diff --git a/internal/ingress/annotations/annotations.go b/internal/ingress/annotations/annotations.go index 885787eb07..831599ab25 100644 --- a/internal/ingress/annotations/annotations.go +++ b/internal/ingress/annotations/annotations.go @@ -49,7 +49,7 @@ const ( DefaultIngressClass = "kong" ) -func validIngress(ingressAnnotationValue, ingressClass string) bool { +func validIngress(ingressAnnotationValue, ingressClass string, skipEmptyAnnotation bool) bool { // we have 2 valid combinations // 1 - ingress with default class | blank annotation on ingress // 2 - ingress with specific class | same annotation on ingress @@ -57,7 +57,7 @@ func validIngress(ingressAnnotationValue, ingressClass string) bool { // and 2 invalid combinations // 3 - ingress with default class | fixed annotation on ingress // 4 - ingress with specific class | different annotation on ingress - if ingressAnnotationValue == "" && ingressClass == DefaultIngressClass { + if ingressAnnotationValue == "" && !skipEmptyAnnotation && ingressClass == DefaultIngressClass { return true } return ingressAnnotationValue == ingressClass @@ -66,22 +66,22 @@ func validIngress(ingressAnnotationValue, ingressClass string) bool { // IngressClassValidatorFunc returns a function which can validate if an Object // belongs to an the ingressClass or not. func IngressClassValidatorFunc( - ingressClass string) func(obj metav1.Object) bool { + ingressClass string, skipEmptyAnnotation bool) func(obj metav1.Object) bool { return func(obj metav1.Object) bool { ingress := obj.GetAnnotations()[ingressClassKey] - return validIngress(ingress, ingressClass) + return validIngress(ingress, ingressClass, skipEmptyAnnotation) } } // IngressClassValidatorFuncFromObjectMeta returns a function which // can validate if an ObjectMeta belongs to an the ingressClass or not. func IngressClassValidatorFuncFromObjectMeta( - ingressClass string) func(obj *metav1.ObjectMeta) bool { + ingressClass string, skipEmptyAnnotation bool) func(obj *metav1.ObjectMeta) bool { return func(obj *metav1.ObjectMeta) bool { ingress := obj.GetAnnotations()[ingressClassKey] - return validIngress(ingress, ingressClass) + return validIngress(ingress, ingressClass, skipEmptyAnnotation) } } diff --git a/internal/ingress/annotations/annotations_test.go b/internal/ingress/annotations/annotations_test.go index 55231d2dc3..5f47d719d1 100644 --- a/internal/ingress/annotations/annotations_test.go +++ b/internal/ingress/annotations/annotations_test.go @@ -27,16 +27,20 @@ import ( func TestIngressClassValidatorFunc(t *testing.T) { tests := []struct { - ingress string - controller string - isValid bool + ingress string + forceIngress bool + controller string + isValid bool }{ - {"", "", true}, - {"", "kong", true}, - {"kong", "kong", true}, - {"custom", "custom", true}, - {"", "killer", false}, - {"custom", "kong", false}, + {"", false, "", true}, + {"", false, "kong", true}, + {"", true, "kong", false}, + {"kong", false, "kong", true}, + {"kong", true, "kong", true}, + {"custom", false, "custom", true}, + {"", false, "killer", false}, + {"custom", false, "kong", false}, + {"custom", true, "kong", false}, } ing := &extensions.Ingress{ @@ -50,7 +54,7 @@ func TestIngressClassValidatorFunc(t *testing.T) { ing.SetAnnotations(data) for _, test := range tests { ing.Annotations[ingressClassKey] = test.ingress - f := IngressClassValidatorFunc(test.controller) + f := IngressClassValidatorFunc(test.controller, test.forceIngress) b := f(&ing.ObjectMeta) if b != test.isValid { t.Errorf("test %v - expected %v but %v was returned", test, test.isValid, b) diff --git a/internal/ingress/store/fake_store.go b/internal/ingress/store/fake_store.go index 81928f5d91..4a5a28cf14 100644 --- a/internal/ingress/store/fake_store.go +++ b/internal/ingress/store/fake_store.go @@ -140,7 +140,7 @@ func NewFakeStore( KnativeIngress: knativeIngressStore, }, - isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong"), + isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong", false), } return s, nil } diff --git a/internal/ingress/store/store.go b/internal/ingress/store/store.go index fe36c30690..a40f5f03e3 100644 --- a/internal/ingress/store/store.go +++ b/internal/ingress/store/store.go @@ -82,6 +82,8 @@ type Store struct { ingressClass string + skipEmptyAnnotation bool + isValidIngresClass func(objectMeta *metav1.ObjectMeta) bool } @@ -104,11 +106,12 @@ type CacheStores struct { } // New creates a new object store to be used in the ingress controller -func New(cs CacheStores, ingressClass string) Storer { +func New(cs CacheStores, ingressClass string, skipEmptyAnnotation bool) Storer { return Store{ - stores: cs, - ingressClass: ingressClass, - isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta(ingressClass), + stores: cs, + ingressClass: ingressClass, + skipEmptyAnnotation: skipEmptyAnnotation, + isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta(ingressClass, skipEmptyAnnotation), } } From f2a7a7ebcc2cc8e41879922514daa6cdf6f441ea Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Thu, 14 May 2020 22:37:04 +0200 Subject: [PATCH 03/10] Fixing docs --- docs/concepts/deployment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/concepts/deployment.md b/docs/concepts/deployment.md index 1d50b12222..15cf9138d3 100644 --- a/docs/concepts/deployment.md +++ b/docs/concepts/deployment.md @@ -264,7 +264,7 @@ There are a few different ways of accomplishing this: where any ingress resource that is not annotated is picked up. Therefore with different ingress class then `kong`, you have to use that ingress class with every Kong CRD object (plugin, consumer) which you use. - You can force the honoring of only `kong` ingress class using the flag `--skip-non-annotated=true`. + You can force the honoring of only `kong` ingress class using the flag `--skip-empty-annotation=true`. - Namespace based isolation: Kong Ingress Controller supports a deployment option where it will satisfy Ingress resources in a specific namespace. With this model, one can deploy From 3f42d7baaff2e0a22865a58c2333ccfc08184166 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 5 Jun 2020 09:46:38 +0200 Subject: [PATCH 04/10] Reverted go.mod and go.sum --- go.mod | 2 -- go.sum | 13 ------------- 2 files changed, 15 deletions(-) diff --git a/go.mod b/go.mod index d3f75c025f..3d0ebad0bb 100644 --- a/go.mod +++ b/go.mod @@ -27,9 +27,7 @@ require ( github.com/tidwall/gjson v1.2.1 github.com/tidwall/match v1.0.1 // indirect github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect - golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e - golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/pool.v3 v3.1.1 k8s.io/api v0.17.4 diff --git a/go.sum b/go.sum index 0aea645248..187450632b 100644 --- a/go.sum +++ b/go.sum @@ -462,7 +462,6 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= @@ -504,14 +503,10 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -537,8 +532,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI= golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= @@ -613,16 +606,10 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200115165105-de0b1760071a h1:bEJ3JL2YUH3tt9KX9dsy0WUF3WOrhjtNjK93o0svepY= golang.org/x/tools v0.0.0-20200115165105-de0b1760071a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97 h1:DAuln/hGp+aJiHpID1Y1hYzMEPP5WLwtZHPb50mN0OE= -golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ= From 8e5a39b2df8f5e159361534cc12aa5ef479fa843 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 5 Jun 2020 09:46:48 +0200 Subject: [PATCH 05/10] Reverted docs --- docs/concepts/deployment.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/concepts/deployment.md b/docs/concepts/deployment.md index 15cf9138d3..66e1b6c505 100644 --- a/docs/concepts/deployment.md +++ b/docs/concepts/deployment.md @@ -264,7 +264,6 @@ There are a few different ways of accomplishing this: where any ingress resource that is not annotated is picked up. Therefore with different ingress class then `kong`, you have to use that ingress class with every Kong CRD object (plugin, consumer) which you use. - You can force the honoring of only `kong` ingress class using the flag `--skip-empty-annotation=true`. - Namespace based isolation: Kong Ingress Controller supports a deployment option where it will satisfy Ingress resources in a specific namespace. With this model, one can deploy From 3341d8e57ee28af2c044f0b6d80be8a69cae1ac9 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 5 Jun 2020 10:09:01 +0200 Subject: [PATCH 06/10] Renamed flags, s/SkipEmptyAnnotation/SkipClasslessIngressV1beta1/g, s/skip-empty-annotation/skip-classless-ingress-v1beta1/g, s/skipEmptyAnnotation/skipClasslessIngress/g, s/forceIngress/skipClasslessIngress/g, go fmt, added one more test --- cli/ingress-controller/flags.go | 12 ++++++------ cli/ingress-controller/main.go | 4 ++-- cli/ingress-controller/main_test.go | 2 +- internal/ingress/annotations/annotations.go | 12 ++++++------ internal/ingress/annotations/annotations_test.go | 11 ++++++----- internal/ingress/store/store.go | 12 ++++++------ 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cli/ingress-controller/flags.go b/cli/ingress-controller/flags.go index 0c1cd8a447..75fb9244dc 100644 --- a/cli/ingress-controller/flags.go +++ b/cli/ingress-controller/flags.go @@ -59,10 +59,10 @@ type cliConfig struct { KongCustomEntitiesSecret string // Resource filtering - WatchNamespace string - SkipEmptyAnnotation bool - IngressClass string - ElectionID string + WatchNamespace string + SkipClasslessIngressV1beta1 bool + IngressClass string + ElectionID string // Ingress Status publish resource PublishService string @@ -176,7 +176,7 @@ mode of Kong. Takes the form of namespace/name.`) // Resource filtering flags.String("watch-namespace", apiv1.NamespaceAll, `Namespace to watch for Ingress. Default is to watch all namespaces`) - flags.Bool("skip-empty-annotation", false, + flags.Bool("skip-classless-ingress-v1beta1", false, `Skip non annotated Ingresses and Kong CRDs.`) flags.String("ingress-class", annotations.DefaultIngressClass, `Name of the ingress class to route through this controller.`) @@ -323,7 +323,7 @@ func parseFlags() (cliConfig, error) { // Resource filtering config.WatchNamespace = viper.GetString("watch-namespace") - config.SkipEmptyAnnotation = viper.GetBool("skip-empty-annotation") + config.SkipClasslessIngressV1beta1 = viper.GetBool("skip-classless-ingress-v1beta1") config.IngressClass = viper.GetString("ingress-class") config.ElectionID = viper.GetString("election-id") diff --git a/cli/ingress-controller/main.go b/cli/ingress-controller/main.go index 42bebf70a0..acad588c10 100644 --- a/cli/ingress-controller/main.go +++ b/cli/ingress-controller/main.go @@ -287,7 +287,7 @@ func main() { updateChannel := channels.NewRingChannel(1024) reh := controller.ResourceEventHandler{ UpdateCh: updateChannel, - IsValidIngresClass: annotations.IngressClassValidatorFunc(cliConfig.IngressClass, cliConfig.SkipEmptyAnnotation), + IsValidIngresClass: annotations.IngressClassValidatorFunc(cliConfig.IngressClass, cliConfig.SkipClasslessIngressV1beta1), } var informers []cache.SharedIndexInformer var cacheStores store.CacheStores @@ -366,7 +366,7 @@ func main() { runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync")) } - store := store.New(cacheStores, cliConfig.IngressClass, cliConfig.SkipEmptyAnnotation) + store := store.New(cacheStores, cliConfig.IngressClass, cliConfig.SkipClasslessIngressV1beta1) kong, err := controller.NewKongController(&controllerConfig, updateChannel, store) if err != nil { diff --git a/cli/ingress-controller/main_test.go b/cli/ingress-controller/main_test.go index 3839e11603..6ca9ab2c02 100644 --- a/cli/ingress-controller/main_test.go +++ b/cli/ingress-controller/main_test.go @@ -76,7 +76,7 @@ func TestHandleSigterm(t *testing.T) { KubeClient: kubeClient, }, channels.NewRingChannel(1024), - store.New(store.CacheStores{}, conf.IngressClass, conf.SkipEmptyAnnotation), + store.New(store.CacheStores{}, conf.IngressClass, conf.SkipClasslessIngressV1beta1), ) exitCh := make(chan int, 1) diff --git a/internal/ingress/annotations/annotations.go b/internal/ingress/annotations/annotations.go index 831599ab25..342b45d0ce 100644 --- a/internal/ingress/annotations/annotations.go +++ b/internal/ingress/annotations/annotations.go @@ -49,7 +49,7 @@ const ( DefaultIngressClass = "kong" ) -func validIngress(ingressAnnotationValue, ingressClass string, skipEmptyAnnotation bool) bool { +func validIngress(ingressAnnotationValue, ingressClass string, skipClasslessIngress bool) bool { // we have 2 valid combinations // 1 - ingress with default class | blank annotation on ingress // 2 - ingress with specific class | same annotation on ingress @@ -57,7 +57,7 @@ func validIngress(ingressAnnotationValue, ingressClass string, skipEmptyAnnotati // and 2 invalid combinations // 3 - ingress with default class | fixed annotation on ingress // 4 - ingress with specific class | different annotation on ingress - if ingressAnnotationValue == "" && !skipEmptyAnnotation && ingressClass == DefaultIngressClass { + if ingressAnnotationValue == "" && !skipClasslessIngress && ingressClass == DefaultIngressClass { return true } return ingressAnnotationValue == ingressClass @@ -66,22 +66,22 @@ func validIngress(ingressAnnotationValue, ingressClass string, skipEmptyAnnotati // IngressClassValidatorFunc returns a function which can validate if an Object // belongs to an the ingressClass or not. func IngressClassValidatorFunc( - ingressClass string, skipEmptyAnnotation bool) func(obj metav1.Object) bool { + ingressClass string, skipClasslessIngress bool) func(obj metav1.Object) bool { return func(obj metav1.Object) bool { ingress := obj.GetAnnotations()[ingressClassKey] - return validIngress(ingress, ingressClass, skipEmptyAnnotation) + return validIngress(ingress, ingressClass, skipClasslessIngress) } } // IngressClassValidatorFuncFromObjectMeta returns a function which // can validate if an ObjectMeta belongs to an the ingressClass or not. func IngressClassValidatorFuncFromObjectMeta( - ingressClass string, skipEmptyAnnotation bool) func(obj *metav1.ObjectMeta) bool { + ingressClass string, skipClasslessIngress bool) func(obj *metav1.ObjectMeta) bool { return func(obj *metav1.ObjectMeta) bool { ingress := obj.GetAnnotations()[ingressClassKey] - return validIngress(ingress, ingressClass, skipEmptyAnnotation) + return validIngress(ingress, ingressClass, skipClasslessIngress) } } diff --git a/internal/ingress/annotations/annotations_test.go b/internal/ingress/annotations/annotations_test.go index 5f47d719d1..27661fc9e9 100644 --- a/internal/ingress/annotations/annotations_test.go +++ b/internal/ingress/annotations/annotations_test.go @@ -27,10 +27,10 @@ import ( func TestIngressClassValidatorFunc(t *testing.T) { tests := []struct { - ingress string - forceIngress bool - controller string - isValid bool + ingress string + skipClasslessIngress bool + controller string + isValid bool }{ {"", false, "", true}, {"", false, "kong", true}, @@ -41,6 +41,7 @@ func TestIngressClassValidatorFunc(t *testing.T) { {"", false, "killer", false}, {"custom", false, "kong", false}, {"custom", true, "kong", false}, + {"", true, "custom", false}, } ing := &extensions.Ingress{ @@ -54,7 +55,7 @@ func TestIngressClassValidatorFunc(t *testing.T) { ing.SetAnnotations(data) for _, test := range tests { ing.Annotations[ingressClassKey] = test.ingress - f := IngressClassValidatorFunc(test.controller, test.forceIngress) + f := IngressClassValidatorFunc(test.controller, test.skipClasslessIngress) b := f(&ing.ObjectMeta) if b != test.isValid { t.Errorf("test %v - expected %v but %v was returned", test, test.isValid, b) diff --git a/internal/ingress/store/store.go b/internal/ingress/store/store.go index a40f5f03e3..66f755748d 100644 --- a/internal/ingress/store/store.go +++ b/internal/ingress/store/store.go @@ -82,7 +82,7 @@ type Store struct { ingressClass string - skipEmptyAnnotation bool + skipClasslessIngress bool isValidIngresClass func(objectMeta *metav1.ObjectMeta) bool } @@ -106,12 +106,12 @@ type CacheStores struct { } // New creates a new object store to be used in the ingress controller -func New(cs CacheStores, ingressClass string, skipEmptyAnnotation bool) Storer { +func New(cs CacheStores, ingressClass string, skipClasslessIngress bool) Storer { return Store{ - stores: cs, - ingressClass: ingressClass, - skipEmptyAnnotation: skipEmptyAnnotation, - isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta(ingressClass, skipEmptyAnnotation), + stores: cs, + ingressClass: ingressClass, + skipClasslessIngress: skipClasslessIngress, + isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta(ingressClass, skipClasslessIngress), } } From 32ba2e13ccd8070e23e3e82424401dbc3445fed2 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 5 Jun 2020 10:13:53 +0200 Subject: [PATCH 07/10] Fixing long line lint error --- cli/ingress-controller/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/ingress-controller/main.go b/cli/ingress-controller/main.go index acad588c10..833388dbc1 100644 --- a/cli/ingress-controller/main.go +++ b/cli/ingress-controller/main.go @@ -287,7 +287,9 @@ func main() { updateChannel := channels.NewRingChannel(1024) reh := controller.ResourceEventHandler{ UpdateCh: updateChannel, - IsValidIngresClass: annotations.IngressClassValidatorFunc(cliConfig.IngressClass, cliConfig.SkipClasslessIngressV1beta1), + IsValidIngresClass: annotations.IngressClassValidatorFunc( + cliConfig.IngressClass, + cliConfig.SkipClasslessIngressV1beta1), } var informers []cache.SharedIndexInformer var cacheStores store.CacheStores From 97629d8694d1364102e1603ed1209cd12a990ae8 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 5 Jun 2020 10:20:22 +0200 Subject: [PATCH 08/10] One more time linting fix --- cli/ingress-controller/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ingress-controller/main.go b/cli/ingress-controller/main.go index 833388dbc1..65abbe73ac 100644 --- a/cli/ingress-controller/main.go +++ b/cli/ingress-controller/main.go @@ -286,7 +286,7 @@ func main() { var synced []cache.InformerSynced updateChannel := channels.NewRingChannel(1024) reh := controller.ResourceEventHandler{ - UpdateCh: updateChannel, + UpdateCh: updateChannel, IsValidIngresClass: annotations.IngressClassValidatorFunc( cliConfig.IngressClass, cliConfig.SkipClasslessIngressV1beta1), From 823eaac533a57df9723f7263a898ac58dbdee6d4 Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 26 Jun 2020 08:15:43 +0200 Subject: [PATCH 09/10] Adding parameter SkipClasslessIngress on FakeObjects in fake_store.go --- internal/ingress/store/fake_store.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/ingress/store/fake_store.go b/internal/ingress/store/fake_store.go index 4a5a28cf14..bc5ac8aff2 100644 --- a/internal/ingress/store/fake_store.go +++ b/internal/ingress/store/fake_store.go @@ -26,16 +26,17 @@ func clusterResourceKeyFunc(obj interface{}) (string, error) { // FakeObjects can be used to populate a fake Store. type FakeObjects struct { - Ingresses []*networking.Ingress - TCPIngresses []*configurationv1beta1.TCPIngress - Services []*apiv1.Service - Endpoints []*apiv1.Endpoints - Secrets []*apiv1.Secret - KongPlugins []*configurationv1.KongPlugin - KongClusterPlugins []*configurationv1.KongClusterPlugin - KongIngresses []*configurationv1.KongIngress - KongConsumers []*configurationv1.KongConsumer - KongCredentials []*configurationv1.KongCredential + Ingresses []*networking.Ingress + TCPIngresses []*configurationv1beta1.TCPIngress + Services []*apiv1.Service + Endpoints []*apiv1.Endpoints + Secrets []*apiv1.Secret + KongPlugins []*configurationv1.KongPlugin + KongClusterPlugins []*configurationv1.KongClusterPlugin + KongIngresses []*configurationv1.KongIngress + KongConsumers []*configurationv1.KongConsumer + KongCredentials []*configurationv1.KongCredential + SkipClasslessIngress bool KnativeIngresses []*knative.Ingress } @@ -140,7 +141,7 @@ func NewFakeStore( KnativeIngress: knativeIngressStore, }, - isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong", false), + isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong", objects.SkipClasslessIngress), } return s, nil } From 90edd8e2444f91bc26070c11e5971696b20d493e Mon Sep 17 00:00:00 2001 From: Samuele Chiocca Date: Fri, 26 Jun 2020 08:31:20 +0200 Subject: [PATCH 10/10] Added integration test on parser_test.go : TestKongSkipClasslessIngress --- .../ingress/controller/parser/parser_test.go | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/internal/ingress/controller/parser/parser_test.go b/internal/ingress/controller/parser/parser_test.go index f6731f2e87..ae68903dac 100644 --- a/internal/ingress/controller/parser/parser_test.go +++ b/internal/ingress/controller/parser/parser_test.go @@ -1617,6 +1617,116 @@ func TestKongRouteAnnotations(t *testing.T) { }) } +func TestKongSkipClasslessIngress(t *testing.T) { + assert := assert.New(t) + t.Run("Kong classless ingress evaluated (true)", func(t *testing.T) { + ingresses := []*networking.Ingress{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: networking.IngressSpec{ + Rules: []networking.IngressRule{ + { + Host: "example.com", + IngressRuleValue: networking.IngressRuleValue{ + HTTP: &networking.HTTPIngressRuleValue{ + Paths: []networking.HTTPIngressPath{ + { + Path: "/", + Backend: networking.IngressBackend{ + ServiceName: "foo-svc", + ServicePort: intstr.FromInt(80), + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + services := []*corev1.Service{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "foo-svc", + Namespace: "default", + }, + }, + } + + store, err := store.NewFakeStore(store.FakeObjects{ + Ingresses: ingresses, + Services: services, + SkipClasslessIngress: false, + }) + assert.Nil(err) + parser := New(store) + state, err := parser.Build() + assert.Nil(err) + assert.NotNil(state) + + assert.Equal(1, len(state.Services), + "expected one service to be rendered") + }) + t.Run("Kong classless ingress evaluated (false)", func(t *testing.T) { + ingresses := []*networking.Ingress{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: networking.IngressSpec{ + Rules: []networking.IngressRule{ + { + Host: "example.com", + IngressRuleValue: networking.IngressRuleValue{ + HTTP: &networking.HTTPIngressRuleValue{ + Paths: []networking.HTTPIngressPath{ + { + Path: "/", + Backend: networking.IngressBackend{ + ServiceName: "foo-svc", + ServicePort: intstr.FromInt(80), + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + services := []*corev1.Service{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "foo-svc", + Namespace: "default", + }, + }, + } + + store, err := store.NewFakeStore(store.FakeObjects{ + Ingresses: ingresses, + Services: services, + SkipClasslessIngress: true, + }) + assert.Nil(err) + parser := New(store) + state, err := parser.Build() + assert.Nil(err) + assert.NotNil(state) + + assert.Equal(0, len(state.Services), + "expected zero service to be rendered") + }) +} + func TestKnativeIngressAndPlugins(t *testing.T) { assert := assert.New(t) t.Run("knative ingress rule and service-level plugin", func(t *testing.T) {