diff --git a/cli/cmd/cluster-apply.go b/cli/cmd/cluster-apply.go index 0a75d1557..b9064e684 100644 --- a/cli/cmd/cluster-apply.go +++ b/cli/cmd/cluster-apply.go @@ -84,6 +84,13 @@ func runClusterApply(cmd *cobra.Command, args []string) { ctxLogger.Fatalf("Verify cluster: %v", err) } + labels := map[string]string{ + "lokomotive.kinvolk.io/name": "kube-system", + } + + if err := k8sutil.UpdateNamespaceWithLabels(labels, "kube-system", kubeconfigPath); err != nil { + ctxLogger.Fatalf("error updating namespace with labels: %q", err) + } // Do controlplane upgrades only if cluster already exists and it is not a managed platform. if exists && !p.Meta().Managed { fmt.Printf("\nEnsuring that cluster controlplane is up to date.\n") diff --git a/pkg/components/util/install.go b/pkg/components/util/install.go index 95f69867f..f04995ade 100644 --- a/pkg/components/util/install.go +++ b/pkg/components/util/install.go @@ -44,6 +44,9 @@ func ensureNamespaceExists(name string, kubeconfigPath string) error { _, err = cs.CoreV1().Namespaces().Create(context.TODO(), &v1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: name, + Labels: map[string]string{ + "lokomotive.kinvolk.io/name": name, + }, }, }, metav1.CreateOptions{}) if err != nil && !errors.IsAlreadyExists(err) { @@ -62,6 +65,14 @@ func InstallComponent(c components.Component, kubeconfig string) error { return fmt.Errorf("failed ensuring that namespace %q for component %q exists: %w", ns, name, err) } + labels := map[string]string{ + "lokomotive.kinvolk.io/name": ns, + } + + if err := k8sutil.UpdateNamespaceWithLabels(labels, ns, kubeconfig); err != nil { + return fmt.Errorf("failed updating namespace %q with labels for component %q: %w", ns, name, err) + } + actionConfig, err := HelmActionConfig(ns, kubeconfig) if err != nil { return fmt.Errorf("failed preparing helm client: %w", err)