kots
kots copied to clipboard
Job resource with generateName
I think this might apply to any resource with generateName but specifically running into this issue with Jobs resource.
The following is the Job YAML spec I'm using to start with
job2.yaml
apiVersion: batch/v1
kind: Job
metadata:
generateName: pi-job2-
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
When deploying this via KOTS, it failed with the Kustomize error
2020-06-30T10:25:57.779Z ERROR downstream/diff.go:51 kustomize stderr: ["2020/06/30 10:25:57 got file 'job.y
aml', but '/tmp/kotsadm353231800/base/job.yaml' must be a directory to be a root\nError: accumulating resources: recurs
ed accumulation of path '/tmp/kotsadm353231800/overlays/midstream': accumulating resources: recursed accumulation of pa
th '/tmp/kotsadm353231800/base': accumulating resources: accumulating resources from 'job.yaml': missing metadata.name
in object {map[apiVersion:batch/v1 kind:Job metadata:map[generateName:pi-gen-name] spec:map[backoffLimit:4 template:map
[spec:map[containers:[map[command:[perl -Mbignum=bpi -wle print bpi(2000)] image:perl name:pi]] restartPolicy:Never]]]]
}\n"]
and when deploying without KOTS but with kubectl apply it fails too for a similar reason
$ kubectl apply -f job2.yaml
error: error when retrieving current configuration of:
Resource: "batch/v1, Resource=jobs", GroupVersionKind: "batch/v1, Kind=Job"
Name: "", Namespace: "default"
Object: &{map["apiVersion":"batch/v1" "kind":"Job" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "generateName":"pi-job2-" "namespace":"default"] "spec":map["backoffLimit":'\x04' "template":map["spec":map["containers":[map["command":["perl" "-Mbignum=bpi" "-wle" "print bpi(2000)"] "image":"perl" "name":"pi"]] "restartPolicy":"Never"]]]]}
from server for: "job2.yaml": resource name may not be empty
But when using kubectl create it works
$ kubectl create -f job2.yaml
job.batch/pi-job2-rlgv8 created
Below is another yaml where I added both name and generateName but name supersedes generateName, see example below.
job.yaml
apiVersion: batch/v1
kind: Job
metadata:
generateName: pi-gen-name
name: pi-name
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
pi-name 1/1 29s 10m
Any thoughts on how to handle generateName in kots?