Skip to content

Commit

Permalink
chore: add debug logs for istio injection logic (#602)
Browse files Browse the repository at this point in the history
## Description
Adds debug logs to better understand circumstances where istio injection
is not occurring

## Related Issue
#604

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor
Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)
followed

---------

Co-authored-by: Micah Nagel <micah.nagel@defenseunicorns.com>
  • Loading branch information
rjferguson21 and mjnagel authored Aug 5, 2024
1 parent 7fe927e commit 9075436
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pepr/operator/controllers/istio/injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function enableInjection(pkg: UDSPackage) {
annotations[pkgKey] = "true";

// Apply the updated Namespace
log.debug(`Updating namespace ${pkg.metadata.namespace} with istio injection label`);
await K8s(kind.Namespace).Apply(
{
metadata: {
Expand All @@ -52,6 +53,9 @@ export async function enableInjection(pkg: UDSPackage) {

// Kill the pods if we changed the value of the istio-injection label
if (originalInjectionLabel !== labels[injectionLabel]) {
log.debug(
`Attempting pod restart in ${pkg.metadata.namespace} based on istio injection label change`,
);
await killPods(pkg.metadata.namespace, true);
}
}
Expand Down Expand Up @@ -86,6 +90,7 @@ export async function cleanupNamespace(pkg: UDSPackage) {
}

// Apply the updated Namespace
log.debug(`Updating namespace ${pkg.metadata.namespace}, removing istio injection labels.`);
await K8s(kind.Namespace).Apply(
{
metadata: {
Expand All @@ -99,6 +104,9 @@ export async function cleanupNamespace(pkg: UDSPackage) {

// Kill the pods if we changed the value of the istio-injection label
if (originalInjectionLabel !== labels[injectionLabel]) {
log.debug(
`Attempting pod restart in ${pkg.metadata.namespace} based on istio injection label change`,
);
await killPods(pkg.metadata.namespace, false);
}
}
Expand All @@ -118,24 +126,28 @@ async function killPods(ns: string, enableInjection: boolean) {
for (const pod of pods.items) {
// Ignore pods that already have a deletion timestamp
if (pod.metadata?.deletionTimestamp) {
log.debug(`Ignoring Pod ${ns}/${pod.metadata?.name}, already being deleted`);
continue;
}

const foundSidecar = pod.spec?.containers?.find(c => c.name === "istio-proxy");

// If enabling injection, ignore pods that already have the istio sidecar
if (enableInjection && foundSidecar) {
log.debug(`Ignoring Pod ${ns}/${pod.metadata?.name}, already has sidecar`);
continue;
}

// If disabling injection, ignore pods that don't have the istio sidecar
if (!enableInjection && !foundSidecar) {
log.debug(`Ignoring Pod ${ns}/${pod.metadata?.name}, injection disabled`);
continue;
}

// Get the UID of the owner of the pod or default to "other" (shouldn't happen)
const controlledBy = pod.metadata?.ownerReferences?.find(ref => ref.controller)?.uid || "other";
groups[controlledBy] = groups[controlledBy] || [];
log.debug(`Adding Pod ${ns}/${pod.metadata?.name} to ${controlledBy} deletion list.`);
groups[controlledBy].push(pod);
}

Expand Down

0 comments on commit 9075436

Please sign in to comment.