How to exit the helm hook if a PVC Claim is not found?

7/5/2019

I have a post-upgrade helm hook job that mounts 2 PV Claims and copies data from one PVC to another. However under some conditions, a particular PVC might not be present. When i run this hook, the job is spawned but is sitting in "Pending" State even though the PVC was found missing. Are there any ways to mark this job as failed and move on?

apiVersion: batch/v1
kind: Job
metadata:
  name: pvc-rsync
spec:
  template:         
    metadata:
        name: rsync
    spec:
      containers:
      - name:pvc-rsync
        image: mrsync:latest
        imagePullPolicy: Always
        volumeMounts:
        - name: source
          mountPath: /srcd
        - name: destination
          mountPath: /dest
      restartPolicy: OnFailure 
      volumes:
      - name: source
        persistentVolumeClaim:
          claimName: foo
      - name: destination
        persistentVolumeClaim:
          claimName: blah

The describe command shows that

Events:
  Type     Reason            Age               From               Message
  ----     ------            ----              ----               -------
  Warning  FailedScheduling  3m (x25 over 4m)  default-scheduler  persistentvolumeclaim "foo" not found

I would like to do one of the 2 things: 1. Detect dynamically that a PVC is not present 2. Exit the job so that it kind of gives the same meaning..

-- Murali
kubernetes-helm
kubernetes-jobs

1 Answer

8/24/2019

No direct solution is available for this. I had to bring up another container with the right cluster Role permissions, initialize kubectl within that container and use it to detect the above.

-- Murali
Source: StackOverflow