Files
Juan Luis RosaandGitHub 6b73e2e362 Add deploymentAnnotations to controller and webhook deployments (#3001)
* support deployment annotations in helm chart

Signed-off-by: Juan Luis Rosa Martinez <[email protected]>

* apply codereview suggestions

Signed-off-by: Juan Luis Rosa Martinez <[email protected]>

* update README.md

Signed-off-by: Juan Luis Rosa Martinez <[email protected]>

---------

Signed-off-by: Juan Luis Rosa Martinez <[email protected]>
2026-06-26 19:17:37 +00:00

661 lines
19 KiB
YAML

#
# Copyright 2024 The Kubeflow authors.
#
# 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
#
# https://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.
#
suite: Test webhook deployment
templates:
- webhook/deployment.yaml
release:
name: spark-operator
namespace: spark-operator
tests:
- it: Should create webhook deployment by default
asserts:
- containsDocument:
apiVersion: apps/v1
kind: Deployment
name: spark-operator-webhook
- it: Should not create webhook deployment if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0
- it: Should set replicas if `webhook.replicas` is set
set:
webhook:
replicas: 10
asserts:
- equal:
path: spec.replicas
value: 10
- it: Should set replicas if `webhook.replicas` is set
set:
webhook:
replicas: 0
asserts:
- equal:
path: spec.replicas
value: 0
- it: Should set revisionHistoryLimit to the default value
asserts:
- equal:
path: spec.revisionHistoryLimit
value: 10
- it: Should set revisionHistoryLimit if `controller.revisionHistoryLimit` is set
set:
webhook:
revisionHistoryLimit: 2
asserts:
- equal:
path: spec.revisionHistoryLimit
value: 2
- it: Should add pod labels if `webhook.labels` is set
set:
webhook:
labels:
key1: value1
key2: value2
asserts:
- equal:
path: spec.template.metadata.labels.key1
value: value1
- equal:
path: spec.template.metadata.labels.key2
value: value2
- it: Should add pod annotations if `webhook.annotations` is set
set:
webhook:
annotations:
key1: value1
key2: value2
asserts:
- equal:
path: spec.template.metadata.annotations.key1
value: value1
- equal:
path: spec.template.metadata.annotations.key2
value: value2
- it: Should add deployment annotations if `webhook.deploymentAnnotations` is set
set:
webhook:
deploymentAnnotations:
key1: value1
key2: value2
asserts:
- equal:
path: metadata.annotations.key1
value: value1
- equal:
path: metadata.annotations.key2
value: value2
- it: Should use the specified image repository if `image.registry`, `image.repository` and `image.tag` are set
set:
image:
registry: test-registry
repository: test-repository
tag: test-tag
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: test-registry/test-repository:test-tag
- it: Should use the specified image pull policy if `image.pullPolicy` is set
set:
image:
pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Always
- it: Should contain `--zap-log-level` arg if `webhook.logLevel` is set
set:
webhook:
logLevel: debug
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --zap-log-level=debug
- it: Should contain `--namespaces` arg if `spark.jobNamespaces` is set
set:
spark.jobNamespaces:
- ns1
- ns2
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --namespaces=ns1,ns2
- it: Should set namespaces to all namespaces (`""`) if `spark.jobNamespaces` contains empty string
set:
spark:
jobNamespaces:
- ""
- default
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --namespaces=""
- it: Should contain `--enable-metrics` arg if `prometheus.metrics.enable` is set to `true`
set:
prometheus:
metrics:
enable: true
port: 12345
portName: test-port
endpoint: /test-endpoint
prefix: test-prefix
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --enable-metrics=true
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --metrics-bind-address=:12345
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --metrics-endpoint=/test-endpoint
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --metrics-prefix=test-prefix
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --metrics-labels=app_type
- it: Should enable leader election by default
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --leader-election=true
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --leader-election-lock-name=spark-operator-webhook-lock
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --leader-election-lock-namespace=spark-operator
- it: Should disable leader election if `webhook.leaderElection.enable` is set to `false`
set:
webhook:
leaderElection:
enable: false
asserts:
- contains:
path: spec.template.spec.containers[?(@.name=="spark-operator-webhook")].args
content: --leader-election=false
- it: Should add webhook port
set:
webhook:
port: 12345
portName: test-port
asserts:
- contains:
path: spec.template.spec.containers[0].ports
content:
name: test-port
containerPort: 12345
- it: Should add metric port if `prometheus.metrics.enable` is true
set:
prometheus:
metrics:
enable: true
port: 10254
portName: metrics
asserts:
- contains:
path: spec.template.spec.containers[0].ports
content:
name: metrics
containerPort: 10254
count: 1
- it: Should add environment variables if `webhook.env` is set
set:
webhook:
env:
- name: ENV_NAME_1
value: ENV_VALUE_1
- name: ENV_NAME_2
valueFrom:
configMapKeyRef:
name: test-configmap
key: test-key
optional: false
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: ENV_NAME_1
value: ENV_VALUE_1
- contains:
path: spec.template.spec.containers[0].env
content:
name: ENV_NAME_2
valueFrom:
configMapKeyRef:
name: test-configmap
key: test-key
optional: false
- it: Should add environment variable sources if `webhook.envFrom` is set
set:
webhook:
envFrom:
- configMapRef:
name: test-configmap
optional: false
- secretRef:
name: test-secret
optional: false
asserts:
- contains:
path: spec.template.spec.containers[0].envFrom
content:
configMapRef:
name: test-configmap
optional: false
- contains:
path: spec.template.spec.containers[0].envFrom
content:
secretRef:
name: test-secret
optional: false
- it: Should add volume mounts if `webhook.volumeMounts` is set
set:
webhook:
volumeMounts:
- name: volume1
mountPath: /volume1
- name: volume2
mountPath: /volume2
asserts:
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: volume1
mountPath: /volume1
count: 1
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: volume2
mountPath: /volume2
count: 1
- it: Should add resources if `webhook.resources` is set
set:
webhook:
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
asserts:
- equal:
path: spec.template.spec.containers[0].resources
value:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
- it: Should add container securityContext if `webhook.securityContext` is set
set:
webhook:
securityContext:
readOnlyRootFilesystem: true
runAsUser: 1000
runAsGroup: 2000
fsGroup: 3000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
runAsNonRoot: true
privileged: false
asserts:
- equal:
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
value: true
- equal:
path: spec.template.spec.containers[0].securityContext.runAsUser
value: 1000
- equal:
path: spec.template.spec.containers[0].securityContext.runAsGroup
value: 2000
- equal:
path: spec.template.spec.containers[0].securityContext.fsGroup
value: 3000
- equal:
path: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
value: false
- equal:
path: spec.template.spec.containers[0].securityContext.capabilities
value:
drop:
- ALL
- equal:
path: spec.template.spec.containers[0].securityContext.runAsNonRoot
value: true
- equal:
path: spec.template.spec.containers[0].securityContext.privileged
value: false
- it: Should add sidecars if `webhook.sidecars` is set
set:
webhook:
sidecars:
- name: sidecar1
image: sidecar-image1
- name: sidecar2
image: sidecar-image2
asserts:
- contains:
path: spec.template.spec.containers
content:
name: sidecar1
image: sidecar-image1
- contains:
path: spec.template.spec.containers
content:
name: sidecar2
image: sidecar-image2
- it: Should add secrets if `image.pullSecrets` is set
set:
image:
pullSecrets:
- name: test-secret1
- name: test-secret2
asserts:
- equal:
path: spec.template.spec.imagePullSecrets[0].name
value: test-secret1
- equal:
path: spec.template.spec.imagePullSecrets[1].name
value: test-secret2
- it: Should add volumes if `webhook.volumes` is set
set:
webhook:
volumes:
- name: volume1
emptyDir: {}
- name: volume2
emptyDir: {}
asserts:
- contains:
path: spec.template.spec.volumes
content:
name: volume1
emptyDir: {}
count: 1
- contains:
path: spec.template.spec.volumes
content:
name: volume2
emptyDir: {}
count: 1
- it: Should add nodeSelector if `webhook.nodeSelector` is set
set:
webhook:
nodeSelector:
key1: value1
key2: value2
asserts:
- equal:
path: spec.template.spec.nodeSelector.key1
value: value1
- equal:
path: spec.template.spec.nodeSelector.key2
value: value2
- it: Should add affinity if `webhook.affinity` is set
set:
webhook:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
asserts:
- equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
- it: Should add tolerations if `webhook.tolerations` is set
set:
webhook:
tolerations:
- key: key1
operator: Equal
value: value1
effect: NoSchedule
- key: key2
operator: Exists
effect: NoSchedule
asserts:
- equal:
path: spec.template.spec.tolerations
value:
- key: key1
operator: Equal
value: value1
effect: NoSchedule
- key: key2
operator: Exists
effect: NoSchedule
- it: Should add priorityClassName if `webhook.priorityClassName` is set
set:
webhook:
priorityClassName: test-priority-class
asserts:
- equal:
path: spec.template.spec.priorityClassName
value: test-priority-class
- it: Should add pod securityContext if `webhook.podSecurityContext` is set
set:
webhook:
podSecurityContext:
runAsUser: 1000
runAsGroup: 2000
fsGroup: 3000
asserts:
- equal:
path: spec.template.spec.securityContext.runAsUser
value: 1000
- equal:
path: spec.template.spec.securityContext.runAsGroup
value: 2000
- equal:
path: spec.template.spec.securityContext.fsGroup
value: 3000
- it: Should not contain topologySpreadConstraints if `webhook.topologySpreadConstraints` is not set
set:
webhook:
topologySpreadConstraints: []
asserts:
- notExists:
path: spec.template.spec.topologySpreadConstraints
- it: Should add topologySpreadConstraints if `webhook.topologySpreadConstraints` is set and `webhook.replicas` is greater than 1
set:
webhook:
replicas: 2
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
asserts:
- equal:
path: spec.template.spec.topologySpreadConstraints
value:
- labelSelector:
matchLabels:
app.kubernetes.io/component: webhook
app.kubernetes.io/instance: spark-operator
app.kubernetes.io/name: spark-operator
maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
- labelSelector:
matchLabels:
app.kubernetes.io/component: webhook
app.kubernetes.io/instance: spark-operator
app.kubernetes.io/name: spark-operator
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
- it: Should fail if `webhook.topologySpreadConstraints` is set and `webhook.replicas` is not greater than 1
set:
webhook:
replicas: 1
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
asserts:
- failedTemplate:
errorMessage: "webhook.replicas must be greater than 1 to enable topology spread constraints for webhook pods"
- it: Should include hostUsers when kubernetes version >= 1.30 and hostUsers is true
capabilities:
majorVersion: 1
minorVersion: 30
set:
webhook:
hostUsers: true
asserts:
- equal:
path: spec.template.spec.hostUsers
value: true
- it: Should include hostUsers when kubernetes version >= 1.30 and hostUsers is false
capabilities:
majorVersion: 1
minorVersion: 34
set:
webhook:
hostUsers: false
asserts:
- equal:
path: spec.template.spec.hostUsers
value: false
- it: Should not contain hostUsers when kubernetes version < 1.29 and hostUsers is set
capabilities:
majorVersion: 1
minorVersion: 29
set:
webhook:
hostUsers: true
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: Should not include hostUsers when kubernetes version >= 1.30 but value not set
capabilities:
majorVersion: 1
minorVersion: 34
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: Should should NOT include hostUsers when kubernetes version >= 1.30 but value is string
capabilities:
majorVersion: 1
minorVersion: 34
set:
webhook:
hostUsers: "true"
asserts:
- notExists:
path: spec.template.spec.hostUsers
- it: Should not include hostUsers when kubernetes version >= 1.30 but value is null
capabilities:
majorVersion: 1
minorVersion: 34
set:
webhook:
hostUsers: null
asserts:
- notExists:
path: spec.template.spec.hostUsers