-
Bug
-
Resolution: Not A Defect
-
Minor
-
Jenkins 2.319.2
kubernetes-plugin 1.31.3
Running on Openshift4
Scripted pipeline with a Jenkins shared library
When creating a podTemplate and specifying a `namespace`, defined persistentVolumeClaims as volumes are not created in the given namespace.
podTemplate
podTemplate( serviceAccount: "default", containers: [ containerTemplate( name: "jnlp", image: "image-registry.openshift-image-registry.svc:5000/openshift/jenkins-agent-nodejs:latest", envVars: [ envVar(key: "HOME", value: "/home/jenkins/agent") ] ), containerTemplate( name: "maven", image: "${imageRegistry}/${imageNamespace}/jdk-maven-jenkins-slave:jdk-11", command: "sleep", args: "99999", alwaysPullImage: true, envVars: [ envVar(key: "HOME", value: "/home/jenkins/agent"), envVar(key: "TZ", value: "Europe/Rome"), ], resourceLimitCpu: "2", resourceRequestCpu: "1", resourceLimitMemory: "4Gi", resourceRequestMemory: "1Gi" ) ], volumes: [ persistentVolumeClaim(mountPath: "/home/jenkins/agent/.m2/repository", claimName: "maven-repository-cache") ], namespace: "project-namespace"
Actual result
The PVC maven-repository-cache is not created in the namespace project-namespace and thus the slave pod doesn't start up with the following error:
Created Pod: openshift project-namespace/dummy-job-11-4r89n-r81k2-9jh13 [Warning][project-namespace/dummy-job-11-4r89n-r81k2-9jh13][FailedScheduling] 0/10 nodes are available: 10 persistentvolumeclaim "maven-repository-cache" not found.
Looking at the project-namespace the PVC isn't created, but instead it is created in the namespace which jenkins runs.
EDIT: The PVC isn't created in Jenkins namespace, but was there already from previous run. This brought me to the assumption that jenkins-kubernetes created the PVC.
Expected result
The plugin should populate the PVC resource with the namespace given in the podTemplate, so that the PVC is created in the correct namespace.
This isn't a bug. I was just assuming the PVC gets created, but in fact `persistentVolumeClaim` just adds the PVC to the pod but doesn't actually create it. For creating PVCs one would have to use `dynamicPVC` which creates the PVC and adds a ownerReference to the pod, so that when the pod is deleted also the PVC is deleted.
So `dynamicPVC` is not really helpful in my case since its coupled to the pod. It would be nice to have `dynamicPVC` support an additional parameter that would just not add the `ownerReference` and would therefore just be deleted when the namespace is deleted. But thats more a feature request, so I'm closing this.