Skip to content

Commit f5f3d03

Browse files
rdksapn3rdc4ptn
andauthored
feat: set default values for kyverno if activated via env var (#229)
* feat: set default values for kyverno if activated via env var On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> * feat: add env to helm chart deployment tempalte and values On-behalf-of: Radek Schekalla (SAP) <[email protected]> Signed-off-by: Radek Schekalla (SAP) <[email protected]> * Update internal/controller/core/cloudorchestrator/controller.go Co-authored-by: Moritz Marby <[email protected]> * Update internal/controller/core/cloudorchestrator/controller.go Co-authored-by: Moritz Marby <[email protected]> --------- Signed-off-by: Radek Schekalla (SAP) <[email protected]> Co-authored-by: Moritz Marby <[email protected]>
1 parent a9aefcf commit f5f3d03

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

charts/mcp-operator/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ spec:
9191
{{- if .Values.apiserver.worker.intervalTime }}
9292
- --apiserver-worker-interval={{ .Values.apiserver.worker.intervalTime }}
9393
{{- end }}
94+
env:
95+
{{- with .Values.managedcontrolplane.extraEnv }}
96+
{{- toYaml . | nindent 10 }}
97+
{{- end }}
9498
ports:
9599
{{- if not .Values.webhooks.disabled }}
96100
- name: webhooks-https

charts/mcp-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ webhooks:
5454
managedcontrolplane:
5555
disabled: false
5656

57+
# Extra environment variables to add to the init container.
58+
extraEnv: [ ]
59+
5760
apiserver:
5861
disabled: false
5962
# architecture:

internal/controller/core/cloudorchestrator/controller.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"os"
89
"strings"
910
"time"
1011

@@ -42,6 +43,43 @@ import (
4243
const (
4344
defaultNamespace string = "openmcp-system" // TODO make this configurable
4445
ControllerName string = "CloudOrchestrator"
46+
47+
envEnableKyvernoDefaultValues string = "ENABLE_KYVERNO_DEFAULT_VALUES"
48+
kyvernoDefaultValues string = `{
49+
"config": {
50+
"excludeGroups": [
51+
"system:nodes"
52+
],
53+
"preserve": false,
54+
"resourceFilters": [
55+
"[*/*,kyverno,*]",
56+
"[*/*,istio-system,*]",
57+
"[*/*,kyma-system,*]",
58+
"[*/*,kube-system,*]",
59+
"[*/*,kube-public,*]",
60+
61+
],
62+
"updateRequestThreshold": 5000,
63+
"webhooks": {
64+
"namespaceSelector": {
65+
"matchExpressions": [
66+
{
67+
"key": "kubernetes.io/metadata.name",
68+
"operator": "NotIn",
69+
"values": [
70+
"kube-system",
71+
"kyverno",
72+
"istio-system",
73+
"kube-public",
74+
"kyma-system",
75+
76+
]
77+
}
78+
]
79+
}
80+
}
81+
}
82+
}`
4583
)
4684

4785
var (
@@ -367,8 +405,14 @@ func convertToControlPlaneSpec(coSpec *openmcpv1alpha1.CloudOrchestratorSpec, ap
367405
}
368406

369407
if coSpec.Kyverno != nil {
408+
var values *apiextensionsv1.JSON
409+
if os.Getenv(envEnableKyvernoDefaultValues) == "true" {
410+
values = &apiextensionsv1.JSON{Raw: []byte(kyvernoDefaultValues)}
411+
}
412+
370413
controlPlaneSpec.Kyverno = &corev1beta1.KyvernoConfig{
371414
Version: coSpec.Kyverno.Version,
415+
Values: values,
372416
}
373417
}
374418

0 commit comments

Comments
 (0)