diff --git a/api/v1alpha1/pattern_types.go b/api/v1alpha1/pattern_types.go index 907733f72..aac9d5b65 100644 --- a/api/v1alpha1/pattern_types.go +++ b/api/v1alpha1/pattern_types.go @@ -151,7 +151,6 @@ type MultiSourceConfig struct { // The git reference when deploying the clustergroup helm chart directly from a git repo // Defaults to 'main'. (Only used when developing the clustergroup helm chart) // +operator-sdk:csv:customresourcedefinitions:type=spec,order=24,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldDependency:multiSourceConfig.enabled:true","urn:alm:descriptor:com.tectonic.ui:advanced"} - // +kubebuilder:default:="main" ClusterGroupChartGitRevision string `json:"clusterGroupChartGitRevision,omitempty"` } diff --git a/config/samples/gitops_v1alpha1_pattern.yaml b/config/samples/gitops_v1alpha1_pattern.yaml index 6f8f0009c..1dfb173c8 100644 --- a/config/samples/gitops_v1alpha1_pattern.yaml +++ b/config/samples/gitops_v1alpha1_pattern.yaml @@ -7,5 +7,6 @@ spec: gitSpec: targetRepo: "https://github.com/validatedpatterns/multicloud-gitops" targetRevision: "main" - multiSourceSupport: false + multiSourceConfig: + enabled: true diff --git a/controllers/argo.go b/controllers/argo.go index c37672985..479ccadc2 100644 --- a/controllers/argo.go +++ b/controllers/argo.go @@ -405,16 +405,16 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter { Name: "global.multiSourceRepoUrl", Value: p.Spec.MultiSourceConfig.HelmRepoUrl, }, - { - Name: "global.multiSourceTargetRevision", - Value: p.Spec.MultiSourceConfig.ClusterGroupChartVersion, - }, + { Name: "global.experimentalCapabilities", Value: p.Spec.ExperimentalCapabilities, }, } - + parameters = append(parameters, argoapi.HelmParameter{ + Name: "global.multiSourceTargetRevision", + Value: getClusterGroupChartVersion(p), + }) for _, extra := range p.Spec.ExtraParameters { if !updateHelmParameter(extra, parameters) { log.Printf("Parameter %q = %q added", extra.Name, extra.Value) @@ -675,10 +675,12 @@ func newMultiSourceApplication(p *api.Pattern) *argoapi.Application { // If we do not specify a custom repo for the clustergroup chart, let's use the default // clustergroup chart from the helm repo url. Otherwise use the git repo that was given if p.Spec.MultiSourceConfig.ClusterGroupGitRepoUrl == "" { + // If the user set the clustergroupchart version use that + baseSource = &argoapi.ApplicationSource{ RepoURL: p.Spec.MultiSourceConfig.HelmRepoUrl, Chart: "clustergroup", - TargetRevision: p.Spec.MultiSourceConfig.ClusterGroupChartVersion, + TargetRevision: getClusterGroupChartVersion(p), Helm: commonApplicationSourceHelm(p, "$patternref"), } } else { @@ -696,6 +698,20 @@ func newMultiSourceApplication(p *api.Pattern) *argoapi.Application { return newArgoOperatorApplication(p, spec) } +func getClusterGroupChartVersion(p *api.Pattern) string { + var clusterGroupChartVersion string + if p.Spec.MultiSourceConfig.ClusterGroupChartVersion != "" { + clusterGroupChartVersion = p.Spec.MultiSourceConfig.ClusterGroupChartVersion + } else { // if the user has not specified anything, then let's detect if common is slimmed + if IsCommonSlimmed(p.Status.LocalCheckoutPath) { + clusterGroupChartVersion = "0.9.*" + } else { + clusterGroupChartVersion = "0.8.*" + } + } + return clusterGroupChartVersion +} + func newArgoApplication(p *api.Pattern) *argoapi.Application { // -- ArgoCD Application var targetApp *argoapi.Application diff --git a/controllers/argo_test.go b/controllers/argo_test.go index c8fcb8501..cac402840 100644 --- a/controllers/argo_test.go +++ b/controllers/argo_test.go @@ -417,13 +417,13 @@ var _ = Describe("Argo Pattern", func() { ForceString: false, }, argoapi.HelmParameter{ - Name: "global.multiSourceTargetRevision", - Value: "0.0.*", + Name: "global.experimentalCapabilities", + Value: "", ForceString: false, }, argoapi.HelmParameter{ - Name: "global.experimentalCapabilities", - Value: "", + Name: "global.multiSourceTargetRevision", + Value: "0.0.*", ForceString: false, }, ))) @@ -451,13 +451,13 @@ var _ = Describe("Argo Pattern", func() { ForceString: false, }, argoapi.HelmParameter{ - Name: "global.multiSourceTargetRevision", - Value: "0.0.*", + Name: "global.experimentalCapabilities", + Value: "", ForceString: false, }, argoapi.HelmParameter{ - Name: "global.experimentalCapabilities", - Value: "", + Name: "global.multiSourceTargetRevision", + Value: "0.0.*", ForceString: false, }, argoapi.HelmParameter{ @@ -482,14 +482,15 @@ var _ = Describe("Argo Pattern", func() { Name: "global.multiSourceRepoUrl", Value: "https://charts.validatedpatterns.io/", }, - argoapi.HelmParameter{ - Name: "global.multiSourceTargetRevision", - Value: "0.0.*", - }, + argoapi.HelmParameter{ Name: "global.experimentalCapabilities", Value: "", ForceString: false, + }, + argoapi.HelmParameter{ + Name: "global.multiSourceTargetRevision", + Value: "0.0.*", }))) }) }) diff --git a/controllers/pattern_controller.go b/controllers/pattern_controller.go index 7870b0c79..9b9593262 100644 --- a/controllers/pattern_controller.go +++ b/controllers/pattern_controller.go @@ -513,9 +513,6 @@ func (r *PatternReconciler) applyDefaults(input *api.Pattern) (*api.Pattern, err if output.Spec.MultiSourceConfig.HelmRepoUrl == "" { output.Spec.MultiSourceConfig.HelmRepoUrl = "https://charts.validatedpatterns.io/" } - if output.Spec.MultiSourceConfig.ClusterGroupChartVersion == "" { - output.Spec.MultiSourceConfig.ClusterGroupChartVersion = "0.8.*" - } // interval cannot be less than 180 seconds to avoid drowning the API server in requests // value of -1 effectively disables the watch for this pattern. diff --git a/controllers/utils.go b/controllers/utils.go index 50f7fccbf..cd0f4d6f7 100644 --- a/controllers/utils.go +++ b/controllers/utils.go @@ -26,6 +26,7 @@ import ( "net/url" "os" "path" + "path/filepath" "strings" "crypto/rand" @@ -394,3 +395,12 @@ func GenerateRandomPassword(length int, randRead func([]byte) (int, error)) (str func DefaultRandRead(b []byte) (int, error) { return rand.Read(b) } + +// This function returns true if common is the slimmed version and false if it is not +func IsCommonSlimmed(patternPath string) bool { + fullPath := filepath.Join(patternPath, "common", "operator-install") + if _, err := os.Stat(fullPath); err == nil { + return false + } + return true +}