Skip to content

Commit

Permalink
chore: use ingress-class instead of ingress.class with knative
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed May 17, 2022
1 parent cfbe807 commit 6a4ee90
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
- diff logging now honors log level instead of printing at all log levels. It
will only print at levels `debug` and `trace`.
[#2422](https:/Kong/kubernetes-ingress-controller/issues/2422)
- Rename kubernetes.io/ingress.class to kubernetes.io/ingress-class #2485
[#2485](https:/Kong/kubernetes-ingress-controller/issues/2485)

## [2.3.1]

Expand Down
5 changes: 3 additions & 2 deletions internal/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const (
)

const (
IngressClassKey = "kubernetes.io/ingress.class"
KnativeIngressClassKey = "networking.knative.dev/ingress.class"
IngressClassKey = "kubernetes.io/ingress.class"
KnativeIngressClassKey = "networking.knative.dev/ingress-class"
KnativeIngressClassAltKey = "networking.knative.dev/ingress.class"

AnnotationPrefix = "konghq.com"

Expand Down
9 changes: 8 additions & 1 deletion internal/controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func IsDefaultIngressClass(obj client.Object) bool {
func MatchesIngressClass(obj client.Object, controllerIngressClass string, isDefault bool) bool {
objectIngressClass := obj.GetAnnotations()[annotations.IngressClassKey]
objectKnativeClass := obj.GetAnnotations()[annotations.KnativeIngressClassKey]
objectKnativeClassAlt := obj.GetAnnotations()[annotations.KnativeIngressClassAltKey]
if isDefault && IsIngressClassEmpty(obj) {
return true
}
Expand All @@ -33,9 +34,12 @@ func MatchesIngressClass(obj client.Object, controllerIngressClass string, isDef
return true
}
}
if objectIngressClass == controllerIngressClass || objectKnativeClass == controllerIngressClass {

switch controllerIngressClass {
case objectIngressClass, objectKnativeClass, objectKnativeClassAlt:
return true
}

return false
}

Expand Down Expand Up @@ -71,6 +75,9 @@ func IsIngressClassEmpty(obj client.Object) bool {
if _, ok := obj.GetAnnotations()[annotations.KnativeIngressClassKey]; ok {
return false
}
if _, ok := obj.GetAnnotations()[annotations.KnativeIngressClassAltKey]; ok {
return false
}
return true
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/dataplane/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ func TestKnativeIngressAndPlugins(t *testing.T) {
Name: "knative-ingress-with-override",
Namespace: "foo-ns",
Annotations: map[string]string{
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
annotations.AnnotationPrefix + annotations.ConfigurationKey: "https-only",
},
},
Expand Down Expand Up @@ -2181,7 +2181,7 @@ func TestKnativeIngressAndPlugins(t *testing.T) {
Name: "knative-ingress-without-override",
Namespace: "foo-ns",
Annotations: map[string]string{
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
},
},
Spec: knative.IngressSpec{
Expand Down Expand Up @@ -2260,7 +2260,7 @@ func TestKnativeIngressAndPlugins(t *testing.T) {
Name: "knative-ingress-with-annotations",
Namespace: "foo-ns",
Annotations: map[string]string{
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
annotations.AnnotationPrefix + annotations.ProtocolsKey: "https",
annotations.AnnotationPrefix + annotations.HTTPSRedirectCodeKey: "308",
annotations.AnnotationPrefix + annotations.StripPathKey: "true",
Expand Down Expand Up @@ -2332,7 +2332,7 @@ func TestKnativeIngressAndPlugins(t *testing.T) {
Name: "knative-ingress",
Namespace: "foo-ns",
Annotations: map[string]string{
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
},
},
Spec: knative.IngressSpec{
Expand Down Expand Up @@ -2371,7 +2371,7 @@ func TestKnativeIngressAndPlugins(t *testing.T) {
Namespace: "foo-ns",
Annotations: map[string]string{
annotations.AnnotationPrefix + annotations.PluginsKey: "knative-key-auth",
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/store/fake_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestFakeStoreListKnativeIngress(t *testing.T) {
Name: "foo",
Namespace: "default",
Annotations: map[string]string{
"networking.knative.dev/ingress.class": annotations.DefaultIngressClass,
"networking.knative.dev/ingress-class": annotations.DefaultIngressClass,
},
},
Spec: knative.IngressSpec{
Expand Down
9 changes: 6 additions & 3 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,12 @@ func (s Store) ListKnativeIngresses() ([]*knative.Ingress, error) {
labels.NewSelector(),
func(ob interface{}) {
ing, ok := ob.(*knative.Ingress)
if ok && s.isValidIngressClass(&ing.ObjectMeta, annotations.KnativeIngressClassKey,
s.getIngressClassHandling()) {
ingresses = append(ingresses, ing)
if ok {
handlingClass := s.getIngressClassHandling()
if s.isValidIngressClass(&ing.ObjectMeta, annotations.KnativeIngressClassKey, handlingClass) ||
s.isValidIngressClass(&ing.ObjectMeta, annotations.KnativeIngressClassAltKey, handlingClass) {
ingresses = append(ingresses, ing)
}
}
})
if err != nil {
Expand Down
25 changes: 19 additions & 6 deletions test/integration/knative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,23 @@ func accessKnativeSrv(ctx context.Context, proxy, nsn string, t *testing.T) bool
ingCli := knativec.NetworkingV1alpha1().Ingresses(nsn)
assert.Eventually(t, func() bool {
curIng, err := ingCli.Get(ctx, "helloworld-go", metav1.GetOptions{})
if err != nil || curIng == nil {
if err != nil {
t.Logf("error getting knative ingress: %v", err)
return false
}
if curIng == nil {
t.Log("got nil when getting knative ingress")
return false
}

conds := curIng.Status.Status.GetConditions()
for _, cond := range conds {
if cond.Type == apis.ConditionReady && cond.Status == v1.ConditionTrue {
t.Log("knative ingress status is ready.")
t.Logf("knative ingress %s/%s status is ready.", curIng.Namespace, curIng.Name)
return true
}
}
t.Logf("knative ingress %s/%s not ready yet", curIng.Namespace, curIng.Name)
return false
}, statusWait, waitTick, true)

Expand All @@ -177,19 +184,25 @@ func accessKnativeSrv(ctx context.Context, proxy, nsn string, t *testing.T) bool
return assert.Eventually(t, func() bool {
resp, err := client.Do(req)
if err != nil {
t.Logf("error requesting %s: %v", req.URL, err)
return false
}
defer resp.Body.Close()

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
t.Logf("error reading response body (url: %s): %v", req.URL, err)
return false
}

if resp.StatusCode == http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return false
}
bodyString := string(bodyBytes)
t.Logf(bodyString)
t.Log("service is successfully accessed through kong.")
return true
}

t.Logf("expected HTTP 200 but got %d, with body: %s", resp.StatusCode, bodyBytes)
return false
}, knativeWaitTime, waitTick)
}

0 comments on commit 6a4ee90

Please sign in to comment.