Skip to content

Deleting an Object which created a Job does not delete the pods created by that job #342

@alanrichman

Description

@alanrichman

What happened?

I have a Composition that creates an Object which creates a Job. When the Object is deleted the Job is deleted but the Pods which were created to execute the Job are not deleted. The expected behavior is that deleting the Object will also delete the Pods since this is what happens when a Job is deleted manually. This does not happen when using a Deployment instead of a Job, in that case Pods are deleted when the Deployment is deleted by way of deleting the Object

How can we reproduce it?

  1. Create this Object

This job will exit with a random code between 0 and 5 to simulate a job which needs to retry a few times which is the case for the real job in my Composition.

apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: test-job
spec:
  references:
  forProvider:
    manifest:
      apiVersion: batch/v1
      kind: Job
      metadata:
        name: test-job
        namespace: default
      spec:
        template:
          spec:
            containers:
              - name: busybox
                image: busybox
                command: ["/bin/sh", "-c", "exit $((RANDOM % 6))"]
                imagePullPolicy: IfNotPresent
            restartPolicy: Never
  1. Allow it to create a few pods. It does not matter whether or not any complete successfully, the behavior is the same.
  2. Delete the Object. Observe that the Job is deleted but all Pods for the job are still there
  3. Create this Object
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: test-deploy
spec:
  references:
  forProvider:
    manifest:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nginx-deployment
        namespace: default
        labels:
          app: nginx
      spec:
        replicas: 3
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:1.14.2
              ports:
              - containerPort: 80
  1. Allow it to create its pods
  2. Delete the Object. Observe that the Deployment is deleted and all Pods for the deployment are deleted

What environment did it happen in?

Crossplane version: 1.19.0
Provider version: 0.17.0
Kubernetes version: v1.30.9-gke.1046000
Kubernetes distribution: Google Kubernetes Engine (GKE)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions