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

k8s:watch uses default namespace even if other namespace is configured #1180

Closed
petergarnaes opened this issue Dec 20, 2021 · 3 comments · Fixed by #1189
Closed

k8s:watch uses default namespace even if other namespace is configured #1180

petergarnaes opened this issue Dec 20, 2021 · 3 comments · Fixed by #1189
Assignees
Labels
bug Something isn't working
Milestone

Comments

@petergarnaes
Copy link

Description

Info

  • Eclipse JKube version : 1.5.1
  • Maven version (mvn -v) :
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: REDACTED
Java version: 17, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-162-generic", arch: "amd64", family: "unix"
  • Kubernetes / Red Hat OpenShift setup and version :
➜ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.17", GitCommit:"68b4e26caf6ede7af577db4af62fb405b4dd47e6", GitTreeState:"clean", BuildDate:"2021-03-18T00:54:02Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

Issue

I am working on a Rancher cluster

Since it involves a Rancher cluster, I can't give a good guide on how to reproduce, but the issue is pretty straight forward. When I am trying to run mvn k8s:resource k8s:build k8s:push k8s:watch, my docker image is built, pushed and deployed correctly (I can find the deployment in the cluster) but I get the following error:

[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.5.1:watch (default-cli) on project spring-kube-demo: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.5.1:watch failed: Failure executing: GET at: https://rancher-cluster.my-company.com/k8s/clusters/local/api/v1/namespaces/default/pods?labelSelector=app%3Dspring-kube-demo%2Cprovider%3Djkube%2Cgroup%3Dcom.mycompany.mydepartment. Message: Forbidden! User myuser doesn't have permission. pods is forbidden: User "myuser" cannot list resource "pods" in API group "" in the namespace "default". -> [Help 1]

Not providing access to the default namespace is by design in Rancher clusters. I do have the namespace configured in my pom.xml:

<plugin>
  <groupId>org.eclipse.jkube</groupId>
    <artifactId>kubernetes-maven-plugin</artifactId>
    <version>1.5.1</version>
    <configuration>
      <namespace>development</namespace>
         <images>
          ...
        </images>
    </configuration>
</plugin>    

I would expect k8s:watch to use the configured namespace.

Full stack trace

@manusa manusa added this to the 1.6.0 milestone Dec 21, 2021
@manusa manusa added the bug Something isn't working label Dec 21, 2021
@rohanKanojia
Copy link
Member

@petergarnaes : Thanks a lot for reporting. I can reproduce this issue. Looks like instead of reading namespace configuration k8s:watch is picking up namespace from .kube/config context :

contexts:
- context:
    cluster: minikube
    namespace: default
    user: minikube
  name: minikube

@petergarnaes
Copy link
Author

petergarnaes commented Dec 21, 2021

@rohanKanojia you are correct, don't know why i did not think of that! Thanks for helping me move on in the current version of the plugin.

@rohanKanojia rohanKanojia self-assigned this Dec 24, 2021
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Dec 24, 2021
… if other namespace is configured

No namespace is specified to Watcher while delegating watch task from
Mojos/Tasks to JKube Kit. Right now Watcher was just picking namespace
from `clusterAccess.getNamespace()` (namespace provided in current
context in `.kube/config`).

Add an additional namespace parameter in Watcher.watch(...) method for
providing configured namespace.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@rohanKanojia
Copy link
Member

I've created a fix for this issue. I think now watch should pick correct configured namespace

Using Kubernetes Maven Plugin, I tested this via adding a namespace in plugin configuration which was not equal to the one in kubeconfig current context:

            <plugin>
                <groupId>org.eclipse.jkube</groupId>
                <artifactId>kubernetes-maven-plugin</artifactId>
                <version>${jkube.version}</version>
                <configuration>
                  <namespace>development</namespace>
                </configuration>
            </plugin>

Using Kubernetes Gradle Plugin, I specified namespace in Groovy configuration:

plugins {
    id 'org.eclipse.jkube.kubernetes' version '1.5.1'
}

kubernetes {
    namespace = 'development'
}

rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Dec 24, 2021
… if other namespace is configured

No namespace is specified to Watcher while delegating watch task from
Mojos/Tasks to JKube Kit. Right now Watcher was just picking namespace
from `clusterAccess.getNamespace()` (namespace provided in current
context in `.kube/config`).

Add an additional namespace parameter in Watcher.watch(...) method for
providing configured namespace.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Dec 27, 2021
… if other namespace is configured

No namespace is specified to Watcher while delegating watch task from
Mojos/Tasks to JKube Kit. Right now Watcher was just picking namespace
from `clusterAccess.getNamespace()` (namespace provided in current
context in `.kube/config`).

Add an additional namespace parameter in Watcher.watch(...) method for
providing configured namespace.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Jan 10, 2022
… if other namespace is configured

No namespace is specified to Watcher while delegating watch task from
Mojos/Tasks to JKube Kit. Right now Watcher was just picking namespace
from `clusterAccess.getNamespace()` (namespace provided in current
context in `.kube/config`).

Add an additional namespace parameter in Watcher.watch(...) method for
providing configured namespace.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
manusa pushed a commit that referenced this issue Jan 14, 2022
…espace is configured

No namespace is specified to Watcher while delegating watch task from
Mojos/Tasks to JKube Kit. Right now Watcher was just picking namespace
from `clusterAccess.getNamespace()` (namespace provided in current
context in `.kube/config`).

Add an additional namespace parameter in Watcher.watch(...) method for
providing configured namespace.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants