forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix mutating the "/metadata/serverAddress" section of a keda.s/v…
…1alpha1/ScaledObject object (kyverno#5374) * fix: fix mutating the "/metadata/serverAddress" section of a keda.sh/v1alpha1/ScaledObject object Signed-off-by: Rodrigo Fior Kuntzer <[email protected]> * fix: update test policy Signed-off-by: Rodrigo Fior Kuntzer <[email protected]> Signed-off-by: Rodrigo Fior Kuntzer <[email protected]> Co-authored-by: shuting <[email protected]>
- Loading branch information
1 parent
a09d2a7
commit 08447c1
Showing
8 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: mutate-keda-scaled-object | ||
policies: | ||
- policy.yaml | ||
resources: | ||
- resources.yaml | ||
results: | ||
- policy: keda-prometheus-serveraddress | ||
rule: keda-prometheus-serveraddress | ||
resources: [service-1] | ||
patchedResource: patchedResource1.yaml | ||
kind: ScaledObject | ||
result: pass | ||
- policy: keda-prometheus-serveraddress | ||
rule: keda-prometheus-serveraddress | ||
resources: [service-2] | ||
patchedResource: patchedResource2.yaml | ||
kind: ScaledObject | ||
result: pass | ||
- policy: keda-prometheus-serveraddress | ||
rule: keda-prometheus-serveraddress | ||
resources: [service-3] | ||
patchedResource: patchedResource3.yaml | ||
kind: ScaledObject | ||
result: pass |
13 changes: 13 additions & 0 deletions
13
test/cli/test/mutate-keda-scaled-object/patchedResource1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-1 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "prometheus" | ||
metadata: | ||
metricName: my-metric-name | ||
query: sum(waiting_jobs_total{job='some-job'}) | ||
serverAddress: http://prometheus.local/ | ||
threshold: "100" |
13 changes: 13 additions & 0 deletions
13
test/cli/test/mutate-keda-scaled-object/patchedResource2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-2 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "prometheus" | ||
metadata: | ||
metricName: my-metric-name | ||
query: sum(waiting_jobs_total{job='some-job'}) | ||
serverAddress: http://prometheus.local/ | ||
threshold: "50" |
12 changes: 12 additions & 0 deletions
12
test/cli/test/mutate-keda-scaled-object/patchedResource3.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-3 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "aws-sqs-queue" | ||
metadata: | ||
queueURL: https://sqs.eu-west-1.amazonaws.com/account_id/QueueName | ||
queueLength: "5" | ||
awsRegion: "eu-west-1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion : kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: keda-prometheus-serveraddress | ||
annotations: | ||
policies.kyverno.io/title: Set KEDA Prometheus Scaler ServerAddress | ||
policies.kyverno.io/subject: KedaPrometheusScaler | ||
policies.kyverno.io/description: >- | ||
The KEDA Prometheus Scaler requires the serverAddress attribute. | ||
spec: | ||
background: false | ||
rules: | ||
- name: keda-prometheus-serveraddress | ||
match: | ||
all: | ||
- resources: | ||
kinds: | ||
- keda.sh/v1alpha1/ScaledObject | ||
preconditions: | ||
all: | ||
- key: "{{request.operation}}" | ||
operator: In | ||
value: | ||
- CREATE | ||
- UPDATE | ||
mutate: | ||
foreach: | ||
- list: "request.object.spec.triggers" | ||
preconditions: | ||
all: | ||
- key: "{{element.type || ''}}" | ||
operator: Equals | ||
value: "prometheus" | ||
patchesJson6902: |- | ||
- path: /spec/triggers/{{elementIndex}}/metadata/serverAddress | ||
op: add | ||
value: "http://prometheus.local/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-1 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "prometheus" | ||
metadata: | ||
metricName: my-metric-name | ||
query: sum(waiting_jobs_total{job='some-job'}) | ||
serverAddress: http://prometheus.internal.svc.cluster.local:9090 | ||
threshold: "100" | ||
--- | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-2 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "prometheus" | ||
metadata: | ||
metricName: my-metric-name | ||
query: sum(waiting_jobs_total{job='some-job'}) | ||
threshold: "50" | ||
--- | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: service-3 | ||
namespace: default | ||
spec: | ||
triggers: | ||
- type: "aws-sqs-queue" | ||
metadata: | ||
queueURL: https://sqs.eu-west-1.amazonaws.com/account_id/QueueName | ||
queueLength: "5" | ||
awsRegion: "eu-west-1" |