Skip to content

Commit

Permalink
Allow overriding secretKey for kubeadm kubeconfig
Browse files Browse the repository at this point in the history
During reconciliation, the bootstrap provider copies the content from the secret provided by Kamaji, named `<cluster>-admin-kubeconfig` into a `cluster-info` configmap of tenant cluster, which then used by kubeadm to join nodes.

This change introduces a new annotation, `kamaji.clastix.io/kubeconfig-secret-key`, for the TenantControlPlane resource. This annotation instructs kamaji to read the kubeconfig from a specific key (the default one is super-admin.conf).

Example:

```
kamaji.clastix.io/kubeconfig-secret-key: super-admin.svc
```

This will instruct the system to use `super-admin.svc` a kubeconfig with a local service FQDN (introduced by #403).

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
  • Loading branch information
kvaps authored and prometherion committed Apr 18, 2024
1 parent 1311220 commit ced34a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ func (c CGroupDriver) String() string {
}

const (
ServiceTypeLoadBalancer = (ServiceType)(corev1.ServiceTypeLoadBalancer)
ServiceTypeClusterIP = (ServiceType)(corev1.ServiceTypeClusterIP)
ServiceTypeNodePort = (ServiceType)(corev1.ServiceTypeNodePort)
ServiceTypeLoadBalancer = (ServiceType)(corev1.ServiceTypeLoadBalancer)
ServiceTypeClusterIP = (ServiceType)(corev1.ServiceTypeClusterIP)
ServiceTypeNodePort = (ServiceType)(corev1.ServiceTypeNodePort)
KubeconfigSecretKeyAnnotation = "kamaji.clastix.io/kubeconfig-secret-key"
)

// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
Expand Down
8 changes: 7 additions & 1 deletion internal/utilities/tenant_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ func GetTenantKubeconfig(ctx context.Context, client client.Client, tenantContro
return nil, err
}

return DecodeKubeconfig(*secretKubeconfig, kubeadmconstants.SuperAdminKubeConfigFileName)
secretKey := kubeadmconstants.SuperAdminKubeConfigFileName
v, ok := tenantControlPlane.GetAnnotations()[kamajiv1alpha1.KubeconfigSecretKeyAnnotation]
if ok && v != "" {
secretKey = v
}

return DecodeKubeconfig(*secretKubeconfig, secretKey)
}

func GetRESTClientConfig(ctx context.Context, client client.Client, tenantControlPlane *kamajiv1alpha1.TenantControlPlane) (*restclient.Config, error) {
Expand Down

0 comments on commit ced34a5

Please sign in to comment.