---
apiVersion: batch/v1
items:
- apiVersion: batch/v1
  kind: CronJob
  metadata:
    annotations:
      exclude.release.openshift.io/internal-openshift-hosted: "true"
      include.release.openshift.io/self-managed-high-availability: "true"
      include.release.openshift.io/single-node-developer: "true"
      release.openshift.io/create-only: "true"
      release.openshift.io/feature-set: Default
    creationTimestamp: "2025-10-27T11:18:44Z"
    generation: 2
    managedFields:
    - apiVersion: batch/v1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:exclude.release.openshift.io/internal-openshift-hosted: {}
            f:include.release.openshift.io/self-managed-high-availability: {}
            f:include.release.openshift.io/single-node-developer: {}
            f:release.openshift.io/create-only: {}
            f:release.openshift.io/feature-set: {}
          f:ownerReferences:
            .: {}
            k:{"uid":"d36bdf59-d268-4238-afb0-5e0b21cca1a4"}: {}
        f:spec:
          f:concurrencyPolicy: {}
          f:failedJobsHistoryLimit: {}
          f:jobTemplate:
            f:spec:
              f:template:
                f:metadata:
                  f:annotations:
                    .: {}
                    f:openshift.io/required-scc: {}
                    f:target.workload.openshift.io/management: {}
                  f:labels:
                    .: {}
                    f:app: {}
                f:spec:
                  f:containers:
                    k:{"name":"crd-cleanup"}:
                      .: {}
                      f:command: {}
                      f:image: {}
                      f:imagePullPolicy: {}
                      f:name: {}
                      f:resources:
                        .: {}
                        f:requests:
                          .: {}
                          f:cpu: {}
                          f:memory: {}
                      f:securityContext:
                        .: {}
                        f:allowPrivilegeEscalation: {}
                        f:capabilities:
                          .: {}
                          f:drop: {}
                      f:terminationMessagePath: {}
                      f:terminationMessagePolicy: {}
                  f:dnsPolicy: {}
                  f:nodeSelector: {}
                  f:priorityClassName: {}
                  f:restartPolicy: {}
                  f:schedulerName: {}
                  f:securityContext:
                    .: {}
                    f:runAsNonRoot: {}
                    f:runAsUser: {}
                    f:seccompProfile:
                      .: {}
                      f:type: {}
                  f:serviceAccount: {}
                  f:serviceAccountName: {}
                  f:terminationGracePeriodSeconds: {}
                  f:tolerations: {}
          f:schedule: {}
          f:successfulJobsHistoryLimit: {}
      manager: cluster-version-operator
      operation: Update
      time: "2025-10-27T11:18:44Z"
    - apiVersion: batch/v1
      fieldsType: FieldsV1
      fieldsV1:
        f:spec:
          f:suspend: {}
      manager: machine-config-operator
      operation: Update
      time: "2025-10-27T11:31:19Z"
    - apiVersion: batch/v1
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          f:lastScheduleTime: {}
          f:lastSuccessfulTime: {}
      manager: kube-controller-manager
      operation: Update
      subresource: status
      time: "2025-10-27T11:31:22Z"
    name: machine-config-nodes-crd-cleanup
    namespace: openshift-machine-config-operator
    ownerReferences:
    - apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      name: version
      uid: d36bdf59-d268-4238-afb0-5e0b21cca1a4
    resourceVersion: "7829"
    uid: 69343df3-04d7-4729-948b-341ef9c1d3e6
  spec:
    concurrencyPolicy: Forbid
    failedJobsHistoryLimit: 1
    jobTemplate:
      metadata:
        creationTimestamp: null
      spec:
        template:
          metadata:
            annotations:
              openshift.io/required-scc: nonroot-v2
              target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
            creationTimestamp: null
            labels:
              app: machine-config-nodes-crd-cleanup
          spec:
            containers:
            - command:
              - /bin/bash
              - -c
              - |
                set -euo pipefail

                # Set trap to suspend cronjob on successful exit (exit code 0)
                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

                CRD_NAME="machineconfignodes.machineconfiguration.openshift.io"

                echo "Checking for MachineConfigNodes CRD with v1alpha1 version..."

                # Check if CRD exists
                if ! CRD_CHECK_OUTPUT=$(oc get crd "$CRD_NAME" 2>&1); then
                  echo "Error checking for CRD $CRD_NAME: $CRD_CHECK_OUTPUT"
                  echo "Assuming CRD does not exist, nothing to clean up"
                  exit 0
                fi

                # Check if CRD has v1alpha1 version
                if ! HAS_V1ALPHA1=$(oc get crd "$CRD_NAME" -o jsonpath='{.spec.versions[?(@.name=="v1alpha1")].name}' 2>&1); then
                  echo "Error checking CRD versions for $CRD_NAME: $HAS_V1ALPHA1"
                  echo "v1 version likely exists, skipping cleanup"
                  exit 0
                fi

                if [ -z "$HAS_V1ALPHA1" ]; then
                  echo "CRD $CRD_NAME does not have v1alpha1 version, nothing to clean up"
                  exit 0
                fi

                echo "Found CRD $CRD_NAME with v1alpha1 version, deleting it..."

                # Delete the CRD
                if DELETE_OUTPUT=$(oc delete crd "$CRD_NAME" 2>&1); then
                  echo "Successfully deleted CRD $CRD_NAME"
                else
                  echo "Failed to delete CRD $CRD_NAME"
                  echo "Delete error output: $DELETE_OUTPUT"
                  exit 1
                fi

                echo "CRD cleanup completed successfully"
              image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:29e3563d5fc11a54ffbf7b28694f1cc3975a72e24035fca4afa44d7937e932c7
              imagePullPolicy: IfNotPresent
              name: crd-cleanup
              resources:
                requests:
                  cpu: 10m
                  memory: 50Mi
              securityContext:
                allowPrivilegeEscalation: false
                capabilities:
                  drop:
                  - ALL
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: FallbackToLogsOnError
            dnsPolicy: ClusterFirst
            nodeSelector:
              node-role.kubernetes.io/master: ""
            priorityClassName: system-cluster-critical
            restartPolicy: OnFailure
            schedulerName: default-scheduler
            securityContext:
              runAsNonRoot: true
              runAsUser: 65534
              seccompProfile:
                type: RuntimeDefault
            serviceAccount: machine-config-operator
            serviceAccountName: machine-config-operator
            terminationGracePeriodSeconds: 30
            tolerations:
            - effect: NoSchedule
              key: node-role.kubernetes.io/master
              operator: Exists
            - effect: NoExecute
              key: node.kubernetes.io/unreachable
              operator: Exists
              tolerationSeconds: 120
            - effect: NoExecute
              key: node.kubernetes.io/not-ready
              operator: Exists
              tolerationSeconds: 120
    schedule: '* * * * *'
    successfulJobsHistoryLimit: 3
    suspend: true
  status:
    lastScheduleTime: "2025-10-27T11:19:00Z"
    lastSuccessfulTime: "2025-10-27T11:31:22Z"
kind: CronJobList
metadata:
  resourceVersion: "2220267"
