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

feat(controllers) add IngressClass v1 #2292

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@

> Release date: TBD
#### Added

- Deployment manifests now include an IngressClass resource and permissions to
read IngressClass resources.
[#2292](https://github.com/Kong/kubernetes-ingress-controller/pull/2292)

#### Fixed

- Unconfigured fields now use their default value according to the Kong proxy
Expand Down
6 changes: 6 additions & 0 deletions config/base/ingressclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: kong
spec:
controller: ingress-controllers.konghq.com/kong
1 change: 1 addition & 0 deletions config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resources:
- namespace.yaml
- ../crd
- ../rbac
- ingressclass.yaml
- service.yaml
- serviceaccount.yaml
- validation-service.yaml
Expand Down
16 changes: 16 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses/status
verbs:
- get
- patch
- update
rainest marked this conversation as resolved.
Show resolved Hide resolved
- apiGroups:
- networking.k8s.io
resources:
Expand Down
23 changes: 23 additions & 0 deletions deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,22 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
Expand Down Expand Up @@ -1414,3 +1430,10 @@ spec:
imagePullSecrets:
- name: kong-enterprise-edition-docker
serviceAccountName: kong-serviceaccount
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: kong
spec:
controller: ingress-controllers.konghq.com/kong
23 changes: 23 additions & 0 deletions deploy/single/all-in-one-dbless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,22 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
Expand Down Expand Up @@ -1407,3 +1423,10 @@ spec:
successThreshold: 1
timeoutSeconds: 1
serviceAccountName: kong-serviceaccount
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: kong
spec:
controller: ingress-controllers.konghq.com/kong
23 changes: 23 additions & 0 deletions deploy/single/all-in-one-postgres-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,22 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
Expand Down Expand Up @@ -1597,3 +1613,10 @@ spec:
image: busybox
name: wait-for-postgres
restartPolicy: OnFailure
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: kong
spec:
controller: ingress-controllers.konghq.com/kong
23 changes: 23 additions & 0 deletions deploy/single/all-in-one-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,22 @@ rules:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
Expand Down Expand Up @@ -1522,3 +1538,10 @@ spec:
image: busybox
name: wait-for-postgres
restartPolicy: OnFailure
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: kong
spec:
controller: ingress-controllers.konghq.com/kong
12 changes: 12 additions & 0 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ var inputControllersNeeded = &typesNeeded{
AcceptsIngressClassNameSpec: true,
RBACVerbs: []string{"get", "list", "watch"},
},
typeNeeded{
PackageImportAlias: "netv1",
PackageAlias: "NetV1",
Package: netv1,
Type: "IngressClass",
Plural: "ingressclasses",
URL: "networking.k8s.io",
CacheType: "IngressV1",
AcceptsIngressClassNameAnnotation: false,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
},
typeNeeded{
PackageImportAlias: "netv1beta1",
PackageAlias: "NetV1Beta1",
Expand Down
61 changes: 61 additions & 0 deletions internal/controllers/configuration/zz_generated_controllers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Config struct {
IngressExtV1beta1Enabled bool
IngressNetV1beta1Enabled bool
IngressNetV1Enabled bool
IngressClassNetV1Enabled bool
UDPIngressEnabled bool
TCPIngressEnabled bool
KongIngressEnabled bool
Expand Down Expand Up @@ -155,6 +156,7 @@ func (c *Config) FlagSet() *pflag.FlagSet {

// Kubernetes API toggling
flagSet.BoolVar(&c.IngressNetV1Enabled, "enable-controller-ingress-networkingv1", true, "Enable the networking.k8s.io/v1 Ingress controller.")
flagSet.BoolVar(&c.IngressClassNetV1Enabled, "enable-controller-ingress-class-networkingv1", true, "Enable the networking.k8s.io/v1 IngressClass controller.")
flagSet.BoolVar(&c.IngressNetV1beta1Enabled, "enable-controller-ingress-networkingv1beta1", true, "Enable the networking.k8s.io/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.IngressExtV1beta1Enabled, "enable-controller-ingress-extensionsv1beta1", true, "Enable the extensions/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.UDPIngressEnabled, "enable-controller-udpingress", true, "Enable the UDPIngress controller.")
Expand Down
10 changes: 10 additions & 0 deletions internal/manager/controllerdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func setupControllers(mgr manager.Manager, proxy proxy.Proxy, c *Config, feature
IngressClassName: c.IngressClassName,
},
},
{
Enabled: c.IngressClassNetV1Enabled,
AutoHandler: ingressPicker.IsNetV1,
Controller: &configuration.NetV1IngressClassReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IngressClass").WithName("netv1"),
Scheme: mgr.GetScheme(),
Proxy: proxy,
},
},
{
Enabled: c.IngressNetV1beta1Enabled,
AutoHandler: ingressPicker.IsNetV1beta1,
Expand Down
9 changes: 9 additions & 0 deletions internal/store/fake_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func clusterResourceKeyFunc(obj interface{}) (string, error) {
type FakeObjects struct {
IngressesV1beta1 []*networkingv1beta1.Ingress
IngressesV1 []*networkingv1.Ingress
IngressClassesV1 []*networkingv1.IngressClass
HTTPRoute []*gatewayv1alpha2.HTTPRoute
TCPIngresses []*configurationv1beta1.TCPIngress
UDPIngresses []*configurationv1beta1.UDPIngress
Expand Down Expand Up @@ -64,6 +65,13 @@ func NewFakeStore(
return nil, err
}
}
ingressClassV1Store := cache.NewStore(keyFunc)
for _, ingress := range objects.IngressClassesV1 {
err := ingressClassV1Store.Add(ingress)
if err != nil {
return nil, err
}
}
httprouteStore := cache.NewStore(keyFunc)
for _, httproute := range objects.HTTPRoute {
if err := httprouteStore.Add(httproute); err != nil {
Expand Down Expand Up @@ -144,6 +152,7 @@ func NewFakeStore(
stores: CacheStores{
IngressV1beta1: ingressV1beta1Store,
IngressV1: ingressV1Store,
IngressClassV1: ingressClassV1Store,
HTTPRoute: httprouteStore,
TCPIngress: tcpIngressStore,
UDPIngress: udpIngressStore,
Expand Down
35 changes: 35 additions & 0 deletions internal/store/fake_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,41 @@ func TestFakeStoreIngressV1(t *testing.T) {
assert.Len(store.ListIngressesV1beta1(), 0)
}

func TestFakeStoreIngressClassV1(t *testing.T) {
assert := assert.New(t)

classes := []*networkingv1.IngressClass{
{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Spec: networkingv1.IngressClassSpec{
Controller: ingressClassKongController,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: networkingv1.IngressClassSpec{
Controller: ingressClassKongController,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "baz",
},
Spec: networkingv1.IngressClassSpec{
Controller: "some-other-controller.example.com/controller",
},
},
}
store, err := NewFakeStore(FakeObjects{IngressClassesV1: classes})
assert.Nil(err)
assert.NotNil(store)
assert.Len(store.ListIngressClassesV1(), 2)
}

func TestFakeStoreListTCPIngress(t *testing.T) {
assert := assert.New(t)

Expand Down
Loading