KubernetesComputer container logs always give 'Pod not found' error

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major
    • Component/s: kubernetes-plugin
    • None

      Hi,

      This PR https://github.com/jenkinsci/kubernetes-plugin/pull/1699 was intended to improve the 'KubernetesComputer' container logs.
      However, logs for a container always give the message: 'Pod not found'.

      After a quick look at the source code, the error became clear very quickly.
      In short, the query param 'containerId' is used to find the 'PodResource'. I believe the correct value should be the pod name, which is passed as a path param.

          public void doContainerLog(@QueryParameter String containerId, StaplerRequest2 req, StaplerResponse2 rsp)
                  throws KubernetesAuthException, IOException {
              String podName = req.getContextPath()
              Jenkins.get().checkPermission(Computer.EXTENDED_READ);
              ByteBuffer outputStream = new ByteBuffer();
              LargeText text = new LargeText(outputStream, false);
              KubernetesSlave slave = getNode();
              if (slave != null) {
                  KubernetesCloud cloud = slave.getKubernetesCloud();
                  String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), cloud.getNamespace());
                  PodResource resource = cloud.getPodResource(namespace, containerId);
      // ... 

      A request's context looks like this:

      /jenkins/computer/mypodname/containerLog?containerId=jnlp 

            Assignee:
            Unassigned
            Reporter:
            Antonio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: