-
New Feature
-
Resolution: Unresolved
-
Minor
Hi,
I would like to be able to access Kubernetes Node where pods are running to log them into Jenkins console log. Searching the web they suggest to do it using envvars and accessing spec info were Kubernetes node is stored and take that info from there:
Something like:
spec: containers: - name: example-container image: jenkins/inbound-agent env: - name: NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName
----------------------------------------------------------------------------------------------------------------------------------------
I tried to define an envvar at container level and pod level (separately, on different runs), but it seems like the info is not fully available or I'm having issues with the envars because defining them even with "hard-coded" string values is not setting them as expected neither:
adapter.podTemplate( cloud: podTemplate.cloud, namespace: this.namespace, label: podName, containers: podTemplate.containers, volumes: podTemplate.volumes + this.extraVolumes envars:[ pod_name:[ key: "pod_name" value: "testing_envars" ] ] )
At Containertemplate level:
protected def defaultContainer() { return adapter.containerTemplate( name: containerName, i mage: image, ttyEnabled: true, command: this.appType ? "cat": "", privileged: this.appType ? false : true, resourceRequestCpu: res.resourceRequestCpu, resourceRequestMemory: res.resourceRequestMemory, resourceLimitCpu: res.resourceLimitCpu, resourceLimitMemory: res.resourceLimitMemory, resourceRequestEphemeralStorage:res.resourceRequestEphemeralStorage, envars:[ pod_name:[ key: "pod_name" value: "testing_envars" ] ) }
Neither of them worked, and also at Jenkins console level the error was something like:
14:26:57 [Pipeline] podTemplate 14:26:57 [Pipeline] // podTemplate 14:26:57 [Pipeline] End of Pipeline 14:26:57 java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List 14:26:57 at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:580) 14:26:57 at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:479) 14:26:57 at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:435) 14:26:57 at PluginClassLoader for structs//org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:332) 14:26:57 Caused: java.lang.IllegalArgumentException: Could not instantiate {name=worker, image=imagelatest, ttyEnabled=true, command=, privileged=true, resourceRequestCpu=2, resourceRequestMemory=2Gi, resourceLimitCpu=8, resourceLimitMemory=12Gi, resourceRequestEphemeralStorage=null, envVars={key=pod_name, value=testing_envars}} for org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate
Just in case all the other parameters at container level and at pod level are working perfectly.