The Deployment metadata inlined the annotation and label logic with nested `if` blocks, which duplicated the fallback handling and made the empty-value cases hard to follow. Moving the rendering into `gitea.deployment.annotations` and `gitea.deployment.labels` keeps the manifest declarative and allows other resources to reuse the same merge semantics later on. The helpers are consumed through `with (include ... | fromYaml)` so that an empty result never emits a dangling `annotations:` key. Labels always render because `gitea.labels` is never empty, which keeps Argo CD from reporting drift. Inside the label helper the user labels are appended with an untrimmed newline, otherwise they would be concatenated onto the last line of `gitea.labels` and `fromYaml` would silently return an `Error` map instead of failing the render. The metadata attributes are additionally sorted alphabetically to follow the chart conventions. Unit tests now cover the previously untested `deployment.annotations` value and assert that the base labels keep rendering despite the new `with` guard. Co-authored-by: Copilot <copilot@github.com>
376 lines
11 KiB
YAML
376 lines
11 KiB
YAML
suite: deployment template (basic)
|
|
release:
|
|
name: gitea-unittests
|
|
namespace: testing
|
|
templates:
|
|
- templates/gitea/deployment.yaml
|
|
- templates/gitea/secret_admin.yaml
|
|
- templates/gitea/secret_config.yaml
|
|
- templates/gitea/secret_gpg.yaml
|
|
- templates/gitea/secret_init.yaml
|
|
- templates/gitea/secret_inlineConfig.yaml
|
|
- templates/gitea/secret_metrics.yaml
|
|
tests:
|
|
- it: renders a deployment
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 1
|
|
- containsDocument:
|
|
kind: Deployment
|
|
apiVersion: apps/v1
|
|
name: gitea-unittests
|
|
- it: renders no deployment when disabled
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.enabled: false
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 0
|
|
- it: deployment labels are set
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.labels:
|
|
hello: world
|
|
asserts:
|
|
- isSubset:
|
|
path: metadata.labels
|
|
content:
|
|
hello: world
|
|
- isSubset:
|
|
path: spec.template.metadata.labels
|
|
content:
|
|
hello: world
|
|
- isNotSubset:
|
|
path: spec.selector.matchLabels
|
|
content:
|
|
hello: world
|
|
- it: deployment labels are not in selector matchLabels
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.labels:
|
|
custom-label: custom-value
|
|
another-label: another-value
|
|
asserts:
|
|
- equal:
|
|
path: spec.selector.matchLabels
|
|
value:
|
|
app.kubernetes.io/name: gitea
|
|
app.kubernetes.io/instance: gitea-unittests
|
|
- it: deployment labels are always rendered
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- isSubset:
|
|
path: metadata.labels
|
|
content:
|
|
app: gitea
|
|
app.kubernetes.io/name: gitea
|
|
app.kubernetes.io/instance: gitea-unittests
|
|
app.kubernetes.io/managed-by: Helm
|
|
- it: deployment annotations are undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: metadata.annotations
|
|
- it: deployment annotations are set
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.annotations:
|
|
hello: world
|
|
asserts:
|
|
- equal:
|
|
path: metadata.annotations
|
|
value:
|
|
hello: world
|
|
- it: nodeSelector is undefined
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.nodeSelector
|
|
template: templates/gitea/deployment.yaml
|
|
- it: nodeSelector is defined
|
|
set:
|
|
deployment.nodeSelector:
|
|
foo: bar
|
|
bar: foo
|
|
asserts:
|
|
- isSubset:
|
|
path: spec.template.spec.nodeSelector
|
|
content:
|
|
foo: bar
|
|
bar: foo
|
|
template: templates/gitea/deployment.yaml
|
|
- it: affinity is undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.affinity
|
|
- it: affinity is defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.affinity:
|
|
nodeAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
nodeSelectorTerms:
|
|
- matchExpressions:
|
|
- key: kubernetes.io/os
|
|
operator: In
|
|
values:
|
|
- linux
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.affinity
|
|
value:
|
|
nodeAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
nodeSelectorTerms:
|
|
- matchExpressions:
|
|
- key: kubernetes.io/os
|
|
operator: In
|
|
values:
|
|
- linux
|
|
- it: dnsConfig is undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.dnsConfig
|
|
- it: dnsConfig is defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.dnsConfig:
|
|
nameservers:
|
|
- 192.0.2.1
|
|
options:
|
|
- name: ndots
|
|
value: "2"
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.dnsConfig
|
|
value:
|
|
nameservers:
|
|
- 192.0.2.1
|
|
options:
|
|
- name: ndots
|
|
value: "2"
|
|
- it: priorityClassName is undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.priorityClassName
|
|
- it: priorityClassName is defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.priorityClassName: high-priority
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.priorityClassName
|
|
value: high-priority
|
|
- it: schedulerName is undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.schedulerName
|
|
- it: schedulerName is defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.schedulerName: stork
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.schedulerName
|
|
value: stork
|
|
- it: strategy defaults to a rolling update
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- equal:
|
|
path: spec.strategy
|
|
value:
|
|
type: RollingUpdate
|
|
rollingUpdate:
|
|
maxUnavailable: 0
|
|
maxSurge: 100%
|
|
- it: strategy omits rollingUpdate for other strategy types
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.strategy.type: Recreate
|
|
asserts:
|
|
- equal:
|
|
path: spec.strategy
|
|
value:
|
|
type: Recreate
|
|
- it: tolerations are undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.tolerations
|
|
- it: tolerations are defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.tolerations:
|
|
- key: database/type
|
|
operator: Equal
|
|
value: postgres
|
|
effect: NoSchedule
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.tolerations
|
|
value:
|
|
- key: database/type
|
|
operator: Equal
|
|
value: postgres
|
|
effect: NoSchedule
|
|
- it: topologySpreadConstraints are undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.topologySpreadConstraints
|
|
- it: topologySpreadConstraints are defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.topologySpreadConstraints:
|
|
- topologyKey: kubernetes.io/hostname
|
|
whenUnsatisfiable: DoNotSchedule
|
|
maxSkew: 1
|
|
labelSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/instance: gitea-unittests
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.topologySpreadConstraints
|
|
value:
|
|
- topologyKey: kubernetes.io/hostname
|
|
whenUnsatisfiable: DoNotSchedule
|
|
maxSkew: 1
|
|
labelSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/instance: gitea-unittests
|
|
|
|
- it: "injects TMP_EXISTING_ENVS_FILE as environment variable to 'init-app-ini' init container"
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.initContainers[1].env
|
|
content:
|
|
name: TMP_EXISTING_ENVS_FILE
|
|
value: /tmp/existing-envs
|
|
- it: "injects ENV_TO_INI_MOUNT_POINT as environment variable to 'init-app-ini' init container"
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.initContainers[1].env
|
|
content:
|
|
name: ENV_TO_INI_MOUNT_POINT
|
|
value: /env-to-ini-mounts
|
|
- it: "deployment.gitea.env is injected into all init containers and the gitea container"
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.gitea.env:
|
|
- name: VARIABLE
|
|
value: my-value
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.initContainers[0].env
|
|
content:
|
|
name: VARIABLE
|
|
value: my-value
|
|
- contains:
|
|
path: spec.template.spec.initContainers[1].env
|
|
content:
|
|
name: VARIABLE
|
|
value: my-value
|
|
- contains:
|
|
path: spec.template.spec.initContainers[2].env
|
|
content:
|
|
name: VARIABLE
|
|
value: my-value
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: VARIABLE
|
|
value: my-value
|
|
- it: CPU resources are defined as well as GOMAXPROCS
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.gitea.resources:
|
|
limits:
|
|
cpu: 200ms
|
|
memory: 200Mi
|
|
requests:
|
|
cpu: 100ms
|
|
memory: 100Mi
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: GOMAXPROCS
|
|
valueFrom:
|
|
resourceFieldRef:
|
|
divisor: "1"
|
|
resource: limits.cpu
|
|
- equal:
|
|
path: spec.template.spec.containers[0].resources
|
|
value:
|
|
limits:
|
|
cpu: 200ms
|
|
memory: 200Mi
|
|
requests:
|
|
cpu: 100ms
|
|
memory: 100Mi
|
|
- it: container resources default to an empty map and GOMAXPROCS is omitted
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.containers[0].resources
|
|
value: {}
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: GOMAXPROCS
|
|
valueFrom:
|
|
resourceFieldRef:
|
|
divisor: "1"
|
|
resource: limits.cpu
|
|
- it: pod level resources are undefined
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.resources
|
|
- it: pod level resources are defined
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
deployment.resources:
|
|
limits:
|
|
cpu: 500m
|
|
memory: 512Mi
|
|
requests:
|
|
cpu: 250m
|
|
memory: 256Mi
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.resources
|
|
value:
|
|
limits:
|
|
cpu: 500m
|
|
memory: 512Mi
|
|
requests:
|
|
cpu: 250m
|
|
memory: 256Mi
|
|
- it: Init containers have correct volumeMount path
|
|
template: templates/gitea/deployment.yaml
|
|
set:
|
|
initContainersScriptsVolumeMountPath: "/custom/init/path"
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath
|
|
value: "/custom/init/path"
|
|
- equal:
|
|
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath
|
|
value: "/custom/init/path"
|
|
- it: Init containers have correct volumeMount path if there is no override
|
|
template: templates/gitea/deployment.yaml
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath
|
|
value: "/usr/sbinx"
|
|
- equal:
|
|
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath
|
|
value: "/usr/sbinx"
|