Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60937

Pods are not created due to 'invalid label value: "jenkins/slave-default"'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • kubernetes-plugin
    • kubernetes-plugin 1.22.1 and following
      Jenkins LTS 2.190.1
      configuration-as-code-plugin
    • kubernetes 1.23.2

      Since upgrading to version 1.22.1 and higher of the kubernetes-plugin pods are not created (and therefore builds are not starting) due to the following error:

      Failed to count the # of live instances on Kubernetes
      io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: GET at: https://172.30.40.1/api/v1/namespaces/rdf4j/pods?labelSelector=jenkins%3Dslave%2Cjenkins%2Flabel%3Djenkins%2Fslave-default. Message: unable to parse requirement: invalid label value: "jenkins/slave-default": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'). Received status: Status(apiVersion=v1, code=400, details=null, kind=Status, message=unable to parse requirement: invalid label value: "jenkins/slave-default": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=BadRequest, status=Failure, additionalProperties={}).
      	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:510)
      

      We use the JCasC plugin to define our pod templates and we don't use labels for pod templates. This causes the label to not only be empty ("") but not be set (null) after every restart of the master (or when the JCasC config is re-applied).

      This leads to the DEFAULT_ID being used in PodTemplate.getLabelsMap():

      public Map<String, String> getLabelsMap() {
          return ImmutableMap.of("jenkins/label", label == null ? DEFAULT_ID : sanitizeLabel(label));
      }
      

      See https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java#L383-L385

      Unfortunately the DEFAULT_ID is set to "jenkins/slave-default":

      private static final String DEFAULT_ID = "jenkins/slave-default";
      

      See https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java#L59

      Then the following labels are created:

      jenkins=slave
      jenkins/label=jenkins/slave-default
      

      This fails because the value of "jenkins/label" contains a slash ("jenkins/slave-default") which is not allowed.

      I'd suggest to change the DEFAULT_ID string to "slave-default" and rename it to DEFAULT_LABEL for good measure.

      PR incoming.

      Workaround is to set pod template labels via JCasC for now.

            fredg Fred G
            fredg Fred G
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: