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

Update remaining resource ingress.class behaviors #815

Merged
merged 8 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
69 changes: 44 additions & 25 deletions internal/ingress/controller/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/kong/go-kong/kong"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/annotations"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/store"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/utils"
configurationv1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1"
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestGlobalPlugin(t *testing.T) {
"global": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
rainest marked this conversation as resolved.
Show resolved Hide resolved
},
},
Protocols: []string{"http"},
Expand Down Expand Up @@ -198,7 +199,7 @@ func TestSecretConfigurationPlugin(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "foo-plugin",
rainest marked this conversation as resolved.
Show resolved Hide resolved
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -228,7 +229,7 @@ func TestSecretConfigurationPlugin(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "bar-plugin",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -279,7 +280,7 @@ func TestSecretConfigurationPlugin(t *testing.T) {
"global": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Protocols: []string{"http"},
Expand Down Expand Up @@ -712,6 +713,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
"id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"),
Expand Down Expand Up @@ -744,6 +748,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
"id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"),
Expand All @@ -757,6 +764,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
"id": []byte("570c28aa-e784-43c1-8ec7-ae7f4ce40189"),
Expand Down Expand Up @@ -785,6 +795,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
"id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"),
Expand All @@ -798,6 +811,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
"id": []byte("570c28aa-e784-43c1-8ec7-ae7f4ce40189"),
Expand All @@ -811,6 +827,9 @@ func TestCACertificate(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Data: map[string][]byte{
// id is missing
Expand Down Expand Up @@ -845,7 +864,7 @@ func TestServiceClientCertificate(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -927,7 +946,7 @@ func TestServiceClientCertificate(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1313,7 +1332,7 @@ func TestKongRouteAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"konghq.com/preserve-host": "faLsE",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1391,7 +1410,7 @@ func TestKongRouteAnnotations(t *testing.T) {
Name: "bar",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
"konghq.com/preserve-host": "wiggle wiggle wiggle",
},
},
Expand Down Expand Up @@ -1471,7 +1490,7 @@ func TestKongRouteAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"konghq.com/regex-priority": "10",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1550,7 +1569,7 @@ func TestKongRouteAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"konghq.com/regex-priority": "IAmAString",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1631,7 +1650,7 @@ func TestKongProcessClasslessIngress(t *testing.T) {
Name: "bar",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1867,7 +1886,7 @@ func TestKongServiceAnnotations(t *testing.T) {
Name: "bar",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -1948,7 +1967,7 @@ func TestKongServiceAnnotations(t *testing.T) {
Name: "bar",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2038,7 +2057,7 @@ func TestKongServiceAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"konghq.com/methods": "POST,GET",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2120,7 +2139,7 @@ func TestDefaultBackend(t *testing.T) {
Name: "ing-with-default-backend",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2166,7 +2185,7 @@ func TestDefaultBackend(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2235,7 +2254,7 @@ func TestParserSecret(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2294,7 +2313,7 @@ func TestParserSecret(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand All @@ -2311,7 +2330,7 @@ func TestParserSecret(t *testing.T) {
Name: "bar",
Namespace: "ns1",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2389,7 +2408,7 @@ func TestParserSecret(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2472,7 +2491,7 @@ func TestPluginAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "foo-plugin",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2562,7 +2581,7 @@ func TestPluginAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "foo-plugin",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2647,7 +2666,7 @@ func TestPluginAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "foo-plugin",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2709,7 +2728,7 @@ func TestPluginAnnotations(t *testing.T) {
Namespace: "default",
Annotations: map[string]string{
"plugins.konghq.com": "does-not-exist",
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -2760,7 +2779,7 @@ func TestParseIngressRules(t *testing.T) {
Name: "foo",
Namespace: "foo-namespace",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down
15 changes: 11 additions & 4 deletions internal/ingress/store/fake_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"testing"

"github.com/kong/kubernetes-ingress-controller/internal/ingress/annotations"
configurationv1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1"
configurationv1beta1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1beta1"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestFakeStoreIngress(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: networking.IngressSpec{
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestFakeStoreListTCPIngress(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
Spec: configurationv1beta1.IngressSpec{
Expand Down Expand Up @@ -324,7 +325,7 @@ func TestFakeStoreConsumer(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
},
Expand Down Expand Up @@ -402,7 +403,7 @@ func TestFakeStoreClusterPlugins(t *testing.T) {
"global": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": "kong",
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
},
Expand Down Expand Up @@ -535,6 +536,9 @@ func TestFakeStore_ListCACerts(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
},
{
Expand All @@ -544,6 +548,9 @@ func TestFakeStore_ListCACerts(t *testing.T) {
Labels: map[string]string{
"konghq.com/ca-cert": "true",
},
Annotations: map[string]string{
"kubernetes.io/ingress.class": annotations.DefaultIngressClass,
},
},
},
}
Expand Down
11 changes: 5 additions & 6 deletions internal/ingress/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ func (s Store) ListTCPIngresses() ([]*configurationv1beta1.TCPIngress, error) {

func (s Store) validKnativeIngressClass(objectMeta *metav1.ObjectMeta) bool {
ingressAnnotationValue := objectMeta.GetAnnotations()[knativeIngressClassKey]
if ingressAnnotationValue == "" &&
s.ingressClass == annotations.DefaultIngressClass {
return true
}
return ingressAnnotationValue == s.ingressClass
}

Expand All @@ -211,6 +207,9 @@ func (s Store) ListKnativeIngresses() ([]*knative.Ingress, error) {
err := cache.ListAll(s.stores.KnativeIngress, labels.NewSelector(),
func(ob interface{}) {
ing, ok := ob.(*knative.Ingress)
// this is implemented directly in store as s.isValidIngressClass only checks the value of the
// kubernetes.io/ingress.class annotation (annotations.ingressClassKey), not
// networking.knative.dev/ingress.class (knativeIngressClassKey)
if ok && s.validKnativeIngressClass(&ing.ObjectMeta) {
ingresses = append(ingresses, ing)
}
Expand Down Expand Up @@ -331,7 +330,7 @@ func (s Store) ListGlobalKongPlugins() ([]*configurationv1.KongPlugin, error) {
labels.NewSelector().Add(*req),
func(ob interface{}) {
p, ok := ob.(*configurationv1.KongPlugin)
if ok && s.isValidIngressClass(&p.ObjectMeta, s.ingressClassMatching) {
if ok && s.isValidIngressClass(&p.ObjectMeta, annotations.ExactOrEmptyClassMatch) {
plugins = append(plugins, p)
}
})
Expand Down Expand Up @@ -378,7 +377,7 @@ func (s Store) ListCACerts() ([]*apiv1.Secret, error) {
labels.NewSelector().Add(*req),
func(ob interface{}) {
p, ok := ob.(*apiv1.Secret)
if ok {
if ok && s.isValidIngressClass(&p.ObjectMeta, annotations.ExactClassMatch) {
secrets = append(secrets, p)
}
})
Expand Down