Skip to content

Commit

Permalink
clm: add --create-namespace to apply
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarbian-sap committed Dec 10, 2024
1 parent 88c5286 commit 8de77ce
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions clm/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (

"github.com/spf13/cobra"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apitypes "k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"

"github.com/sap/component-operator-runtime/clm/internal/backoff"
Expand All @@ -26,8 +29,9 @@ import (
const applyUsage = `Apply component manifests to Kubernetes cluster`

type applyOptions struct {
valuesSources []string
timeout time.Duration
valuesSources []string
createNamespace bool
timeout time.Duration
}

func newApplyCmd() *cobra.Command {
Expand Down Expand Up @@ -60,6 +64,14 @@ func newApplyCmd() *cobra.Command {

ownerId := fullName + "/" + namespace + "/" + name

if err := clnt.Get(context.TODO(), apitypes.NamespacedName{Name: namespace}, &corev1.Namespace{}); apierrors.IsNotFound(err) && options.createNamespace {
if err := clnt.Create(context.TODO(), &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}); err != nil {
return err
}
} else if err != nil {
return err
}

release, err := releaseClient.Get(context.TODO(), namespace, name)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -145,6 +157,7 @@ func newApplyCmd() *cobra.Command {

flags := cmd.Flags()
flags.StringArrayVarP(&options.valuesSources, "values", "f", nil, "Path to values file in yaml format (can be repeated, values will be merged in order of appearance)")
flags.BoolVar(&options.createNamespace, "create-namespace", false, "Create release namespace if not existing")
flags.DurationVar(&options.timeout, "timeout", 0, "Time to wait for the operation to complete (default is to wait forever)")

return cmd
Expand Down

0 comments on commit 8de77ce

Please sign in to comment.