From 8eac317eb5c17b417d4b34f7d36b70eb04df0825 Mon Sep 17 00:00:00 2001 From: krish Date: Mon, 23 Sep 2024 21:44:41 +0530 Subject: [PATCH 1/4] Update missing files --- .../operator/config/webhook/manifests.yaml | 40 +++++++++++++++++++ common-controller/go.mod | 2 +- .../operator/config/webhook/manifests.yaml | 40 +++++++++++++++++++ .../internal/operator/operator.go | 5 +++ common-go-libs/config/webhook/manifests.yaml | 40 +++++++++++++++++++ .../adapter-mutating-webhook-config.yaml | 4 +- .../adapter-validation-webhook-config.yaml | 4 +- 7 files changed, 130 insertions(+), 5 deletions(-) diff --git a/adapter/internal/operator/config/webhook/manifests.yaml b/adapter/internal/operator/config/webhook/manifests.yaml index b13c9e7c4..e8cd2e25b 100644 --- a/adapter/internal/operator/config/webhook/manifests.yaml +++ b/adapter/internal/operator/config/webhook/manifests.yaml @@ -204,6 +204,26 @@ webhooks: resources: - interceptorservices sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: mratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None - admissionReviewVersions: - v1 clientConfig: @@ -430,6 +450,26 @@ webhooks: resources: - interceptorservices sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: vratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None - admissionReviewVersions: - v1 clientConfig: diff --git a/common-controller/go.mod b/common-controller/go.mod index d5707c7a8..a2b34d9c8 100644 --- a/common-controller/go.mod +++ b/common-controller/go.mod @@ -22,7 +22,7 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/redis/go-redis/v9 v9.2.1 github.com/wso2/apk/adapter v0.0.0-20231214082511-af2c8b8a19f1 - github.com/wso2/apk/common-go-libs v0.0.0-20240304050809-a382bc6b0d82 + github.com/wso2/apk/common-go-libs v0.0.0-20240923143402-ff7fdb0366f9 google.golang.org/grpc v1.65.0 ) diff --git a/common-controller/internal/operator/config/webhook/manifests.yaml b/common-controller/internal/operator/config/webhook/manifests.yaml index 233b8cad7..d34315615 100644 --- a/common-controller/internal/operator/config/webhook/manifests.yaml +++ b/common-controller/internal/operator/config/webhook/manifests.yaml @@ -204,6 +204,26 @@ webhooks: resources: - interceptorservices sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: mratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None - admissionReviewVersions: - v1 clientConfig: @@ -430,6 +450,26 @@ webhooks: resources: - interceptorservices sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: vratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None - admissionReviewVersions: - v1 clientConfig: diff --git a/common-controller/internal/operator/operator.go b/common-controller/internal/operator/operator.go index 6ab3078c6..77684918c 100644 --- a/common-controller/internal/operator/operator.go +++ b/common-controller/internal/operator/operator.go @@ -147,6 +147,11 @@ func InitOperator(metricsConfig config.Metrics) { "Unable to create webhook for Ratelimit, error: %v", err)) } + if err = (&dpv1alpha3.RateLimitPolicy{}).SetupWebhookWithManager(mgr); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2637, logging.MAJOR, + "Unable to create webhook for Ratelimit, error: %v", err)) + } + if err = (&dpv1alpha3.APIPolicy{}).SetupWebhookWithManager(mgr); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2638, logging.MAJOR, "Unable to create webhook for APIPolicy, error: %v", err)) diff --git a/common-go-libs/config/webhook/manifests.yaml b/common-go-libs/config/webhook/manifests.yaml index f4a9f4cd1..34dcc46bd 100644 --- a/common-go-libs/config/webhook/manifests.yaml +++ b/common-go-libs/config/webhook/manifests.yaml @@ -184,6 +184,46 @@ webhooks: resources: - interceptorservices sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: mratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None +- admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-dp-wso2-com-v1alpha3-ratelimitpolicy + failurePolicy: Fail + name: mratelimitpolicy.kb.io + rules: + - apiGroups: + - dp.wso2.com + apiVersions: + - v1alpha3 + operations: + - CREATE + - UPDATE + resources: + - ratelimitpolicies + sideEffects: None - admissionReviewVersions: - v1 clientConfig: diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-mutating-webhook-config.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-mutating-webhook-config.yaml index f254504fd..a33cdac0e 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-mutating-webhook-config.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-mutating-webhook-config.yaml @@ -112,14 +112,14 @@ webhooks: service: name: {{ template "apk-helm.resource.prefix" . }}-common-controller-service namespace: {{ .Release.Namespace }} - path: /mutate-dp-wso2-com-v1alpha1-ratelimitpolicy + path: /mutate-dp-wso2-com-v1alpha3-ratelimitpolicy failurePolicy: Fail name: mratelimitpolicy.kb.io rules: - apiGroups: - dp.wso2.com apiVersions: - - v1alpha1 + - v1alpha3 operations: - CREATE - UPDATE diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-validation-webhook-config.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-validation-webhook-config.yaml index 3bec9878d..df7f197b7 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-validation-webhook-config.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/webhook/adapter-validation-webhook-config.yaml @@ -112,14 +112,14 @@ webhooks: service: name: {{ template "apk-helm.resource.prefix" . }}-common-controller-service namespace: {{ .Release.Namespace }} - path: /validate-dp-wso2-com-v1alpha1-ratelimitpolicy + path: /validate-dp-wso2-com-v1alpha3-ratelimitpolicy failurePolicy: Fail name: vratelimitpolicy.kb.io rules: - apiGroups: - dp.wso2.com apiVersions: - - v1alpha1 + - v1alpha3 operations: - CREATE - UPDATE From 8e82374f81ee329dcfe381c23e690d0932272420 Mon Sep 17 00:00:00 2001 From: krish Date: Tue, 24 Sep 2024 14:20:31 +0530 Subject: [PATCH 2/4] Update fail test --- test/cucumber-tests/CRs/artifacts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cucumber-tests/CRs/artifacts.yaml b/test/cucumber-tests/CRs/artifacts.yaml index 2bbeb801a..2ae8aefb8 100644 --- a/test/cucumber-tests/CRs/artifacts.yaml +++ b/test/cucumber-tests/CRs/artifacts.yaml @@ -773,7 +773,7 @@ spec: --- -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha3" kind: "RateLimitPolicy" metadata: name: "api-subscription-ratelimit" From e96b6d82c04671c590ab889cd3dc923e7db88f59 Mon Sep 17 00:00:00 2001 From: krish Date: Tue, 24 Sep 2024 15:29:28 +0530 Subject: [PATCH 3/4] Fail test --- test/cucumber-tests/CRs/artifacts.yaml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/cucumber-tests/CRs/artifacts.yaml b/test/cucumber-tests/CRs/artifacts.yaml index 2ae8aefb8..b0b01e37b 100644 --- a/test/cucumber-tests/CRs/artifacts.yaml +++ b/test/cucumber-tests/CRs/artifacts.yaml @@ -912,10 +912,30 @@ spec: name: "Semantic Versioning API" version: "v\\d+(\\.\\d+)?" ratelimitRef: - name: api-subscription-ratelimit + name: api--sem-subscription-ratelimit level: application --- +apiVersion: "dp.wso2.com/v1alpha3" +kind: "RateLimitPolicy" +metadata: + name: "api--sem-subscription-ratelimit" +spec: + override: + subscription: + stopOnQuotaReach: true + organization: "default" + requestCount: + requestsPerUnit: 4 + unit: "Minute" + burstControl: + requestsPerUnit: 4 + unit: "Minute" + targetRef: + kind: Subscription + name: "7416c241a121b844392d447f00ff6709cb9c932b" + group: gateway.networking.k8s.io +--- apiVersion: cp.wso2.com/v1alpha2 kind: ApplicationMapping metadata: From 9cb00e1911875a26a3f67c018d6baa606798372d Mon Sep 17 00:00:00 2001 From: krish Date: Tue, 24 Sep 2024 21:33:06 +0530 Subject: [PATCH 4/4] Update test --- test/cucumber-tests/CRs/artifacts.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cucumber-tests/CRs/artifacts.yaml b/test/cucumber-tests/CRs/artifacts.yaml index b0b01e37b..a4a64a574 100644 --- a/test/cucumber-tests/CRs/artifacts.yaml +++ b/test/cucumber-tests/CRs/artifacts.yaml @@ -926,10 +926,10 @@ spec: stopOnQuotaReach: true organization: "default" requestCount: - requestsPerUnit: 4 + requestsPerUnit: 50 unit: "Minute" burstControl: - requestsPerUnit: 4 + requestsPerUnit: 50 unit: "Minute" targetRef: kind: Subscription