Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
[Add] add default namespace if not specified
Browse files Browse the repository at this point in the history
If the bundle objects do not specify a namespace,
use the default namespace to deploy them.

Signed-off-by: Varsha Prasad Narsing <[email protected]>
  • Loading branch information
varshaprasad96 committed Sep 18, 2023
1 parent f4888e8 commit 9b3df66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ generate: $(CONTROLLER_GEN) ## Generate code and manifests
paths=./internal/uploadmgr/... \
output:stdout > ./manifests/base/core/resources/cluster_role.yaml
$(Q)$(CONTROLLER_GEN) rbac:roleName=webhooks-admin paths=./internal/webhook/... output:stdout > ./manifests/base/apis/webhooks/resources/cluster_role.yaml
$(Q)$(CONTROLLER_GEN) rbac:roleName=helm-provisioner-admin \
paths=./internal/controllers/bundle/... \
paths=./internal/controllers/bundledeployment/... \
paths=./internal/provisioner/helm/... \
output:stdout > ./manifests/base/provisioners/helm/resources/cluster_role.yaml

verify: tidy fmt generate ## Verify the current code generation and lint
git diff --exit-code
Expand Down Expand Up @@ -144,7 +139,6 @@ install-manifests:
wait:
$(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/core --timeout=60s
$(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/rukpak-webhooks --timeout=60s
$(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/helm-provisioner --timeout=60s
$(KUBECTL) wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s

run: build-container kind-cluster kind-load install ## Build image, stop/start a local kind cluster, and run operator in that cluster
Expand All @@ -171,7 +165,7 @@ uninstall: ## Remove all rukpak resources from the cluster

##@ build/load:

BINARIES=core helm unpack webhooks crdvalidator rukpakctl
BINARIES=core unpack webhooks crdvalidator rukpakctl
LINUX_BINARIES=$(join $(addprefix linux/,$(BINARIES)), )

.PHONY: build $(BINARIES) $(LINUX_BINARIES) build-container kind-load kind-load-bundles kind-cluster registry-load-bundles
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha2/bundledeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
)

var (
Expand Down Expand Up @@ -87,6 +87,8 @@ type BundleDeploymentSpec struct {
// Should move to helm deployer configuration.
// +kubebuilder:pruning:PreserveUnknownFields
Config runtime.RawExtension `json:"config,omitempty"`
// +optional
DefaultNamespace string `json:"defaultnamespace,omitempty"`
}

// BundleDeploymentStatus defines the observed state of BundleDeployment
Expand Down
11 changes: 9 additions & 2 deletions internal/controllers/v1alpha2/deployer/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (hd *helmDeployer) Deploy(ctx context.Context, fs afero.Fs, bundleDeploymen
util.CoreOwnerKindKey: v1alpha2.BundleDeploymentKind,
util.CoreOwnerNameKey: bundleDeployment.GetName(),
},
defaultNamespace: bundleDeployment.Spec.DefaultNamespace,
}

rel, state, err := hd.getReleaseState(cl, bundleDeployment, chrt, values, post)
Expand Down Expand Up @@ -320,8 +321,9 @@ func getChartFromPlainBundle(chartfs afero.Fs, bd *v1alpha2.BundleDeployment) (*
}

type postrenderer struct {
labels map[string]string
cascade postrender.PostRenderer
labels map[string]string
defaultNamespace string
cascade postrender.PostRenderer
}

func (p *postrenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) {
Expand All @@ -337,6 +339,11 @@ func (p *postrenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, erro
return nil, err
}
obj.SetLabels(util.MergeMaps(obj.GetLabels(), p.labels))
// If the default namespace is not already created in the cluster, there
// would be an error since we do not create a ns if it doesn't exist.
if obj.GetNamespace() == "" && p.defaultNamespace != "" {
obj.SetNamespace(p.defaultNamespace)
}
b, err := obj.MarshalJSON()
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ spec:
configuration.'
type: object
x-kubernetes-preserve-unknown-fields: true
defaultnamespace:
type: string
format:
description: Format refers to the bundle type which is being passed
through the bundle deployment API.
Expand Down

0 comments on commit 9b3df66

Please sign in to comment.