From bdf3abbfcc6b6b705b432b49c4a5e234479afed7 Mon Sep 17 00:00:00 2001 From: maheshbaliga Date: Wed, 11 Dec 2024 22:44:41 +0530 Subject: [PATCH] bugfix: set labels to kubeconfig and cert secrets --- pkg/certs/ensure.go | 10 ++++++++++ pkg/util/kubeconfig/kubeconfig.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/certs/ensure.go b/pkg/certs/ensure.go index 01b44bbd24..4fe1697ec8 100644 --- a/pkg/certs/ensure.go +++ b/pkg/certs/ensure.go @@ -22,6 +22,12 @@ import ( "k8s.io/klog/v2" ) +const ( + CertSecretLabelAppKey = "app" + CertSecretLabelAppValue = "vcluster" + CertSecretLabelReleaseKey = "release" +) + func EnsureCerts( ctx context.Context, serviceCIDR string, @@ -131,6 +137,10 @@ func EnsureCerts( Name: secretName, Namespace: currentNamespace, OwnerReferences: ownerRef, + Labels: map[string]string{ + CertSecretLabelAppKey: CertSecretLabelAppValue, + CertSecretLabelReleaseKey: currentNamespace, + }, }, Data: map[string][]byte{}, } diff --git a/pkg/util/kubeconfig/kubeconfig.go b/pkg/util/kubeconfig/kubeconfig.go index 84c4e6c4fb..16bdc316cd 100644 --- a/pkg/util/kubeconfig/kubeconfig.go +++ b/pkg/util/kubeconfig/kubeconfig.go @@ -32,6 +32,9 @@ const ( CertificateSecretKey = "client-certificate" CertificateKeySecretKey = "client-key" TokenSecretKey = "token" + KubeConfigSecretLabelAppKey = "app" + KubeConfigSecretLabelAppValue = "vcluster" + KubeConfigSecretLabelReleaseKey = "release" ) func WriteKubeConfig(ctx context.Context, currentNamespaceClient client.Client, secretName, secretNamespace string, config *clientcmdapi.Config, isRemote bool) error { @@ -70,6 +73,10 @@ func WriteKubeConfig(ctx context.Context, currentNamespaceClient client.Client, ObjectMeta: metav1.ObjectMeta{ Name: secretName, Namespace: secretNamespace, + Labels: map[string]string{ + KubeConfigSecretLabelAppKey: KubeConfigSecretLabelAppValue, + KubeConfigSecretLabelReleaseKey: secretNamespace, + }, }, } result, err := controllerutil.CreateOrPatch(ctx, currentNamespaceClient, kubeConfigSecret, func() error {