diff --git a/cmd/gotk/create_helmrelease.go b/cmd/gotk/create_helmrelease.go index 562b6115..2b6a61f5 100644 --- a/cmd/gotk/create_helmrelease.go +++ b/cmd/gotk/create_helmrelease.go @@ -98,7 +98,7 @@ func init() { createHelmReleaseCmd.Flags().StringVar(&hrSource, "source", "", "source that contains the chart (/)") createHelmReleaseCmd.Flags().StringVar(&hrChart, "chart", "", "Helm chart name or path") createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts a semver range (ignored for charts from GitRepository sources)") - createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed") + createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed, supported formats '' and '/'") createHelmReleaseCmd.Flags().StringVar(&hrTargetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace") createHelmReleaseCmd.Flags().StringVar(&hrValuesFile, "values", "", "local path to the values.yaml file") createCmd.AddCommand(createHelmReleaseCmd) @@ -143,7 +143,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { }, Spec: helmv2.HelmReleaseSpec{ ReleaseName: hrName, - DependsOn: hrDependsOn, + DependsOn: utils.makeDependsOn(hrDependsOn), Interval: metav1.Duration{ Duration: interval, }, diff --git a/cmd/gotk/create_kustomization.go b/cmd/gotk/create_kustomization.go index 95364dbe..e5898692 100644 --- a/cmd/gotk/create_kustomization.go +++ b/cmd/gotk/create_kustomization.go @@ -94,7 +94,7 @@ func init() { createKsCmd.Flags().StringArrayVar(&ksHealthCheck, "health-check", nil, "workload to be included in the health assessment, in the format '/.'") createKsCmd.Flags().DurationVar(&ksHealthTimeout, "health-check-timeout", 2*time.Minute, "timeout of health checking operations") createKsCmd.Flags().StringVar(&ksValidation, "validation", "", "validate the manifests before applying them on the cluster, can be 'client' or 'server'") - createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "Kustomization that must be ready before this Kustomization can be applied") + createKsCmd.Flags().StringArrayVar(&ksDependsOn, "depends-on", nil, "Kustomization that must be ready before this Kustomization can be applied, supported formats '' and '/'") createKsCmd.Flags().StringVar(&ksSAName, "sa-name", "", "service account name") createKsCmd.Flags().StringVar(&ksSANamespace, "sa-namespace", "", "service account namespace") createKsCmd.Flags().StringVar(&ksDecryptionProvider, "decryption-provider", "", "enables secrets decryption, provider can be 'sops'") @@ -134,7 +134,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { Labels: ksLabels, }, Spec: kustomizev1.KustomizationSpec{ - DependsOn: ksDependsOn, + DependsOn: utils.makeDependsOn(hrDependsOn), Interval: metav1.Duration{ Duration: interval, }, diff --git a/cmd/gotk/utils.go b/cmd/gotk/utils.go index 16d0d6bf..e1e7c752 100644 --- a/cmd/gotk/utils.go +++ b/cmd/gotk/utils.go @@ -24,6 +24,7 @@ import ( "io" "os" "os/exec" + "strings" "text/template" corev1 "k8s.io/api/core/v1" @@ -34,6 +35,7 @@ import ( helmv2 "github.com/fluxcd/helm-controller/api/v2alpha1" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1" + "github.com/fluxcd/pkg/runtime/dependency" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" ) @@ -177,3 +179,23 @@ func (*Utils) containsItemString(s []string, e string) bool { } return false } + +func (*Utils) makeDependsOn(deps []string) []dependency.CrossNamespaceDependencyReference { + refs := []dependency.CrossNamespaceDependencyReference{} + for _, dep := range deps { + parts := strings.Split(dep, "/") + depNamespace := "" + depName := "" + if len(parts) > 1 { + depNamespace = parts[0] + depName = parts[1] + } else { + depName = parts[0] + } + refs = append(refs, dependency.CrossNamespaceDependencyReference{ + Namespace: depNamespace, + Name: depName, + }) + } + return refs +} diff --git a/docs/cmd/gotk_create_helmrelease.md b/docs/cmd/gotk_create_helmrelease.md index e1d254f4..09e9803a 100644 --- a/docs/cmd/gotk_create_helmrelease.md +++ b/docs/cmd/gotk_create_helmrelease.md @@ -58,7 +58,7 @@ gotk create helmrelease [name] [flags] ``` --chart string Helm chart name or path --chart-version string Helm chart version, accepts a semver range (ignored for charts from GitRepository sources) - --depends-on stringArray HelmReleases that must be ready before this release can be installed + --depends-on stringArray HelmReleases that must be ready before this release can be installed, supported formats '' and '/' -h, --help help for helmrelease --release-name string name used for the Helm release, defaults to a composition of '[-]' --source string source that contains the chart (/) diff --git a/docs/cmd/gotk_create_kustomization.md b/docs/cmd/gotk_create_kustomization.md index 3f0ad7ca..436cc329 100644 --- a/docs/cmd/gotk_create_kustomization.md +++ b/docs/cmd/gotk_create_kustomization.md @@ -50,7 +50,7 @@ gotk create kustomization [name] [flags] ``` --decryption-provider string enables secrets decryption, provider can be 'sops' --decryption-secret string set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption - --depends-on stringArray Kustomization that must be ready before this Kustomization can be applied + --depends-on stringArray Kustomization that must be ready before this Kustomization can be applied, supported formats '' and '/' --health-check stringArray workload to be included in the health assessment, in the format '/.' --health-check-timeout duration timeout of health checking operations (default 2m0s) -h, --help help for kustomization