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

Commit

Permalink
lokomotive: update namespace with labels
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 26, 2020
1 parent 4ed8a4e commit 8733e78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/cmd/cluster-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/kinvolk/lokomotive/internal"
"github.com/kinvolk/lokomotive/pkg/install"
"github.com/kinvolk/lokomotive/pkg/k8sutil"
"github.com/kinvolk/lokomotive/pkg/lokomotive"
Expand Down Expand Up @@ -84,6 +85,12 @@ func runClusterApply(cmd *cobra.Command, args []string) {
ctxLogger.Fatalf("Verify cluster: %v", err)
}

labels := map[string]string{}
internal.AppendNamespaceNameToLabels("kube-system", &labels)

if err := k8sutil.UpdateNamespaceWithLabels(labels, "kube-system", kubeconfigPath); err != nil {
ctxLogger.Fatalf("error updating namespace %q with labels: %q", "kube-system", 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")
Expand Down
6 changes: 6 additions & 0 deletions pkg/components/util/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ 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 := c.GetNamespaceLabels()

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 8733e78

Please sign in to comment.