Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
k8stypes "k8s.io/apimachinery/pkg/types"
<<<<<<< HEAD
ctrl "sigs.k8s.io/controller-runtime"
=======
>>>>>>> cbfa0389 (feat: support kubernetes.io/ingress.class annotations (#2615))
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down
9 changes: 9 additions & 0 deletions internal/types/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import (
netv1 "k8s.io/api/networking/v1"
netv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"
<<<<<<< HEAD
kschema "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
=======
"k8s.io/utils/ptr"
>>>>>>> cbfa0389 (feat: support kubernetes.io/ingress.class annotations (#2615))
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
Expand Down Expand Up @@ -215,6 +219,11 @@ func GvkOf(obj any) schema.GroupVersionKind {
}
}

<<<<<<< HEAD
=======
// GetEffectiveIngressClassName returns the effective ingress class name.
// It first checks spec.IngressClassName, and falls back to the annotation if spec is empty.
>>>>>>> cbfa0389 (feat: support kubernetes.io/ingress.class annotations (#2615))
func GetEffectiveIngressClassName(ingress *netv1.Ingress) string {
if cls := ptr.Deref(ingress.Spec.IngressClassName, ""); cls != "" {
return cls
Expand Down
62 changes: 62 additions & 0 deletions test/e2e/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,4 +1117,66 @@ spec:
Should(Equal("enabled"))
})
})

Context("Ingress with annotation-based IngressClass", func() {
const ingressClassSpec = `
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: %s
spec:
controller: "%s"
parameters:
apiGroup: "apisix.apache.org"
kind: "GatewayProxy"
name: "apisix-proxy-config"
namespace: %s
scope: "Namespace"
`
const ingressSpec = `
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: apisix-ingress-annotation
annotations:
kubernetes.io/ingress.class: %s
spec:
rules:
- host: annotation.example.com
http:
paths:
- path: /get
pathType: Prefix
backend:
service:
name: httpbin-service-e2e-test
port:
number: 80
`

It("Ingress with kubernetes.io/ingress.class annotation", func() {
By("create GatewayProxy")
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace())
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
time.Sleep(5 * time.Second)

By("create IngressClass")
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassSpec, s.Namespace(), s.GetControllerName(), s.Namespace()), s.Namespace())
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")

By("create Ingress with annotation")
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressSpec, s.Namespace()), s.Namespace())
Expect(err).NotTo(HaveOccurred(), "creating Ingress with annotation")

By("verify Ingress with annotation works")
Eventually(func() int {
return s.NewAPISIXClient().
GET("/get").
WithHost("annotation.example.com").
Expect().Raw().StatusCode
}).WithTimeout(20 * time.Second).ProbeEvery(time.Second).
Should(Equal(http.StatusOK))
})
})
})