Bash / shellcheck (push) Successful in 7s
Bash / bash-unittest (push) Successful in 25s
changelog / changelog (push) Successful in 15s
Helm / helm-lint (push) Successful in 13s
Helm / helm-unittest (push) Successful in 20s
Markdown linter / markdown-lint (push) Successful in 18s
Markdown linter / markdown-link-checker (push) Successful in 52s
A HA `Cluster` is only actually highly available if its instances end up in different failure domains. Pod
anti-affinity alone cannot express that: it only keeps the instances off the same node, not off the same zone,
and `cloudnativePG.affinity` has no way to encode a skew budget. Without `topologySpreadConstraints` a three
instance cluster can legitimately be scheduled into a single availability zone, where a zone outage takes down
the primary and both replicas at once.
Both `affinity` and `topologySpreadConstraints` are rendered only when they are set. The CloudNativePG API
declares them as `omitempty`, so an empty `{}` or `[]` in the manifest would show up as a permanent diff against
the state the operator writes back.
Tolerations deliberately do not get a dedicated value. CloudNativePG has no `spec.tolerations`, it nests them
below `spec.affinity.tolerations`, so they are configured through `cloudnativePG.affinity` like `nodeSelector`
and the anti-affinity settings. A separate top-level value would only have to be folded back into the same place
and would silently conflict with a tolerations list set via `cloudnativePG.affinity`.
Co-authored-by: Copilot <copilot@github.com>
183 lines
4.8 KiB
YAML
183 lines
4.8 KiB
YAML
suite: Test cluster basics
|
|
release:
|
|
name: gitea-unittests
|
|
namespace: testing
|
|
tests:
|
|
- it: "Render nothing when cloudnativePG is disabled"
|
|
templates:
|
|
- templates/cluster.yaml
|
|
- templates/secret_cloudnativePG.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: false
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 0
|
|
|
|
- it: "Render the Cluster with the default values"
|
|
template: templates/cluster.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
asserts:
|
|
- containsDocument:
|
|
kind: Cluster
|
|
apiVersion: postgresql.cnpg.io/v1
|
|
name: gitea-unittests-postgresql
|
|
namespace: testing
|
|
- equal:
|
|
path: spec.instances
|
|
value: 3
|
|
- equal:
|
|
path: spec.imageName
|
|
value: "ghcr.io/cloudnative-pg/postgresql:18.0"
|
|
- equal:
|
|
path: spec.bootstrap.initdb
|
|
value:
|
|
database: "gitea"
|
|
owner: "gitea"
|
|
secret:
|
|
name: gitea-unittests-postgresql-app
|
|
- equal:
|
|
path: spec.storage.size
|
|
value: "10Gi"
|
|
- notExists:
|
|
path: spec.storage.storageClass
|
|
- notExists:
|
|
path: spec.walStorage
|
|
- notExists:
|
|
path: spec.affinity
|
|
- notExists:
|
|
path: spec.topologySpreadConstraints
|
|
|
|
- it: "Render the credential Secret with the default values"
|
|
template: templates/secret_cloudnativePG.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
asserts:
|
|
- containsDocument:
|
|
kind: Secret
|
|
apiVersion: v1
|
|
name: gitea-unittests-postgresql-app
|
|
namespace: testing
|
|
- equal:
|
|
path: type
|
|
value: kubernetes.io/basic-auth
|
|
- equal:
|
|
path: data.password
|
|
decodeBase64: true
|
|
value: "gitea"
|
|
- equal:
|
|
path: data.username
|
|
decodeBase64: true
|
|
value: "gitea"
|
|
- notExists:
|
|
path: data.database
|
|
- notExists:
|
|
path: stringData
|
|
|
|
- it: "Render no credential Secret when an existing Secret is used"
|
|
template: templates/secret_cloudnativePG.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
credentials:
|
|
existingSecret:
|
|
enabled: true
|
|
secretName: my-credentials
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 0
|
|
|
|
- it: "Reference the existing Secret in the Cluster"
|
|
template: templates/cluster.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
credentials:
|
|
existingSecret:
|
|
enabled: true
|
|
secretName: my-credentials
|
|
database: my-database
|
|
username: my-username
|
|
asserts:
|
|
- equal:
|
|
path: spec.bootstrap.initdb
|
|
value:
|
|
database: "my-database"
|
|
owner: "my-username"
|
|
secret:
|
|
name: my-credentials
|
|
|
|
- it: "Apply the storage and walStorage customizations"
|
|
template: templates/cluster.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
storage:
|
|
size: 1337Mi
|
|
storageClass: my-storage-class
|
|
walStorage:
|
|
enabled: true
|
|
size: 42Mi
|
|
storageClass: my-wal-storage-class
|
|
asserts:
|
|
- equal:
|
|
path: spec.storage
|
|
value:
|
|
size: "1337Mi"
|
|
storageClass: "my-storage-class"
|
|
- equal:
|
|
path: spec.walStorage
|
|
value:
|
|
size: "42Mi"
|
|
storageClass: "my-wal-storage-class"
|
|
|
|
- it: "Apply the scheduling customizations"
|
|
template: templates/cluster.yaml
|
|
set:
|
|
cloudnativePG:
|
|
enabled: true
|
|
affinity:
|
|
nodeSelector:
|
|
disktype: ssd
|
|
podAntiAffinityType: required
|
|
tolerations:
|
|
- key: my-key
|
|
operator: Equal
|
|
value: my-value
|
|
effect: NoSchedule
|
|
priorityClassName: my-priority-class
|
|
topologySpreadConstraints:
|
|
- maxSkew: 1
|
|
topologyKey: topology.kubernetes.io/zone
|
|
whenUnsatisfiable: DoNotSchedule
|
|
labelSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/name: gitea
|
|
asserts:
|
|
- equal:
|
|
path: spec.affinity
|
|
value:
|
|
nodeSelector:
|
|
disktype: ssd
|
|
podAntiAffinityType: required
|
|
tolerations:
|
|
- key: my-key
|
|
operator: Equal
|
|
value: my-value
|
|
effect: NoSchedule
|
|
- equal:
|
|
path: spec.priorityClassName
|
|
value: my-priority-class
|
|
- equal:
|
|
path: spec.topologySpreadConstraints
|
|
value:
|
|
- maxSkew: 1
|
|
topologyKey: topology.kubernetes.io/zone
|
|
whenUnsatisfiable: DoNotSchedule
|
|
labelSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/name: gitea
|