kubestellar: bug: job filtering is not working as expected

Describe the bug

The batch.kubernetes.io/controller-uid and controller-uid labels are still present in a job wrapped in the ManifestWork. This causes the error shown in the ManifestWork:

 message: 'Failed to apply manifest: Job.batch "pi" is invalid: [spec.template.metadata.labels[controller-uid]:
          Required value: must be ''3840adbb-55d5-46f3-992c-51b0eccc0abc'', spec.template.metadata.labels[batch.kubernetes.io/controller-uid]:
          Required value: must be ''3840adbb-55d5-46f3-992c-51b0eccc0abc'', spec.selector:
          Invalid value: v1.LabelSelector{MatchLabels:map[string]string{}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}:
          field is immutable]'

Steps To Reproduce

  1. Run release 0.21.0
  2. Apply a test job and related binding policy:
kubectl apply -f - <<EOF
apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  suspend: true
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4
---
apiVersion: control.kubestellar.io/v1alpha1
kind: BindingPolicy
metadata:
  name: jobs
spec:
  wantSingletonReportedState: true
  clusterSelectors:
  - matchLabels:
      name: cluster1
  downsync:
  - objectSelectors:
    - matchLabels: 
        batch.kubernetes.io/job-name: pi
EOF  
  1. Check ManifestWork:
$ k get manifestwork -n cluster1 jobs-wds0 -o yaml
apiVersion: work.open-cluster-management.io/v1
kind: ManifestWork
metadata:
  annotations:
    transport.kubestellar.io/originOwnerReferenceBindingGeneration: "2"
  creationTimestamp: "2024-03-21T01:11:10Z"
  finalizers:
  - cluster.open-cluster-management.io/manifest-work-cleanup
  generation: 2
  labels:
    transport.kubestellar.io/originOwnerReferenceBindingKey: jobs
    transport.kubestellar.io/originWdsName: wds0
  name: jobs-wds0
  namespace: cluster1
  resourceVersion: "80085"
  uid: 276a9f9a-b8fe-41a8-a3f2-8ce6c8281d51
spec:
  workload:
    manifests:
    - apiVersion: batch/v1
      kind: Job
      metadata:
        creationTimestamp: "2024-03-21T01:11:08Z"
        labels:
          batch.kubernetes.io/controller-uid: 3ba716d0-192a-4108-8f9e-d804e892b761
          batch.kubernetes.io/job-name: pi
          controller-uid: 3ba716d0-192a-4108-8f9e-d804e892b761
          job-name: pi
          managed-by.kubestellar.io/singletonstatus: jobs
        name: pi
        namespace: default
      spec:
        backoffLimit: 4
        completionMode: NonIndexed
        completions: 1
        parallelism: 1
        selector:
          matchLabels: {}
        suspend: true
        template:
          metadata:
            creationTimestamp: null
            labels:
              batch.kubernetes.io/job-name: pi
              job-name: pi
          spec:
            containers:
            - command:
              - perl
              - -Mbignum=bpi
              - -wle
              - print bpi(2000)
              image: perl:5.34.0
              imagePullPolicy: IfNotPresent
              name: pi
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
            dnsPolicy: ClusterFirst
            restartPolicy: Never
            schedulerName: default-scheduler
            securityContext: {}
            terminationGracePeriodSeconds: 30
      status:
        conditions:
        - lastProbeTime: "2024-03-21T01:11:10Z"
          lastTransitionTime: "2024-03-21T01:11:10Z"
          message: Job suspended
          reason: JobSuspended
          status: "True"
          type: Suspended
        ready: 0
        uncountedTerminatedPods: {}
status:
  conditions:
  - lastTransitionTime: "2024-03-21T01:11:10Z"
    message: Failed to apply manifest work
    observedGeneration: 2
    reason: AppliedManifestWorkFailed
    status: "False"
    type: Applied
  - lastTransitionTime: "2024-03-21T01:11:10Z"
    message: All resources are available
    observedGeneration: 2
    reason: ResourcesAvailable
    status: "True"
    type: Available
  resourceStatus:
    manifests:
    - conditions:
      - lastTransitionTime: "2024-03-21T01:11:10Z"
        message: 'Failed to apply manifest: Job.batch "pi" is invalid: [spec.template.metadata.labels[controller-uid]:
          Required value: must be ''3840adbb-55d5-46f3-992c-51b0eccc0abc'', spec.template.metadata.labels[batch.kubernetes.io/controller-uid]:
          Required value: must be ''3840adbb-55d5-46f3-992c-51b0eccc0abc'', spec.selector:
          Invalid value: v1.LabelSelector{MatchLabels:map[string]string{}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}:
          field is immutable]'
        reason: AppliedManifestFailed
        status: "False"
        type: Applied
      - lastTransitionTime: "2024-03-21T01:11:10Z"
        message: Resource is available
        reason: ResourceAvailable
        status: "True"
        type: Available
      - lastTransitionTime: "2024-03-21T01:11:10Z"
        message: ""
        reason: NoStatusFeedbackSynced
        status: "True"
        type: StatusFeedbackSynced
      resourceMeta:
        group: batch
        kind: Job
        name: pi
        namespace: default
        ordinal: 0
        resource: jobs
        version: v1
      statusFeedback: {}

Expected Behavior

batch.kubernetes.io/controller-uid and controller-uid should not be present in the wrapped job object.

Additional Context

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 37 (37 by maintainers)

Most upvoted comments

we may want to filter status out regardless if subresource or not. It is a waste of storage in etcd if we have many of those - see https://github.com/kubestellar/kubestellar/pull/1937