Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
add labels to namespace
Browse files Browse the repository at this point in the history
Adds `lokomotive.kinvolk.io/name: <namespace-name>` label to the
`kube-system` and components Namespace.

This allows NetworkPolicies to be applied using the `namespaceSelector`.

Signed-off-by: Imran Pochi <imran@kinvolk.io>
  • Loading branch information
ipochi committed Jun 22, 2020
1 parent ebf9ce3 commit 373ab03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/cmd/cluster-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func runClusterApply(cmd *cobra.Command, args []string) {
ctxLogger.Fatalf("Verify cluster: %v", err)
}

labels := map[string]string{
"lokomotive.kinvolk.io/name": "kube-system",
}

k8sutil.UpdateNamespaceWithLabels(labels, "kube-system", kubeconfigPath)

// 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")
Expand Down
11 changes: 11 additions & 0 deletions pkg/components/util/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 373ab03

Please sign in to comment.