Skip to content

Commit

Permalink
feat(controllers) add IngressClass v1
Browse files Browse the repository at this point in the history
Add an IngressClass controller.

Add IngressClass functions to the stores.

Add IngressClass permissions and a default IngressClass resource to the
manifests.
  • Loading branch information
rainest committed Feb 24, 2022
1 parent 0f2f9be commit 786efbc
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 2 deletions.
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
- 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.

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

0 comments on commit 786efbc

Please sign in to comment.