From f1d3592a9754faf6f25df9550dd9bca4c6492357 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Fri, 31 May 2024 12:18:44 -0400 Subject: [PATCH 1/3] chore: add checks before killing pods when updating istio annotations --- src/pepr/operator/controllers/istio/injection.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pepr/operator/controllers/istio/injection.ts b/src/pepr/operator/controllers/istio/injection.ts index b1562164e..5bc87ae59 100644 --- a/src/pepr/operator/controllers/istio/injection.ts +++ b/src/pepr/operator/controllers/istio/injection.ts @@ -17,6 +17,7 @@ export async function enableInjection(pkg: UDSPackage) { const sourceNS = await K8s(kind.Namespace).Get(pkg.metadata.namespace); const labels = sourceNS.metadata?.labels || {}; + const originalInjectionLabel = labels[injectionLabel]; const annotations = sourceNS.metadata?.annotations || {}; const pkgKey = `uds.dev/pkg-${pkg.metadata.name}`; @@ -45,7 +46,10 @@ export async function enableInjection(pkg: UDSPackage) { { force: true }, ); - await killPods(pkg.metadata.namespace, true); + // Kill the pods if we changed the value of the istio-injection label + if (originalInjectionLabel !== labels[injectionLabel]) { + await killPods(pkg.metadata.namespace, true); + } } } @@ -61,6 +65,7 @@ export async function cleanupNamespace(pkg: UDSPackage) { const sourceNS = await K8s(kind.Namespace).Get(pkg.metadata.namespace); const labels = sourceNS.metadata?.labels || {}; + const originalInjectionLabel = labels[injectionLabel]; const annotations = sourceNS.metadata?.annotations || {}; // Remove the package annotation @@ -88,7 +93,10 @@ export async function cleanupNamespace(pkg: UDSPackage) { { force: true }, ); - await killPods(pkg.metadata.namespace, false); + // Kill the pods if we changed the value of the istio-injection label + if (originalInjectionLabel !== labels[injectionLabel]) { + await killPods(pkg.metadata.namespace, false); + } } /** From b299bc49de1b42a3fac2412c0af1171dc3b6dca6 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Tue, 4 Jun 2024 11:37:33 -0400 Subject: [PATCH 2/3] chore: align references to istio injection label When enabling injection, read the value of the injection label once and use that const value instead of re-reading from the labels object. --- src/pepr/operator/controllers/istio/injection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pepr/operator/controllers/istio/injection.ts b/src/pepr/operator/controllers/istio/injection.ts index 5bc87ae59..5859743a4 100644 --- a/src/pepr/operator/controllers/istio/injection.ts +++ b/src/pepr/operator/controllers/istio/injection.ts @@ -23,11 +23,11 @@ export async function enableInjection(pkg: UDSPackage) { // Mark the original namespace injection setting for if all packages are removed if (!annotations[injectionAnnotation]) { - annotations[injectionAnnotation] = labels[injectionLabel] || "non-existent"; + annotations[injectionAnnotation] = originalInjectionLabel || "non-existent"; } // Ensure the namespace is configured - if (!annotations[pkgKey] || labels[injectionLabel] !== "enabled") { + if (!annotations[pkgKey] || originalInjectionLabel !== "enabled") { // Ensure Istio injection is enabled labels[injectionLabel] = "enabled"; From a26a1d589999e7c39b65ddb704ce327069e8fec8 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Wed, 5 Jun 2024 11:15:18 -0400 Subject: [PATCH 3/3] fix: kill pods by finding their statefulset, not daemonset --- src/pepr/operator/controllers/istio/injection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pepr/operator/controllers/istio/injection.ts b/src/pepr/operator/controllers/istio/injection.ts index 5859743a4..36102cff3 100644 --- a/src/pepr/operator/controllers/istio/injection.ts +++ b/src/pepr/operator/controllers/istio/injection.ts @@ -137,8 +137,8 @@ async function killPods(ns: string, enableInjection: boolean) { // Delete each group of pods for (const group of Object.values(groups)) { - // If this is a daemonset, delete the pods in reverse name order - if (group[0].metadata?.ownerReferences?.find(ref => ref.kind === "DaemonSet")) { + // If this is a statefulset, delete the pods in reverse name order + if (group[0].metadata?.ownerReferences?.find(ref => ref.kind === "StatefulSet")) { group.sort((a, b) => (b.metadata?.name || "").localeCompare(a.metadata?.name || "")); }