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

out-kube-config-secret-namespace feature produces unknown namespace for the cache error #1291

Open
guyguy333 opened this issue Oct 10, 2023 · 5 comments
Assignees
Labels

Comments

@guyguy333
Copy link

What happened?

I try to use out-kube-config-secret-namespace syncer feature but I'm getting this error:

Error writing kube config to secret: creating xxxxx-kubeconfig secret in the vclusters ns failed: apply generated kube config secret: unable to get: vclusters/xxxxx-kubeconfig because of unknown namespace for the cache

vCluster syncer is running in vcluster-xxxx namespace and I would like my kubeconfig secret to be available in vclusters namespace.
I added this RBAC so syncer pod can read/write secrets in vclusters namespace without luck. Any idea what's wrong ?

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: vclusters-kubeconfig-rw
  namespace: vclusters
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: vclusters-kubeconfig-rw-xxxxx
  namespace: vclusters
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: vclusters-kubeconfig-rw
subjects:
  - kind: ServiceAccount
    name: vc-vcluster
    namespace: vcluster-xxxx

What did you expect to happen?

  • No longer syncer error and a secret write in the right namespace
  • Minimal RBAC documented for this feature

How can we reproduce it (as minimally and precisely as possible)?

Just use out-kube-config-secret-namespace feature with a namespace different than vcluster namespace

Anything else we need to know?

No response

Host cluster Kubernetes version

$ kubectl version
1.28

Host cluster Kubernetes distribution

EKS

vlcuster version

$ vcluster --version
v0.16.2

Vcluster Kubernetes distribution(k3s(default)), k8s, k0s)

# Write here

OS and Arch

OS: 
Arch:
@rikycaldeira
Copy link

rikycaldeira commented Oct 12, 2023

I've hit this problem as well, seems that in the current version of controller-runtime it is entering multi-namespace mode, and when creating the blocking cache client if the separate kubeconfig secret namespace is not in the list of default namespaces no namespace cache mapping is initialized

I'd suggest creating a new client to interact with the separate namespace to manage the kubeconfig secret, unless there's a way to do it via the existing blocking cache client? If the separate namespace is added to the default namespaces of the existing client it probably will initialize informers for a lot more than the kubeconfig secret

@matskiv
Copy link
Contributor

matskiv commented Oct 12, 2023

@rikycaldeira sounds like you understand the problem quite well, would you be interested in contributing a PR? And since it is Hacktoberfest, Loft is also giving away some swag for the PR contributors. :)

@rikycaldeira
Copy link

I can give it a try, although I'm not super familiar with the codebase, hope I don't ruin something :D
I'll follow my own suggestion of instantiating a dedicated client and put it up for review

@matskiv
Copy link
Contributor

matskiv commented Oct 13, 2023

Awesome! Feel free to reach out to the team in Slack if you need any help. Don't forget to check out contributing.md, we are using DevSpace for dev, which should make iterating the implementation easier :)

@guyguy333
Copy link
Author

@rikycaldeira @matskiv Did you work on a fix ? Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants