Skip to content

Commit

Permalink
fix: ArgoCD ApplicationSet customValues invalid patch (#25)
Browse files Browse the repository at this point in the history
Change-Id: Ib651bddf3baea2a3e3088d804764a9f7db7a2906
  • Loading branch information
zmotso committed Feb 2, 2024
1 parent 3fe5395 commit dd00410
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
k8s.io/client-go v0.26.11
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
sigs.k8s.io/controller-runtime v0.14.6
sigs.k8s.io/yaml v1.3.0
)

replace github.com/openshift/api => github.com/openshift/api v0.0.0-20231118005202-0f638a8a4705
Expand Down Expand Up @@ -202,5 +203,4 @@ require (
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
3 changes: 1 addition & 2 deletions pkg/argocd/argoapplicationset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ func generateTemplatePatch(pipeline, gitopsUrlPath, gitUser, gitHost string, ssh
path: deploy-templates
repoURL: %s/{{ .gitUrlPath }}
targetRevision: '{{ if eq .versionType "edp" }}build/{{ .imageTag }}{{ else }}{{ .imageTag }}{{ end }}'
{{- end }}
`
{{- end }}`

return fmt.Sprintf(template, gitopsRepoUrl, pipeline, sshURL)
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/argocd/argoapplicationset_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package argocd

import (
"bytes"
"context"
"encoding/json"
"testing"
"text/template"

argoApi "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/go-logr/logr"
Expand All @@ -14,6 +16,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/yaml"

cdPipeApi "github.com/epam/edp-cd-pipeline-operator/v2/api/v1"
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
Expand Down Expand Up @@ -1169,3 +1172,32 @@ func TestArgoApplicationSetManager_RemoveApplicationSetGenerators(t *testing.T)
})
}
}

func Test_generateTemplatePatch(t *testing.T) {
appset := generateTemplatePatch("pipe1", "/company/app1", "git", "github.com", 22)

Create := func(name, t string) *template.Template {
return template.Must(template.New(name).Option("missingkey=error").Parse(t))
}

tmpl := Create("appset", appset)

buf := &bytes.Buffer{}
err := tmpl.Execute(
buf,
map[string]any{
"customValues": true,
"versionType": "edp",
"imageTag": "NaN",
"imageRepository": "repo1",
"codebase": "app1",
"stage": "stage1",
"gitUrlPath": "/company/app1",
},
)
require.NoError(t, err)

y, err := yaml.YAMLToJSON(buf.Bytes())
require.NotNil(t, y)
require.NoError(t, err)
}

0 comments on commit dd00410

Please sign in to comment.