Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ConfigMapKeyRefEnvVar and fieldRefEnvVar to set env from more sources #297

Closed
wants to merge 2 commits into from

Conversation

jenningsloy318
Copy link

and two sources to create ENV

  1. ConfigMapKeyRefEnvVar to create env from configmap
  2. fieldRefEnvVar to create env from pod ObjectField(status.hostIP, status.podIP, ..etc)

Refer to https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#envvarsource-v1-core

…efEnvVar to create env from pod ObjectField(status.hostIP, status.podIP, ..etc)
@carlossg
Copy link
Contributor

Thanks, although I'm trying to focus on #275 instead of adding fields for any possible value which will make the plugin too complex

@jenningsloy318
Copy link
Author

Hi @carlossg:

Thanks for your info, I wonder when #275 is stable enough that we can use. I implemented this feature because current plugin missed some feature.

I also need one feature that in the volume part, sometime to mount a volume, we still need to specify the subPath when multiple volumes are mounted under one mount point.

@carlossg
Copy link
Contributor

carlossg commented Apr 6, 2018

#275 is done, please give it a try and see if this is still needed

@jenningsloy318
Copy link
Author

@carlossg

HI today I tried with new version with following plugin, but it still lacks the flexilility.

I'd want to add some volumes and env, but still not working.

pipeline {
  agent {
    kubernetes {
        label'jnlp-slave'
        cloud 'kubernetes'
        defaultContainer 'jnlp-slave'
        yaml """
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-agent-pvc
  namespace: jenkins
  annotations:
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi 
---
apiVersion: v1
kind: Pod
metadata:
    namespace: jenkins
  labels:
    name: jnlp-slave
spec:
  containers:
  - name: jnlp-slave
    image: jenkinsci/jnlp-slave
    command:
    resources:
      limits:
        cpu: 1
        memory: 2Gi
    env:
    - name: JAVA_OPTS
      value: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
    - name: JENKINS_URL
      value: http://jenkins.jenkins:8080/
    - name: JENKINS_AGENT_WORKDIR
      value: /var/jenkins_home
    volumeMounts: 
    - name: jenkins-home
      mountPath: /var/jenkins_home
    securityContext:
        runAsUser: 0
    volumes: 
    - name: localtime
      hostPath:
        path: /etc/localtime      
    - name: jenkins-home
      persistentVolumeClaim:
        claimName: jenkins-agent-pvc     
"""
}
}
stages {

        stage('build the source code and create docker image') {
            steps {
                sh 'mvn -B clean install'
            }
        }

    }
}

when I check the running pod, no env named JAVA_OPTS or JENKINS_AGENT_WORKDIR.

# kubectl describe pod jnlp-slave-zpfs0-js64z
Name:           jnlp-slave-zpfs0-js64z
Namespace:      jenkins
Node:           ip-10-250-1-135.eu-central-1.compute.internal/10.250.1.135
Start Time:     Thu, 26 Apr 2018 19:12:11 +0800
Labels:         <none>
Annotations:    cni.projectcalico.org/podIP=100.96.2.19/32
Status:         Running
IP:             100.96.2.19
Containers:
  jnlp:
    Container ID:       docker://3a88d81268d5ed1614611a4a605141ef1ed07bef73bb545d61babcd01d60cb5d
    Image:              jenkins/jnlp-slave:alpine
    Image ID:           docker-pullable://jenkins/jnlp-slave@sha256:7038c115ef71aee0820ccbcc9e2e723767efd47eee664fdb2bdf82a99acfdd71
    Port:               <none>
    State:              Running
      Started:          Thu, 26 Apr 2018 19:12:12 +0800
    Ready:              True
    Restart Count:      0
    Environment:
      JENKINS_SECRET:   6095a6bac778d981da7de573cf12d430ddb3488efe75f6f395879905f19ec97d
      JENKINS_NAME:     jnlp-slave-zpfs0-js64z
      JENKINS_URL:      http://jenkins.jenkins:8080/
      HOME:             /home/jenkins
    Mounts:
      /home/jenkins from workspace-volume (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-h255r (ro)
Conditions:
  Type          Status
  Initialized   True
  Ready         True
  PodScheduled  True
Volumes:
  workspace-volume:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
  default-token-h255r:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-h255r
    Optional:   false
QoS Class:      BestEffort
Node-Selectors: <none>
Tolerations:    node.kubernetes.io/not-ready:NoExecute for 300s
                node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  FirstSeen     LastSeen        Count   From                                                    SubObjectPath           Type            Reason                  Message
  ---------     --------        -----   ----                                                    -------------           --------        ------                  -------
  1m            1m              1       default-scheduler                                                               Normal          Scheduled               Successfully assigned jnlp-slave-zpfs0-js64z to ip-10-250-1-135.eu-central-1.compute.internal
  59s           59s             1       kubelet, ip-10-250-1-135.eu-central-1.compute.internal                          Normal          SuccessfulMountVolume   MountVolume.SetUp succeeded for volume "workspace-volume"
  59s           59s             1       kubelet, ip-10-250-1-135.eu-central-1.compute.internal                          Normal          SuccessfulMountVolume   MountVolume.SetUp succeeded for volume "default-token-h255r"
  59s           59s             1       kubelet, ip-10-250-1-135.eu-central-1.compute.internal  spec.containers{jnlp}   Normal          Pulled                  Container image "jenkins/jnlp-slave:alpine" already present on machine
  59s           59s             1       kubelet, ip-10-250-1-135.eu-central-1.compute.internal  spec.containers{jnlp}   Normal          Created                 Created container
  59s           59s             1       kubelet, ip-10-250-1-135.eu-central-1.compute.internal  spec.containers{jnlp}   Normal          Started                 Started container

@carlossg
Copy link
Contributor

First, try without the PersistentVolumeClaim, the yaml should be only the pod definition, I don't even know if that would work
You have a missing space at label'jnlp-slave'
I think this is picking a different agent, do you have any other agents defined in jenkins config with label jnlp-slave ? try with a new label to see

@jenningsloy318
Copy link
Author

jenningsloy318 commented Apr 27, 2018

@carlossg

" I think this is picking a different agent, do you have any other agents defined in jenkins config with label jnlp-slave ? try with a new label to see"

Yes, I made a new image based on the official jnlp image.

@carlossg
Copy link
Contributor

I meant you have more than one pod template defined in jenkins with the same label so when it runs it may be picking the other one instead of the one defined in your pipeline

@carlossg carlossg closed this Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants