Skip to content

Commit

Permalink
Merge pull request #1433 from FabianKramm/main
Browse files Browse the repository at this point in the history
refactor: add isRemote to WriteKubeConfigToSecret
  • Loading branch information
FabianKramm authored Dec 28, 2023
2 parents d7876d3 + 2536391 commit 8235e1b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/setup/controller_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func CreateVClusterKubeConfig(config *clientcmdapi.Config, options *options.Virt
return config, nil
}

func WriteKubeConfigToSecret(ctx context.Context, currentNamespace string, currentNamespaceClient client.Client, options *options.VirtualClusterOptions, config *clientcmdapi.Config) error {
func WriteKubeConfigToSecret(ctx context.Context, currentNamespace string, currentNamespaceClient client.Client, options *options.VirtualClusterOptions, config *clientcmdapi.Config, isRemote bool) error {
config, err := CreateVClusterKubeConfig(config, options)
if err != nil {
return err
Expand Down Expand Up @@ -334,14 +334,14 @@ func WriteKubeConfigToSecret(ctx context.Context, currentNamespace string, curre
}

// write the extra secret
err = kubeconfig.WriteKubeConfig(ctx, currentNamespaceClient, options.KubeConfigSecret, secretNamespace, config)
err = kubeconfig.WriteKubeConfig(ctx, currentNamespaceClient, options.KubeConfigSecret, secretNamespace, config, isRemote)
if err != nil {
return fmt.Errorf("creating %s secret in the %s ns failed: %w", options.KubeConfigSecret, secretNamespace, err)
}
}

// write the default Secret
return kubeconfig.WriteKubeConfig(ctx, currentNamespaceClient, kubeconfig.GetDefaultSecretName(translate.Suffix), currentNamespace, config)
return kubeconfig.WriteKubeConfig(ctx, currentNamespaceClient, kubeconfig.GetDefaultSecretName(translate.Suffix), currentNamespace, config, isRemote)
}

func InitControllerContext(
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartControllers(controllerContext *options.ControllerContext) error {
// write the kube config to secret
go func() {
wait.Until(func() {
err := WriteKubeConfigToSecret(controllerContext.Context, controllerContext.CurrentNamespace, controllerContext.CurrentNamespaceClient, controllerContext.Options, controllerContext.VirtualRawConfig)
err := WriteKubeConfigToSecret(controllerContext.Context, controllerContext.CurrentNamespace, controllerContext.CurrentNamespaceClient, controllerContext.Options, controllerContext.VirtualRawConfig, false)
if err != nil {
klog.Errorf("Error writing kube config to secret: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
CertificateKeySecretKey = "client-key"
)

func WriteKubeConfig(ctx context.Context, currentNamespaceClient client.Client, secretName, secretNamespace string, config *api.Config) error {
func WriteKubeConfig(ctx context.Context, currentNamespaceClient client.Client, secretName, secretNamespace string, config *api.Config, isRemote bool) error {
out, err := clientcmd.Write(*config)
if err != nil {
return err
Expand Down Expand Up @@ -73,7 +73,7 @@ func WriteKubeConfig(ctx context.Context, currentNamespaceClient client.Client,
kubeConfigSecret.Data[CertificateKeySecretKey] = key

// set owner reference
if translate.Owner != nil && translate.Owner.GetNamespace() == kubeConfigSecret.Namespace {
if !isRemote && translate.Owner != nil && translate.Owner.GetNamespace() == kubeConfigSecret.Namespace {
kubeConfigSecret.OwnerReferences = translate.GetOwnerReference(nil)
}
return nil
Expand Down

0 comments on commit 8235e1b

Please sign in to comment.