feat(platform-auth): add functions to manage platform auth pod restar… - #3491
feat(platform-auth): add functions to manage platform auth pod restar…#3491CasLubbers wants to merge 5 commits into
Conversation
…ts based on oauth2-proxy health
There was a problem hiding this comment.
Pull request overview
Adds a one-shot “platform auth pod restart” mechanism to the operator’s successful apply path, gated on oauth2-proxy’s ArgoCD health and persisted via a marker ConfigMap, to mitigate Istio JWKS caching issues described in the new ADR.
Changes:
- Add marker ConfigMap helpers to detect/record that the platform-auth restart has already been performed.
- Extend
AplOperator.runApplyIfNotBusy()to (non-blockingly) restartotomi.io/auth=platformworkloads once oauth2-proxy is Healthy, then write the marker. - Introduce a runtime-upgrade helper that finds platform-auth pods cluster-wide and restarts each distinct workload once, with unit tests and ADR documentation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/operator/k8s.ts | Adds marker ConfigMap read/create helpers for the one-shot restart state. |
| src/operator/k8s.test.ts | Adds unit tests for the new marker helpers. |
| src/operator/apl-operator.ts | Hooks the restart check+action into the successful apply path, gated on ArgoCD health and marker state. |
| src/operator/apl-operator.test.ts | Adds tests verifying restart behavior and that apply success is not blocked by restart-check failures. |
| src/common/runtime-upgrades/restart-platform-auth-pods.ts | Implements pod discovery by label selector and workload-deduped restart using existing restart primitives. |
| src/common/runtime-upgrades/restart-platform-auth-pods.test.ts | Adds unit tests for label selection and restart deduplication. |
| adr/index.md | Registers the new ADR entry. |
| adr/2026-08-04-restart-platform-auth-pods-after-oauth2-proxy-healthy.md | Documents rationale/approach for the one-shot restart behavior. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/operator/k8s.test.ts:233
markPlatformAuthPodsRestartedhas a code path that intentionally ignores ConfigMap creation conflicts (ApiException 409), but the unit tests only cover the successful create. Adding a test for the 409 case will lock in the intended idempotent behavior (important when multiple operator instances race).
test('creates the marker configmap', async () => {
mockCoreV1Api.createNamespacedConfigMap.mockResolvedValue({})
await markPlatformAuthPodsRestarted('test-namespace', 'apl-platform-auth-restart-state')
expect(mockCoreV1Api.createNamespacedConfigMap).toHaveBeenCalledWith({
namespace: 'test-namespace',
body: { metadata: { name: 'apl-platform-auth-restart-state' } },
})
})
})
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/operator/apl-operator.ts:140
- The restart marker check and write are separated (read in needsPlatformAuthPodsRestart(), then create in restartPlatformAuthPods()), which is non-atomic. If two operator instances ever run concurrently, both can observe the marker missing and both can restart pods before one of them creates the ConfigMap, violating the “exactly once” requirement from the ADR.
Consider using the ConfigMap create as the gate/lock (e.g., attempt create first and skip on 409), or introducing an explicit lock/status field (in-progress/done) so concurrent instances don’t both restart while still allowing retries when a restart attempt fails.
private async needsPlatformAuthPodsRestart(): Promise<boolean> {
if (await hasPlatformAuthPodsRestarted()) return false
await checkArgoCDAppStatus(OAUTH2_PROXY_ARGOCD_APP_NAME, k8s.custom(), 'health', 'Healthy')
return true
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/common/runtime-upgrades/restart-platform-auth-pods.ts:27
restartPlatformAuthPodsaborts the whole restart sequence ifrestartPodOwnerthrows for any single pod (e.g.restartPodOwnercan propagate errors fromdeletePodfor Tekton-managed pods). This can leave the cluster in a partially-restarted state and also prevents the restart marker from being written, causing repeated restarts on subsequent applies.
for (const pod of pods) {
const workloadKey = deps.getWorkloadKeyFromPod(pod)
if (workloadKey && restartedWorkloads.has(workloadKey)) continue
await deps.restartPodOwner(pod, d, parsedArgs)
src/operator/apl-operator.ts:117
- PR description says the marker check happens “on every reconcile run”, but the implementation runs after every successful apply for both
PollandReconciletriggers. Please align either the description or the code so operators know when to expect the one-shot restart to run (and to avoid surprising restarts during the poll loop).
try {
// See adr/2026-08-04-restart-platform-auth-pods-after-oauth2-proxy-healthy.md
if (await this.needsPlatformAuthPodsRestart()) {
await this.restartPlatformAuthPods()
}
| import { getWorkloadKeyFromPod, restartPodOwner } from './restart-istio-sidecars' | ||
|
|
||
| export const PLATFORM_AUTH_LABEL_SELECTOR = 'otomi.io/auth=platform' | ||
| export const OAUTH2_PROXY_ARGOCD_APP_NAME = 'istio-system-oauth2-proxy' |
There was a problem hiding this comment.
Declared here, but it seems to be exclusively used in apl-operator.ts. Would consider moving it and skip the import.
| export const OTOMI_NAMESPACE = 'otomi' | ||
| export const SEALED_SECRETS_NAMESPACE = 'apl-secrets' | ||
| export const OTOMI_SECRETS = 'otomi-secrets' | ||
| export const APL_PLATFORM_AUTH_RESTART_STATE_CM = 'apl-platform-auth-restart-state' |
There was a problem hiding this comment.
Would prefer skipping the APL_ prefix. The id is quite long as it is.
|
Just minor comments on naming / placing things. |

📌 Summary
Will restart all platformAuth pods when the
apl-platform-auth-restart-stateCM does not exist. This is checked on every reconcile run.🔍 Reviewer Notes
Observe following logs being written when you install APL:
Observe following CM is written when restart has happend:
apl-platform-auth-restart-state🧹 Checklist