diff --git a/hack/capi-operator_test.bats b/hack/capi-operator_test.bats new file mode 100644 index 000000000..cfd2fd8e2 --- /dev/null +++ b/hack/capi-operator_test.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats +# The operator's resync period is what bounds the stale-Ready window after an +# operator restart (kubernetes-sigs/cluster-api-operator#1031): about two +# periods. It reaches the manager only through patches/sync-period.diff, which +# `make update` has to reapply on every re-vendor, and through the value in +# values.yaml. Losing either silently returns the window to about 20 minutes, +# so this checks the argument the rendered Deployment actually carries. + +load test_helper + +REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" +OPERATOR="$REPO_ROOT/packages/system/capi-operator" + +@test "the operator manager runs with a one-minute resync period" { + local rendered args + rendered="$BATS_TEST_TMPDIR/operator.yaml" + helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api > "$rendered" + args="$(yq -N 'select(.kind == "Deployment") | .spec.template.spec.containers[] | select(.name == "manager") | .args[]' "$rendered")" + [ -n "$args" ] || { echo "no manager container args rendered from $OPERATOR" >&2; return 1; } + case "$(printf '%s\n' "$args" | grep -c '^--sync-period=')" in + 1) ;; + *) echo "expected exactly one --sync-period in the manager args, got:" >&2; echo "$args" >&2; return 1 ;; + esac + printf '%s\n' "$args" | grep -qx -- '--sync-period=1m' || { echo "manager args: $args" >&2; return 1; } +} diff --git a/packages/system/capi-operator/Makefile b/packages/system/capi-operator/Makefile index 9349f5499..e90c8fe88 100644 --- a/packages/system/capi-operator/Makefile +++ b/packages/system/capi-operator/Makefile @@ -9,3 +9,6 @@ include ../../../hack/package.mk update: clean capi-operator-update rm -rf charts/cluster-api-operator/charts/ + # The upstream chart has no value for --sync-period; values.yaml explains + # why we set it. + patch -p1 < patches/sync-period.diff diff --git a/packages/system/capi-operator/charts/cluster-api-operator/templates/deployment.yaml b/packages/system/capi-operator/charts/cluster-api-operator/templates/deployment.yaml index 598d85c8a..1d51dce18 100644 --- a/packages/system/capi-operator/charts/cluster-api-operator/templates/deployment.yaml +++ b/packages/system/capi-operator/charts/cluster-api-operator/templates/deployment.yaml @@ -86,6 +86,9 @@ spec: - --leader-elect-retry-period={{ .retryPeriod }} {{- end }} {{- end }} + {{- with .Values.syncPeriod }} + - --sync-period={{ . }} + {{- end }} command: - /manager {{- with .Values.image.manager }} diff --git a/packages/system/capi-operator/patches/sync-period.diff b/packages/system/capi-operator/patches/sync-period.diff new file mode 100644 index 000000000..4c10946ad --- /dev/null +++ b/packages/system/capi-operator/patches/sync-period.diff @@ -0,0 +1,12 @@ +--- a/charts/cluster-api-operator/templates/deployment.yaml ++++ b/charts/cluster-api-operator/templates/deployment.yaml +@@ -86,6 +86,9 @@ + - --leader-elect-retry-period={{ .retryPeriod }} + {{- end }} + {{- end }} ++ {{- with .Values.syncPeriod }} ++ - --sync-period={{ . }} ++ {{- end }} + command: + - /manager + {{- with .Values.image.manager }} diff --git a/packages/system/capi-operator/values.yaml b/packages/system/capi-operator/values.yaml index 7e8b95c50..40cffd7a8 100644 --- a/packages/system/capi-operator/values.yaml +++ b/packages/system/capi-operator/values.yaml @@ -1,4 +1,12 @@ cluster-api-operator: + # A restarted v0.19 operator ignores the provider Deployments it finds + # running (kubernetes-sigs/cluster-api-operator#1031), so a stale + # Ready=False on a provider clears only at the first informer resync, + # two periods after the restart: ~20 min at the 10m default, ~2 min at + # 1m (both measured). A resync is served from the cache and changes + # nothing when providers are in sync, so the short period costs no API + # writes. Applied through patches/sync-period.diff. + syncPeriod: 1m resources: manager: limits: