Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: operator retry bug fixes #524

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
996 changes: 628 additions & 368 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/istio/common/manifests/pepr-istio-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Have to pre-create the namespace and also patch it with the istio-injection label later because
# Helm is kind of dumb: https://github.com/helm/helm/issues/350
kind: Namespace
apiVersion: v1
metadata:
name: pepr-system
labels:
Expand Down
2 changes: 1 addition & 1 deletion src/pepr/operator/controllers/keycloak/client-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function syncClient(

if (isRetry) {
Log.error(`${msg}, retry failed, aborting`);
throw new Error(`${msg}. RETRY FAILED, aborting: ${JSON.stringify(err)}`);
throw new Error(`${msg}. RETRY FAILED, aborting: ${err.message}`);
}

// Retry the request
Expand Down
3 changes: 2 additions & 1 deletion src/pepr/operator/crd/generated/package-v1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export enum ClientAuthenticatorType {
*/
export interface Groups {
/**
* List of group allowed to access to client
* List of groups allowed to access to client
*/
anyOf?: string[];
}
Expand Down Expand Up @@ -564,6 +564,7 @@ export enum Phase {
Failed = "Failed",
Pending = "Pending",
Ready = "Ready",
Retrying = "Retrying",
}

RegisterKind(Package, {
Expand Down
2 changes: 1 addition & 1 deletion src/pepr/operator/crd/sources/package/v1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export const v1alpha1: V1CustomResourceDefinitionVersion = {
type: "integer",
},
phase: {
enum: ["Pending", "Ready", "Failed"],
enum: ["Pending", "Ready", "Failed", "Retrying"],
type: "string",
},
ssoClients: {
Expand Down
1 change: 1 addition & 0 deletions src/pepr/operator/reconcilers/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ describe("handleFailure", () => {
expect(PatchStatus).toHaveBeenCalledWith({
metadata: { namespace: "default", name: "test" },
status: {
phase: Phase.Retrying,
retryAttempt: 1,
},
});
Expand Down
13 changes: 12 additions & 1 deletion src/pepr/operator/reconcilers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const uidSeen = new Set<string>();
* @returns true if the CRD is pending or the current generation has been processed
*/
export function shouldSkip(cr: UDSPackage) {
const isRetrying = cr.status?.phase === Phase.Retrying;
const isPending = cr.status?.phase === Phase.Pending;
const isCurrentGeneration = cr.metadata?.generation === cr.status?.observedGeneration;

Expand All @@ -22,6 +23,12 @@ export function shouldSkip(cr: UDSPackage) {
return false;
}

// If the CR is retrying, it should not be skipped
if (isRetrying) {
Log.debug(cr, `Should skip? No, retrying`);
return false;
}

// This is the second time the CR has been seen, so check if it is pending or the current generation
if (isPending || isCurrentGeneration) {
Log.debug(cr, `Should skip? Yes, pending or current generation and not first time seen`);
Expand Down Expand Up @@ -50,6 +57,9 @@ export async function updateStatus(cr: UDSPackage, status: PkgStatus) {
},
status,
});

// Track the UID of the CRD to know if it has been seen before
uidSeen.add(cr.metadata!.uid!);
}

/**
Expand Down Expand Up @@ -95,7 +105,7 @@ export async function handleFailure(err: { status: number; message: string }, cr
const identifier = `${metadata.namespace}/${metadata.name}`;
let status: Status;

// todo: identify exact 404 we are targetting, possibly in `updateStatus`
// todo: identify exact 404 we are targeting, possibly in `updateStatus`
if (err.status === 404) {
Log.warn({ err }, `Package metadata seems to have been deleted`);
return;
Expand All @@ -108,6 +118,7 @@ export async function handleFailure(err: { status: number; message: string }, cr
Log.error({ err }, `Reconciliation attempt ${currRetry} failed for ${identifier}, retrying...`);

status = {
phase: Phase.Retrying,
retryAttempt: currRetry,
};
} else {
Expand Down
5 changes: 1 addition & 4 deletions src/pepr/operator/reconcilers/package-reconciler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Log } from "pepr";

import { handleFailure, shouldSkip, uidSeen, updateStatus } from ".";
import { handleFailure, shouldSkip, updateStatus } from ".";
import { UDSConfig } from "../../config";
import { enableInjection } from "../controllers/istio/injection";
import { istioResources } from "../controllers/istio/istio-resources";
Expand Down Expand Up @@ -67,9 +67,6 @@ export async function packageReconciler(pkg: UDSPackage) {
observedGeneration: metadata.generation,
retryAttempt: 0, // todo: make this nullable when kfc generates the type
});

// Update to indicate this version of pepr-core has reconciled the package successfully once
uidSeen.add(pkg.metadata!.uid!);
} catch (err) {
void handleFailure(err, pkg);
}
Expand Down