Skip to content

Commit

Permalink
feat: allow overriding secretKey for kubeconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Kvapil <[email protected]>
  • Loading branch information
kvaps authored Apr 23, 2024
1 parent e949f41 commit 9ff3a33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions controllers/kamajicontrolplane_controller_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *KamajiControlPlaneReconciler) createOrUpdateKubeconfig(ctx context.Cont
kamajiAdminKubeconfig.Namespace = tcp.Namespace

if err := r.client.Get(ctx, types.NamespacedName{Name: kamajiAdminKubeconfig.Name, Namespace: kamajiAdminKubeconfig.Namespace}, kamajiAdminKubeconfig); err != nil {
return errors.Wrap(err, "cannot retrieve source-of-truth for admin kubecofig")
return errors.Wrap(err, "cannot retrieve source-of-truth for admin kubeconfig")
}

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expand All @@ -147,7 +147,12 @@ func (r *KamajiControlPlaneReconciler) createOrUpdateKubeconfig(ctx context.Cont
labels["kamaji.clastix.io/cluster"] = cluster.Name
labels["kamaji.clastix.io/tcp"] = tcp.Name

value, ok := kamajiAdminKubeconfig.Data["admin.conf"]
secretKey := "admin.conf"
if v, ok := kcp.GetAnnotations()[kamajiv1alpha1.KubeconfigSecretKeyAnnotation]; ok && v != "" {
secretKey = v
}

value, ok := kamajiAdminKubeconfig.Data[secretKey]
if !ok {
return errors.New("missing key from *kamajiv1alpha1.TenantControlPlane admin kubeconfig secret")
}
Expand Down
10 changes: 10 additions & 0 deletions controllers/kamajicontrolplane_controller_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func (r *KamajiControlPlaneReconciler) createOrUpdateTenantControlPlane(ctx cont
tcp.Name = kcp.GetName()
tcp.Namespace = kcp.GetNamespace()

if tcp.Annotations == nil {
tcp.Annotations = make(map[string]string)
}

if kubeconfigSecretKey := kcp.Annotations[kamajiv1alpha1.KubeconfigSecretKeyAnnotation]; kubeconfigSecretKey != "" {
tcp.Annotations[kamajiv1alpha1.KubeconfigSecretKeyAnnotation] = kubeconfigSecretKey
} else {
delete(tcp.Annotations, kamajiv1alpha1.KubeconfigSecretKeyAnnotation)
}

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
_, scopeErr := controllerutil.CreateOrUpdate(ctx, r.client, tcp, func() error {
// TenantControlPlane port
Expand Down

0 comments on commit 9ff3a33

Please sign in to comment.