Skip to content

Commit

Permalink
Merge pull request #300 from mbaldessari/automatic-common-version-det…
Browse files Browse the repository at this point in the history
…ection

automatic common version detection
  • Loading branch information
mbaldessari authored Oct 28, 2024
2 parents 7f695f5 + 4cf76f0 commit 93aa75e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
1 change: 0 additions & 1 deletion api/v1alpha1/pattern_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
3 changes: 2 additions & 1 deletion config/samples/gitops_v1alpha1_pattern.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ spec:
gitSpec:
targetRepo: "https://github.com/validatedpatterns/multicloud-gitops"
targetRevision: "main"
multiSourceSupport: false
multiSourceConfig:
enabled: true

28 changes: 22 additions & 6 deletions controllers/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
25 changes: 13 additions & 12 deletions controllers/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)))
Expand Down Expand Up @@ -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{
Expand All @@ -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.*",
})))
})
})
Expand Down
3 changes: 0 additions & 3 deletions controllers/pattern_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strings"

"crypto/rand"
Expand Down Expand Up @@ -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
}

0 comments on commit 93aa75e

Please sign in to comment.