kubernetes-sigs / cluster-api-provider-kubevirt

Cluster API Provider for KubeVirt
Apache License 2.0
110 stars 63 forks source link

Tenant namespace should fallback to current context namespace if external kubeconfig is specified. #158

Closed pjaton closed 2 years ago

pjaton commented 2 years ago

What steps did you take and what happened:

Discussed with @agradouski:

The namespace where to spawn a tenant cluster should be resolved as follow:

  1. the namespace specified by the enduser in a node's VirtualMachine template; i.e. as KubevirtMachineTemplate.spec.template.spec.virtualMachineTemplate.metadata.namespace
  2. If this is not set and an infraClusterSecretRef is set for this cluster:
    1. If set, use the namespace directly set as a value in the secret.
    2. Otherwise, fallback to the namespace of the context currently selected in the kubeconfig set in the secret.
    3. If the latter is not set, then fallback to the default namespace
  3. Otherwise, use the "current" namespace where the cluster specification has been created.

The current logic skips 2.ii; i.e. it ignores the namespace, if any, set in the kubeconfig file for the current context and directly fallback to default.

What did you expect to happen:

If the end-user did not specified a namespace in the virtual-machine template, and they reference a secret with a kubeconfig to connect to the infrastructure, but the secret doesn't specified directly a namespace, then the namespace of the context currently selected in the kubeconfig should be used, if it is set.

Environment:

/kind bug

pjaton commented 2 years ago

/assign @pjaton