Skip to content

Commit 409d01e

Browse files
Merge pull request #5238 from djoshy/unrevert-mcn-crd
OCPBUGS-59723: Reintroduce cronjob that deletes MCN v1alpha1 CRD
2 parents 1b20021 + 38093ce commit 409d01e

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: machine-config-nodes-crd-cleanup
5+
namespace: openshift-machine-config-operator
6+
annotations:
7+
include.release.openshift.io/self-managed-high-availability: "true"
8+
include.release.openshift.io/single-node-developer: "true"
9+
# exclude from hypershift
10+
exclude.release.openshift.io/internal-openshift-hosted: "true"
11+
release.openshift.io/feature-set: Default
12+
# This prevent an update of this cronjob once the child job suspends on a successful run
13+
release.openshift.io/create-only: "true"
14+
spec:
15+
# Run every minute initially to trigger an immediate run
16+
schedule: "* * * * *"
17+
# Don't suspend initially - let it run once
18+
suspend: false
19+
# Only allow 1 concurrent job and prevent overlapping
20+
concurrencyPolicy: Forbid
21+
jobTemplate:
22+
spec:
23+
backOffLimit: 3
24+
template:
25+
metadata:
26+
labels:
27+
app: machine-config-nodes-crd-cleanup
28+
annotations:
29+
target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
30+
openshift.io/required-scc: nonroot-v2
31+
spec:
32+
serviceAccountName: machine-config-operator
33+
restartPolicy: OnFailure
34+
containers:
35+
- name: crd-cleanup
36+
image: placeholder.url.oc.will.replace.this.org/placeholdernamespace:rhel-coreos
37+
terminationMessagePolicy: FallbackToLogsOnError
38+
command:
39+
- /bin/bash
40+
- -c
41+
- |
42+
set -euo pipefail
43+
44+
# Set trap to suspend cronjob on successful exit (exit code 0)
45+
trap 'if [ $? -eq 0 ]; then echo "Suspending cronjob..."; oc patch cronjob machine-config-nodes-crd-cleanup -p "{\"spec\":{\"suspend\":true}}" --field-manager=machine-config-operator || echo "Failed to suspend cronjob"; fi' EXIT
46+
47+
CRD_NAME="machineconfignodes.machineconfiguration.openshift.io"
48+
49+
echo "Checking for MachineConfigNodes CRD with v1alpha1 version..."
50+
51+
# Check if CRD exists
52+
if ! oc get crd "$CRD_NAME" >/dev/null 2>&1; then
53+
echo "CRD $CRD_NAME does not exist, nothing to clean up"
54+
exit 0
55+
fi
56+
57+
# Check if CRD has v1alpha1 version
58+
HAS_V1ALPHA1=$(oc get crd "$CRD_NAME" -o jsonpath='{.spec.versions[?(@.name=="v1alpha1")].name}' 2>/dev/null || echo "")
59+
60+
if [ -z "$HAS_V1ALPHA1" ]; then
61+
echo "CRD $CRD_NAME does not have v1alpha1 version, nothing to clean up"
62+
exit 0
63+
fi
64+
65+
echo "Found CRD $CRD_NAME with v1alpha1 version, deleting it..."
66+
67+
# Delete the CRD
68+
if oc delete crd "$CRD_NAME"; then
69+
echo "Successfully deleted CRD $CRD_NAME"
70+
else
71+
echo "Failed to delete CRD $CRD_NAME"
72+
exit 1
73+
fi
74+
75+
echo "CRD cleanup completed successfully"
76+
resources:
77+
requests:
78+
cpu: 10m
79+
memory: 50Mi
80+
securityContext:
81+
allowPrivilegeEscalation: false
82+
capabilities:
83+
drop:
84+
- ALL
85+
securityContext:
86+
runAsNonRoot: true
87+
runAsUser: 65534
88+
seccompProfile:
89+
type: RuntimeDefault
90+
nodeSelector:
91+
node-role.kubernetes.io/control-plane: ""
92+
priorityClassName: "system-cluster-critical"
93+
tolerations:
94+
- effect: NoSchedule
95+
key: node-role.kubernetes.io/master
96+
operator: Exists
97+
- effect: NoExecute
98+
key: node.kubernetes.io/unreachable
99+
operator: Exists
100+
tolerationSeconds: 120
101+
- effect: NoExecute
102+
key: node.kubernetes.io/not-ready
103+
operator: Exists
104+
tolerationSeconds: 120

0 commit comments

Comments
 (0)