|
| 1 | +suite: cozystack-controller runs one active manager |
| 2 | +templates: |
| 3 | + - templates/deployment.yaml |
| 4 | + - templates/rbac.yaml |
| 5 | + - templates/leader-election-role.yaml |
| 6 | + |
| 7 | +release: |
| 8 | + name: cozystack-controller |
| 9 | + namespace: cozy-system |
| 10 | + |
| 11 | +# Eight reconcilers in this manager write (HelmRelease patches, Gateway and |
| 12 | +# Certificate renders, ResourceQuota, Secret replication, CA projection), so a |
| 13 | +# second replica is only safe behind leader election. --leader-elect is passed |
| 14 | +# unconditionally and the Lease grant ships with it; raising replicas then adds a |
| 15 | +# standby rather than a second writer. |
| 16 | +# |
| 17 | +# The Lease grant is namespaced on purpose: the lock lives in the manager's own |
| 18 | +# namespace, so the ClusterRole does not hand out Lease writes in every |
| 19 | +# namespace. |
| 20 | + |
| 21 | +tests: |
| 22 | + - it: the manager always asks for leader election |
| 23 | + template: templates/deployment.yaml |
| 24 | + asserts: |
| 25 | + - contains: |
| 26 | + path: spec.template.spec.containers[0].args |
| 27 | + content: --leader-elect |
| 28 | + |
| 29 | + - it: replicas defaults to the previously hardcoded 1 |
| 30 | + template: templates/deployment.yaml |
| 31 | + asserts: |
| 32 | + - equal: |
| 33 | + path: spec.replicas |
| 34 | + value: 1 |
| 35 | + |
| 36 | + - it: replicas value drives spec.replicas |
| 37 | + set: |
| 38 | + cozystackController.replicas: 2 |
| 39 | + template: templates/deployment.yaml |
| 40 | + asserts: |
| 41 | + - equal: |
| 42 | + path: spec.replicas |
| 43 | + value: 2 |
| 44 | + |
| 45 | + - it: the Lease verbs come from a namespaced Role in cozy-system |
| 46 | + template: templates/leader-election-role.yaml |
| 47 | + documentSelector: |
| 48 | + path: kind |
| 49 | + value: Role |
| 50 | + asserts: |
| 51 | + - equal: |
| 52 | + path: metadata.name |
| 53 | + value: cozystack-controller-leader-election |
| 54 | + - equal: |
| 55 | + path: metadata.namespace |
| 56 | + value: cozy-system |
| 57 | + - contains: |
| 58 | + path: rules |
| 59 | + content: |
| 60 | + apiGroups: ["coordination.k8s.io"] |
| 61 | + resources: ["leases"] |
| 62 | + verbs: ["get", "list", "watch", "create", "update", "patch"] |
| 63 | + |
| 64 | + - it: the Lease Role reaches the controller ServiceAccount in cozy-system |
| 65 | + template: templates/leader-election-role.yaml |
| 66 | + documentSelector: |
| 67 | + path: kind |
| 68 | + value: RoleBinding |
| 69 | + asserts: |
| 70 | + - equal: |
| 71 | + path: roleRef.name |
| 72 | + value: cozystack-controller-leader-election |
| 73 | + - contains: |
| 74 | + path: subjects |
| 75 | + content: |
| 76 | + kind: ServiceAccount |
| 77 | + name: cozystack-controller |
| 78 | + namespace: cozy-system |
| 79 | + |
| 80 | + - it: the ClusterRole grants no Lease write, so no other namespace is reachable |
| 81 | + template: templates/rbac.yaml |
| 82 | + documentSelector: |
| 83 | + path: kind |
| 84 | + value: ClusterRole |
| 85 | + asserts: |
| 86 | + # Match on the resource alone (any: true), not on the exact rule spelling, so |
| 87 | + # the assertion fails for any ClusterRole rule that hands out leases — e.g. |
| 88 | + # one with verbs: ["*"] — instead of only for the rule shape used above. |
| 89 | + - notContains: |
| 90 | + path: rules |
| 91 | + content: |
| 92 | + resources: ["leases"] |
| 93 | + any: true |
0 commit comments