Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1alpha1/pattern_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type GitConfig struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=16
TargetRevision string `json:"targetRevision,omitempty"`

// Path within git repo where values files are located. Default: repository root
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=17
TargetPath string `json:"targetPath,omitempty"`

// Upstream git repo containing the pattern to deploy. Used when in-cluster fork to point to the upstream pattern repository.
// Takes precedence over TargetRepo
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=14,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldDependency:gitSpec.inClusterGitServer:true"}
Expand Down
12 changes: 5 additions & 7 deletions bundle/manifests/gitops.hybrid-cloud-patterns.io_patterns.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
creationTimestamp: null
name: patterns.gitops.hybrid-cloud-patterns.io
spec:
group: gitops.hybrid-cloud-patterns.io
Expand Down Expand Up @@ -107,6 +107,10 @@ spec:
description: (DEPRECATED) Branch, tag or commit in the upstream
git repository. Does not support short-sha's. Default to HEAD
type: string
targetPath:
description: 'Path within git repo where values files are located.
Default: repository root'
type: string
targetRepo:
description: Git repo containing the pattern to deploy. Must use
https/http or, for ssh, git@server:foo/bar.git
Expand Down Expand Up @@ -241,9 +245,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ spec:
description: (DEPRECATED) Branch, tag or commit in the upstream
git repository. Does not support short-sha's. Default to HEAD
type: string
targetPath:
description: 'Path within git repo where values files are located.
Default: repository root'
type: string
targetRepo:
description: Git repo containing the pattern to deploy. Must use
https/http or, for ssh, git@server:foo/bar.git
Expand Down
13 changes: 13 additions & 0 deletions internal/controller/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter {
Name: "global.targetRevision",
Value: p.Spec.GitConfig.TargetRevision,
},
{
Name: "global.targetPath",
Value: p.Spec.GitConfig.TargetPath,
},
{
Name: "global.hubClusterDomain",
Value: p.Status.AppClusterDomain,
Expand Down Expand Up @@ -457,6 +461,14 @@ func convertArgoHelmParametersToMap(params []argoapi.HelmParameter) map[string]a
}

func newApplicationValueFiles(p *api.Pattern, prefix string) []string {
basePath := p.Spec.GitConfig.TargetPath
if basePath != "" {
if prefix != "" {
prefix = fmt.Sprintf("%s/%s", prefix, basePath)
} else {
prefix = basePath
}
}
files := []string{
fmt.Sprintf("%s/values-global.yaml", prefix),
fmt.Sprintf("%s/values-%s.yaml", prefix, p.Spec.ClusterGroupName),
Expand Down Expand Up @@ -668,6 +680,7 @@ func newMultiSourceApplication(p *api.Pattern) *argoapi.Application {
valuesSource := &argoapi.ApplicationSource{
RepoURL: p.Spec.GitConfig.TargetRepo,
TargetRevision: p.Spec.GitConfig.TargetRevision,
Path: p.Spec.GitConfig.TargetPath,
Ref: "patternref",
}
sources = append(sources, *valuesSource)
Expand Down
49 changes: 49 additions & 0 deletions internal/controller/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ var _ = Describe("Argo Pattern", func() {
Expect(newMultiSourceApplication(pattern)).To(Equal(multiSourceArgoApp))
})
})
Context("multiSource with targetPath set", func() {
It("Returns an argo application with path in values source", func() {
format.MaxDepth = 100
format.MaxLength = 0
pattern.Spec.GitConfig.TargetPath = "envs/dev"
tmpTrue := true
pattern.Spec.MultiSourceConfig.Enabled = &tmpTrue
multiSourceArgoApp = argoApp.DeepCopy()
multiSourceArgoApp.Spec.Source = nil
multiSourceArgoApp.Spec.Sources = []argoapi.ApplicationSource{
{
RepoURL: pattern.Spec.GitConfig.TargetRepo,
TargetRevision: pattern.Spec.GitConfig.TargetRevision,
Path: "envs/dev",
Ref: "patternref",
},
{
RepoURL: pattern.Spec.MultiSourceConfig.HelmRepoUrl,
Chart: "clustergroup",
Path: "",
TargetRevision: pattern.Spec.MultiSourceConfig.ClusterGroupChartVersion,
Helm: commonApplicationSourceHelm(pattern, "$patternref"),
},
}
Expect(newMultiSourceApplication(pattern)).To(Equal(multiSourceArgoApp))
pattern.Spec.GitConfig.TargetPath = ""
})
})
})

Describe("Testing newApplicationValueFiles function", func() {
Expand Down Expand Up @@ -242,6 +270,23 @@ var _ = Describe("Argo Pattern", func() {
"myprefix/test2.yaml")))
})
})

Context("With targetPath set", func() {
BeforeEach(func() {
pattern.Spec.GitConfig.TargetPath = "envs/dev"
})
AfterEach(func() {
pattern.Spec.GitConfig.TargetPath = ""
})
It("Returns values with targetPath prefix", func() {
valueFiles := newApplicationValueFiles(pattern, "")
Expect(valueFiles).To(Equal(prefixArray(defaultValueFiles, "envs/dev")))
})
It("Returns values with combined prefix and targetPath", func() {
valueFiles := newApplicationValueFiles(pattern, "$patternref")
Expect(valueFiles).To(Equal(prefixArray(defaultValueFiles, "$patternref/envs/dev")))
})
})
})

Describe("Argo Helm Functions", func() {
Expand Down Expand Up @@ -367,6 +412,10 @@ var _ = Describe("Argo Pattern", func() {
Value: "main",
ForceString: false,
},
{
Name: "global.targetPath",
Value: "",
},
{
Name: "global.hubClusterDomain",
Value: "apps.hub-cluster.validatedpatterns.io",
Expand Down