From 859715679e479d028ffec1c3075b216ec5430c8c Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Wed, 12 Jul 2023 13:59:42 +0200 Subject: [PATCH] feat(crd): add KongConsumerGroup CRD --- CHANGELOG.md | 2 + PROJECT | 8 + ...uration.konghq.com_kongconsumergroups.yaml | 47 +++++ config/crd/kustomization.yaml | 1 + config/rbac/role.yaml | 16 ++ .../single/all-in-one-dbless-enterprise.yaml | 63 +++++++ .../all-in-one-dbless-k4k8s-enterprise.yaml | 63 +++++++ .../all-in-one-dbless-konnect-enterprise.yaml | 63 +++++++ deploy/single/all-in-one-dbless-konnect.yaml | 63 +++++++ deploy/single/all-in-one-dbless-legacy.yaml | 63 +++++++ deploy/single/all-in-one-dbless.yaml | 63 +++++++ .../all-in-one-postgres-enterprise.yaml | 63 +++++++ deploy/single/all-in-one-postgres.yaml | 63 +++++++ docs/api-reference.md | 18 ++ .../generators/controllers/networking/main.go | 15 ++ .../configuration/zz_generated_controllers.go | 154 +++++++++++++++ internal/manager/controllerdef.go | 20 ++ .../v1beta1/kongconsumergroup_types.go | 49 +++++ .../v1beta1/zz_generated.deepcopy.go | 57 ++++++ .../v1beta1/configuration_client.go | 5 + .../v1beta1/fake/fake_configuration_client.go | 4 + .../v1beta1/fake/fake_kongconsumergroup.go | 129 +++++++++++++ .../v1beta1/generated_expansion.go | 2 + .../v1beta1/kongconsumergroup.go | 178 ++++++++++++++++++ test/envtest/crds_envtest_test.go | 5 + 25 files changed, 1214 insertions(+) create mode 100644 config/crd/bases/configuration.konghq.com_kongconsumergroups.yaml create mode 100644 pkg/apis/configuration/v1beta1/kongconsumergroup_types.go create mode 100644 pkg/clientset/typed/configuration/v1beta1/fake/fake_kongconsumergroup.go create mode 100644 pkg/clientset/typed/configuration/v1beta1/kongconsumergroup.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f4f6806091..de9beef9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ Adding a new version? You'll need three changes: ### Added +- **WIP** Introduce `KongConsumerGroup` CRD (supported by Kong Enterprise only) + [#4325](https://github.com/Kong/kubernetes-ingress-controller/pull/4325) - The ResponseHeaderModifier Gateway API filter is now supported and translated to the proper set of Kong plugins. [#4350](https://github.com/Kong/kubernetes-ingress-controller/pull/4350) diff --git a/PROJECT b/PROJECT index aba06d3066..70426e2e3d 100644 --- a/PROJECT +++ b/PROJECT @@ -36,6 +36,14 @@ resources: kind: KongConsumer path: github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1 version: v1 +- api: + crdVersion: v1beta1 + namespaced: true + domain: konghq.com + group: configuration + kind: KongConsumerGroup + path: github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1beta1 + version: v1beta1 - api: crdVersion: v1 namespaced: true diff --git a/config/crd/bases/configuration.konghq.com_kongconsumergroups.yaml b/config/crd/bases/configuration.konghq.com_kongconsumergroups.yaml new file mode 100644 index 0000000000..079ccb47eb --- /dev/null +++ b/config/crd/bases/configuration.konghq.com_kongconsumergroups.yaml @@ -0,0 +1,47 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 229f895639..d5b97943a8 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -6,6 +6,7 @@ resources: - bases/configuration.konghq.com_udpingresses.yaml - bases/configuration.konghq.com_kongclusterplugins.yaml - bases/configuration.konghq.com_kongconsumers.yaml +- bases/configuration.konghq.com_kongconsumergroups.yaml - bases/configuration.konghq.com_kongingresses.yaml - bases/configuration.konghq.com_kongplugins.yaml - bases/configuration.konghq.com_ingressclassparameterses.yaml diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index b41adcf7a0..7980025695 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -73,6 +73,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless-enterprise.yaml b/deploy/single/all-in-one-dbless-enterprise.yaml index be28bf70af..01957740e6 100644 --- a/deploy/single/all-in-one-dbless-enterprise.yaml +++ b/deploy/single/all-in-one-dbless-enterprise.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml b/deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml index e204e9fc24..b818d90d72 100644 --- a/deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml +++ b/deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless-konnect-enterprise.yaml b/deploy/single/all-in-one-dbless-konnect-enterprise.yaml index 7c7c0d6739..d0f4537812 100644 --- a/deploy/single/all-in-one-dbless-konnect-enterprise.yaml +++ b/deploy/single/all-in-one-dbless-konnect-enterprise.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless-konnect.yaml b/deploy/single/all-in-one-dbless-konnect.yaml index 85fdc98906..faa4bcc45c 100644 --- a/deploy/single/all-in-one-dbless-konnect.yaml +++ b/deploy/single/all-in-one-dbless-konnect.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless-legacy.yaml b/deploy/single/all-in-one-dbless-legacy.yaml index 9ead57e508..08d23aa57e 100644 --- a/deploy/single/all-in-one-dbless-legacy.yaml +++ b/deploy/single/all-in-one-dbless-legacy.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-dbless.yaml b/deploy/single/all-in-one-dbless.yaml index f0fb4a9aa8..22e1285b6b 100644 --- a/deploy/single/all-in-one-dbless.yaml +++ b/deploy/single/all-in-one-dbless.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-postgres-enterprise.yaml b/deploy/single/all-in-one-postgres-enterprise.yaml index 93ba248c41..8914290503 100644 --- a/deploy/single/all-in-one-postgres-enterprise.yaml +++ b/deploy/single/all-in-one-postgres-enterprise.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/deploy/single/all-in-one-postgres.yaml b/deploy/single/all-in-one-postgres.yaml index 9dc0e54d1e..bdf8a3c21a 100644 --- a/deploy/single/all-in-one-postgres.yaml +++ b/deploy/single/all-in-one-postgres.yaml @@ -222,6 +222,53 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.12.1 + name: kongconsumergroups.configuration.konghq.com +spec: + group: configuration.konghq.com + names: + categories: + - kong-ingress-controller + kind: KongConsumerGroup + listKind: KongConsumerGroupList + plural: kongconsumergroups + shortNames: + - kcg + singular: kongconsumergroup + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Age + jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1beta1 + schema: + openAPIV3Schema: + description: KongConsumerGroup is the Schema for the kongconsumergroups API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.1 @@ -1254,6 +1301,22 @@ rules: - get - patch - update +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups + verbs: + - get + - list + - watch +- apiGroups: + - configuration.konghq.com + resources: + - kongconsumergroups/status + verbs: + - get + - patch + - update - apiGroups: - configuration.konghq.com resources: diff --git a/docs/api-reference.md b/docs/api-reference.md index c21b6b1b8a..eb45b0eec4 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -312,9 +312,27 @@ _Appears in:_ Package v1beta1 contains API Schema definitions for the configuration.konghq.com v1beta1 API group. +- [KongConsumerGroup](#kongconsumergroup) - [TCPIngress](#tcpingress) - [UDPIngress](#udpingress) +### KongConsumerGroup + + + +KongConsumerGroup is the Schema for the kongconsumergroups API. + + + +| Field | Description | +| --- | --- | +| `apiVersion` _string_ | `configuration.konghq.com/v1beta1` +| `kind` _string_ | `KongConsumerGroup` +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | + + + + ### TCPIngress diff --git a/hack/generators/controllers/networking/main.go b/hack/generators/controllers/networking/main.go index 0264aad632..ac294e6622 100644 --- a/hack/generators/controllers/networking/main.go +++ b/hack/generators/controllers/networking/main.go @@ -148,6 +148,21 @@ var inputControllersNeeded = &typesNeeded{ NeedsUpdateReferences: true, RBACVerbs: []string{"get", "list", "watch"}, }, + typeNeeded{ + Group: "configuration.konghq.com", + Version: "v1beta1", + Kind: "KongConsumerGroup", + PackageImportAlias: "kongv1beta1", + PackageAlias: "KongV1Beta1", + Package: kongv1beta1, + Plural: "kongconsumergroups", + CacheType: "ConsumerGroup", + NeedsStatusPermissions: true, + AcceptsIngressClassNameAnnotation: true, + AcceptsIngressClassNameSpec: false, + NeedsUpdateReferences: true, + RBACVerbs: []string{"get", "list", "watch"}, + }, typeNeeded{ Group: "configuration.konghq.com", Version: "v1beta1", diff --git a/internal/controllers/configuration/zz_generated_controllers.go b/internal/controllers/configuration/zz_generated_controllers.go index bd6e1924b9..0210b208fe 100644 --- a/internal/controllers/configuration/zz_generated_controllers.go +++ b/internal/controllers/configuration/zz_generated_controllers.go @@ -977,6 +977,160 @@ func (r *KongV1KongConsumerReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, nil } +// ----------------------------------------------------------------------------- +// KongV1Beta1 KongConsumerGroup - Reconciler +// ----------------------------------------------------------------------------- + +// KongV1Beta1KongConsumerGroupReconciler reconciles KongConsumerGroup resources +type KongV1Beta1KongConsumerGroupReconciler struct { + client.Client + + Log logr.Logger + Scheme *runtime.Scheme + DataplaneClient *dataplane.KongClient + CacheSyncTimeout time.Duration + + IngressClassName string + DisableIngressClassLookups bool + ReferenceIndexers ctrlref.CacheIndexers +} + +// SetupWithManager sets up the controller with the Manager. +func (r *KongV1Beta1KongConsumerGroupReconciler) SetupWithManager(mgr ctrl.Manager) error { + c, err := controller.New("KongV1Beta1KongConsumerGroup", mgr, controller.Options{ + Reconciler: r, + LogConstructor: func(_ *reconcile.Request) logr.Logger { + return r.Log + }, + CacheSyncTimeout: r.CacheSyncTimeout, + }) + if err != nil { + return err + } + if !r.DisableIngressClassLookups { + err = c.Watch( + source.Kind(mgr.GetCache(), &netv1.IngressClass{}), + handler.EnqueueRequestsFromMapFunc(r.listClassless), + predicate.NewPredicateFuncs(ctrlutils.IsDefaultIngressClass), + ) + if err != nil { + return err + } + } + preds := ctrlutils.GeneratePredicateFuncsForIngressClassFilter(r.IngressClassName) + return c.Watch( + source.Kind(mgr.GetCache(), &kongv1beta1.KongConsumerGroup{}), + &handler.EnqueueRequestForObject{}, + preds, + ) +} + +// listClassless finds and reconciles all objects without ingress class information +func (r *KongV1Beta1KongConsumerGroupReconciler) listClassless(ctx context.Context, obj client.Object) []reconcile.Request { + resourceList := &kongv1beta1.KongConsumerGroupList{} + if err := r.Client.List(ctx, resourceList); err != nil { + r.Log.Error(err, "failed to list classless kongconsumergroups") + return nil + } + var recs []reconcile.Request + for i, resource := range resourceList.Items { + if ctrlutils.IsIngressClassEmpty(&resourceList.Items[i]) { + recs = append(recs, reconcile.Request{ + NamespacedName: k8stypes.NamespacedName{ + Namespace: resource.Namespace, + Name: resource.Name, + }, + }) + } + } + return recs +} + +//+kubebuilder:rbac:groups=configuration.konghq.com,resources=kongconsumergroups,verbs=get;list;watch +//+kubebuilder:rbac:groups=configuration.konghq.com,resources=kongconsumergroups/status,verbs=get;update;patch + +// Reconcile processes the watched objects +func (r *KongV1Beta1KongConsumerGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log := r.Log.WithValues("KongV1Beta1KongConsumerGroup", req.NamespacedName) + + // get the relevant object + obj := new(kongv1beta1.KongConsumerGroup) + if err := r.Get(ctx, req.NamespacedName, obj); err != nil { + if apierrors.IsNotFound(err) { + obj.Namespace = req.Namespace + obj.Name = req.Name + + // remove reference record where the KongConsumerGroup is the referrer + if err := ctrlref.DeleteReferencesByReferrer(r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + return ctrl.Result{}, err + } + + return ctrl.Result{}, r.DataplaneClient.DeleteObject(obj) + } + return ctrl.Result{}, err + } + log.V(util.DebugLevel).Info("reconciling resource", "namespace", req.Namespace, "name", req.Name) + + // clean the object up if it's being deleted + if !obj.DeletionTimestamp.IsZero() && time.Now().After(obj.DeletionTimestamp.Time) { + log.V(util.DebugLevel).Info("resource is being deleted, its configuration will be removed", "type", "KongConsumerGroup", "namespace", req.Namespace, "name", req.Name) + + // remove reference record where the KongConsumerGroup is the referrer + if err := ctrlref.DeleteReferencesByReferrer(r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + return ctrl.Result{}, err + } + + objectExistsInCache, err := r.DataplaneClient.ObjectExists(obj) + if err != nil { + return ctrl.Result{}, err + } + if objectExistsInCache { + if err := r.DataplaneClient.DeleteObject(obj); err != nil { + return ctrl.Result{}, err + } + return ctrl.Result{Requeue: true}, nil // wait until the object is no longer present in the cache + } + return ctrl.Result{}, nil + } + + class := new(netv1.IngressClass) + if !r.DisableIngressClassLookups { + if err := r.Get(ctx, k8stypes.NamespacedName{Name: r.IngressClassName}, class); err != nil { + // we log this without taking action to support legacy configurations that only set ingressClassName or + // used the class annotation and did not create a corresponding IngressClass. We only need this to determine + // if the IngressClass is default or to configure default settings, and can assume no/no additional defaults + // if none exists. + log.V(util.DebugLevel).Info("could not retrieve IngressClass", "ingressclass", r.IngressClassName) + } + } + // if the object is not configured with our ingress.class, then we need to ensure it's removed from the cache + if !ctrlutils.MatchesIngressClass(obj, r.IngressClassName, ctrlutils.IsDefaultIngressClass(class)) { + log.V(util.DebugLevel).Info("object missing ingress class, ensuring it's removed from configuration", + "namespace", req.Namespace, "name", req.Name, "class", r.IngressClassName) + return ctrl.Result{}, r.DataplaneClient.DeleteObject(obj) + } else { + log.V(util.DebugLevel).Info("object has matching ingress class", "namespace", req.Namespace, "name", req.Name, + "class", r.IngressClassName) + } + + // update the kong Admin API with the changes + if err := r.DataplaneClient.UpdateObject(obj); err != nil { + return ctrl.Result{}, err + } + // update reference relationship from the KongConsumerGroup to other objects. + if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + if apierrors.IsNotFound(err) { + // reconcile again if the secret does not exist yet + return ctrl.Result{ + Requeue: true, + }, nil + } + return ctrl.Result{}, err + } + + return ctrl.Result{}, nil +} + // ----------------------------------------------------------------------------- // KongV1Beta1 TCPIngress - Reconciler // ----------------------------------------------------------------------------- diff --git a/internal/manager/controllerdef.go b/internal/manager/controllerdef.go index 8392d9c6c0..e421e32a91 100644 --- a/internal/manager/controllerdef.go +++ b/internal/manager/controllerdef.go @@ -271,6 +271,26 @@ func setupControllers( ReferenceIndexers: referenceIndexers, }, }, + { + Enabled: c.KongConsumerEnabled && ShouldEnableCRDController( + schema.GroupVersionResource{ + Group: konghqcomv1beta1.GroupVersion.Group, + Version: konghqcomv1beta1.GroupVersion.Version, + Resource: "kongconsumergroups", + }, + restMapper, + ), + Controller: &configuration.KongV1Beta1KongConsumerGroupReconciler{ + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("KongConsumerGroup"), + Scheme: mgr.GetScheme(), + DataplaneClient: dataplaneClient, + IngressClassName: c.IngressClassName, + DisableIngressClassLookups: !c.IngressClassNetV1Enabled, + CacheSyncTimeout: c.CacheSyncTimeout, + ReferenceIndexers: referenceIndexers, + }, + }, { Enabled: c.KongClusterPluginEnabled && ShouldEnableCRDController( schema.GroupVersionResource{ diff --git a/pkg/apis/configuration/v1beta1/kongconsumergroup_types.go b/pkg/apis/configuration/v1beta1/kongconsumergroup_types.go new file mode 100644 index 0000000000..05aff7230a --- /dev/null +++ b/pkg/apis/configuration/v1beta1/kongconsumergroup_types.go @@ -0,0 +1,49 @@ +/* +Copyright 2023 Kong, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:resource:shortName=kcg,categories=kong-ingress-controller +// +kubebuilder:validation:Optional +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age" + +// KongConsumerGroup is the Schema for the kongconsumergroups API. +type KongConsumerGroup struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` +} + +// +kubebuilder:object:root=true + +// KongConsumerGroupList contains a list of KongConsumerGroups. +type KongConsumerGroupList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KongConsumerGroup `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KongConsumerGroup{}, &KongConsumerGroupList{}) +} diff --git a/pkg/apis/configuration/v1beta1/zz_generated.deepcopy.go b/pkg/apis/configuration/v1beta1/zz_generated.deepcopy.go index d5d1d7482f..0b1b6af12c 100644 --- a/pkg/apis/configuration/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/configuration/v1beta1/zz_generated.deepcopy.go @@ -76,6 +76,63 @@ func (in *IngressTLS) DeepCopy() *IngressTLS { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KongConsumerGroup) DeepCopyInto(out *KongConsumerGroup) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KongConsumerGroup. +func (in *KongConsumerGroup) DeepCopy() *KongConsumerGroup { + if in == nil { + return nil + } + out := new(KongConsumerGroup) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KongConsumerGroup) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KongConsumerGroupList) DeepCopyInto(out *KongConsumerGroupList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KongConsumerGroup, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KongConsumerGroupList. +func (in *KongConsumerGroupList) DeepCopy() *KongConsumerGroupList { + if in == nil { + return nil + } + out := new(KongConsumerGroupList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KongConsumerGroupList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TCPIngress) DeepCopyInto(out *TCPIngress) { *out = *in diff --git a/pkg/clientset/typed/configuration/v1beta1/configuration_client.go b/pkg/clientset/typed/configuration/v1beta1/configuration_client.go index b78db114c8..d44e16b39a 100644 --- a/pkg/clientset/typed/configuration/v1beta1/configuration_client.go +++ b/pkg/clientset/typed/configuration/v1beta1/configuration_client.go @@ -28,6 +28,7 @@ import ( type ConfigurationV1beta1Interface interface { RESTClient() rest.Interface + KongConsumerGroupsGetter TCPIngressesGetter UDPIngressesGetter } @@ -37,6 +38,10 @@ type ConfigurationV1beta1Client struct { restClient rest.Interface } +func (c *ConfigurationV1beta1Client) KongConsumerGroups(namespace string) KongConsumerGroupInterface { + return newKongConsumerGroups(c, namespace) +} + func (c *ConfigurationV1beta1Client) TCPIngresses(namespace string) TCPIngressInterface { return newTCPIngresses(c, namespace) } diff --git a/pkg/clientset/typed/configuration/v1beta1/fake/fake_configuration_client.go b/pkg/clientset/typed/configuration/v1beta1/fake/fake_configuration_client.go index 1a9cd5067d..5264e950f3 100644 --- a/pkg/clientset/typed/configuration/v1beta1/fake/fake_configuration_client.go +++ b/pkg/clientset/typed/configuration/v1beta1/fake/fake_configuration_client.go @@ -28,6 +28,10 @@ type FakeConfigurationV1beta1 struct { *testing.Fake } +func (c *FakeConfigurationV1beta1) KongConsumerGroups(namespace string) v1beta1.KongConsumerGroupInterface { + return &FakeKongConsumerGroups{c, namespace} +} + func (c *FakeConfigurationV1beta1) TCPIngresses(namespace string) v1beta1.TCPIngressInterface { return &FakeTCPIngresses{c, namespace} } diff --git a/pkg/clientset/typed/configuration/v1beta1/fake/fake_kongconsumergroup.go b/pkg/clientset/typed/configuration/v1beta1/fake/fake_kongconsumergroup.go new file mode 100644 index 0000000000..c1e62c53bf --- /dev/null +++ b/pkg/clientset/typed/configuration/v1beta1/fake/fake_kongconsumergroup.go @@ -0,0 +1,129 @@ +/* +Copyright 2021 Kong, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeKongConsumerGroups implements KongConsumerGroupInterface +type FakeKongConsumerGroups struct { + Fake *FakeConfigurationV1beta1 + ns string +} + +var kongconsumergroupsResource = v1beta1.SchemeGroupVersion.WithResource("kongconsumergroups") + +var kongconsumergroupsKind = v1beta1.SchemeGroupVersion.WithKind("KongConsumerGroup") + +// Get takes name of the kongConsumerGroup, and returns the corresponding kongConsumerGroup object, and an error if there is any. +func (c *FakeKongConsumerGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KongConsumerGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(kongconsumergroupsResource, c.ns, name), &v1beta1.KongConsumerGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KongConsumerGroup), err +} + +// List takes label and field selectors, and returns the list of KongConsumerGroups that match those selectors. +func (c *FakeKongConsumerGroups) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KongConsumerGroupList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(kongconsumergroupsResource, kongconsumergroupsKind, c.ns, opts), &v1beta1.KongConsumerGroupList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.KongConsumerGroupList{ListMeta: obj.(*v1beta1.KongConsumerGroupList).ListMeta} + for _, item := range obj.(*v1beta1.KongConsumerGroupList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested kongConsumerGroups. +func (c *FakeKongConsumerGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(kongconsumergroupsResource, c.ns, opts)) + +} + +// Create takes the representation of a kongConsumerGroup and creates it. Returns the server's representation of the kongConsumerGroup, and an error, if there is any. +func (c *FakeKongConsumerGroups) Create(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.CreateOptions) (result *v1beta1.KongConsumerGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(kongconsumergroupsResource, c.ns, kongConsumerGroup), &v1beta1.KongConsumerGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KongConsumerGroup), err +} + +// Update takes the representation of a kongConsumerGroup and updates it. Returns the server's representation of the kongConsumerGroup, and an error, if there is any. +func (c *FakeKongConsumerGroups) Update(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.UpdateOptions) (result *v1beta1.KongConsumerGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(kongconsumergroupsResource, c.ns, kongConsumerGroup), &v1beta1.KongConsumerGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KongConsumerGroup), err +} + +// Delete takes name of the kongConsumerGroup and deletes it. Returns an error if one occurs. +func (c *FakeKongConsumerGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(kongconsumergroupsResource, c.ns, name, opts), &v1beta1.KongConsumerGroup{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeKongConsumerGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(kongconsumergroupsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.KongConsumerGroupList{}) + return err +} + +// Patch applies the patch and returns the patched kongConsumerGroup. +func (c *FakeKongConsumerGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KongConsumerGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(kongconsumergroupsResource, c.ns, name, pt, data, subresources...), &v1beta1.KongConsumerGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.KongConsumerGroup), err +} diff --git a/pkg/clientset/typed/configuration/v1beta1/generated_expansion.go b/pkg/clientset/typed/configuration/v1beta1/generated_expansion.go index 06a7038e35..16697c634a 100644 --- a/pkg/clientset/typed/configuration/v1beta1/generated_expansion.go +++ b/pkg/clientset/typed/configuration/v1beta1/generated_expansion.go @@ -18,6 +18,8 @@ limitations under the License. package v1beta1 +type KongConsumerGroupExpansion interface{} + type TCPIngressExpansion interface{} type UDPIngressExpansion interface{} diff --git a/pkg/clientset/typed/configuration/v1beta1/kongconsumergroup.go b/pkg/clientset/typed/configuration/v1beta1/kongconsumergroup.go new file mode 100644 index 0000000000..daad9ec2ba --- /dev/null +++ b/pkg/clientset/typed/configuration/v1beta1/kongconsumergroup.go @@ -0,0 +1,178 @@ +/* +Copyright 2021 Kong, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1beta1" + scheme "github.com/kong/kubernetes-ingress-controller/v2/pkg/clientset/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// KongConsumerGroupsGetter has a method to return a KongConsumerGroupInterface. +// A group's client should implement this interface. +type KongConsumerGroupsGetter interface { + KongConsumerGroups(namespace string) KongConsumerGroupInterface +} + +// KongConsumerGroupInterface has methods to work with KongConsumerGroup resources. +type KongConsumerGroupInterface interface { + Create(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.CreateOptions) (*v1beta1.KongConsumerGroup, error) + Update(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.UpdateOptions) (*v1beta1.KongConsumerGroup, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.KongConsumerGroup, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.KongConsumerGroupList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KongConsumerGroup, err error) + KongConsumerGroupExpansion +} + +// kongConsumerGroups implements KongConsumerGroupInterface +type kongConsumerGroups struct { + client rest.Interface + ns string +} + +// newKongConsumerGroups returns a KongConsumerGroups +func newKongConsumerGroups(c *ConfigurationV1beta1Client, namespace string) *kongConsumerGroups { + return &kongConsumerGroups{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the kongConsumerGroup, and returns the corresponding kongConsumerGroup object, and an error if there is any. +func (c *kongConsumerGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.KongConsumerGroup, err error) { + result = &v1beta1.KongConsumerGroup{} + err = c.client.Get(). + Namespace(c.ns). + Resource("kongconsumergroups"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of KongConsumerGroups that match those selectors. +func (c *kongConsumerGroups) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.KongConsumerGroupList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.KongConsumerGroupList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("kongconsumergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested kongConsumerGroups. +func (c *kongConsumerGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("kongconsumergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a kongConsumerGroup and creates it. Returns the server's representation of the kongConsumerGroup, and an error, if there is any. +func (c *kongConsumerGroups) Create(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.CreateOptions) (result *v1beta1.KongConsumerGroup, err error) { + result = &v1beta1.KongConsumerGroup{} + err = c.client.Post(). + Namespace(c.ns). + Resource("kongconsumergroups"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kongConsumerGroup). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a kongConsumerGroup and updates it. Returns the server's representation of the kongConsumerGroup, and an error, if there is any. +func (c *kongConsumerGroups) Update(ctx context.Context, kongConsumerGroup *v1beta1.KongConsumerGroup, opts v1.UpdateOptions) (result *v1beta1.KongConsumerGroup, err error) { + result = &v1beta1.KongConsumerGroup{} + err = c.client.Put(). + Namespace(c.ns). + Resource("kongconsumergroups"). + Name(kongConsumerGroup.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(kongConsumerGroup). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the kongConsumerGroup and deletes it. Returns an error if one occurs. +func (c *kongConsumerGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("kongconsumergroups"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *kongConsumerGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("kongconsumergroups"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched kongConsumerGroup. +func (c *kongConsumerGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.KongConsumerGroup, err error) { + result = &v1beta1.KongConsumerGroup{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("kongconsumergroups"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/test/envtest/crds_envtest_test.go b/test/envtest/crds_envtest_test.go index 683c7bd1cb..f0ab3d1c23 100644 --- a/test/envtest/crds_envtest_test.go +++ b/test/envtest/crds_envtest_test.go @@ -67,6 +67,11 @@ func TestMissingCRDsDontCrashTheManager(t *testing.T) { Version: kongv1.GroupVersion.Version, Resource: "kongconsumers", }, + { + Group: kongv1beta1.GroupVersion.Group, + Version: kongv1beta1.GroupVersion.Version, + Resource: "kongconsumergroups", + }, { Group: kongv1.GroupVersion.Group, Version: kongv1.GroupVersion.Version,