Skip to content

Commit

Permalink
support matrix git generator (cnoe-io#338)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored Jul 10, 2024
1 parent ab5a003 commit 8099edd
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/controllers/custompackage/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ func (r *Reconciler) reconcileArgoCDAppSet(ctx context.Context, resource *v1alph
}
}
}
if g.Matrix != nil {
for j := range g.Matrix.Generators {
nestedGenerator := g.Matrix.Generators[j]
if nestedGenerator.Git != nil {
res, repo, gErr := r.reconcileArgoCDSource(ctx, resource, nestedGenerator.Git.RepoURL, appSet.GetName())
if gErr != nil {
return res, fmt.Errorf("reconciling git generator URL %s, %s: %w", nestedGenerator.Git.RepoURL, resource.Spec.ArgoCD.ApplicationFile, gErr)
}
if repo != nil {
nestedGenerator.Git.RepoURL = repo.Status.InternalGitRepositoryUrl
if repo.Status.InternalGitRepositoryUrl == "" {
notSyncedRepos += 1
}
}
}
}
}
}

gitGeneratorsSynced := notSyncedRepos == 0
Expand Down
71 changes: 71 additions & 0 deletions pkg/controllers/custompackage/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,70 @@ func TestReconcileCustomPkgAppSet(t *testing.T) {
},
},
},
{
input: v1alpha1.CustomPackage{
ObjectMeta: metav1.ObjectMeta{
Name: "test4",
Namespace: "test",
UID: "test4",
},
Spec: v1alpha1.CustomPackageSpec{
Replicate: true,
GitServerURL: "https://cnoe.io",
InternalGitServeURL: "http://internal.cnoe.io",
ArgoCD: v1alpha1.ArgoCDPackageSpec{
ApplicationFile: filepath.Join(cwd, "test/resources/customPackages/applicationSet/generator-matrix.yaml"),
Type: "ApplicationSet",
},
},
},
expectedGitRepo: v1alpha1.GitRepository{
ObjectMeta: metav1.ObjectMeta{
Name: localRepoName("generator-matrix", "test/resources/customPackages/applicationSet/test1"),
Namespace: "test",
},
Spec: v1alpha1.GitRepositorySpec{
Source: v1alpha1.GitRepositorySource{
Type: "local",
Path: filepath.Join(cwd, "test/resources/customPackages/applicationSet/test1"),
},
Provider: v1alpha1.Provider{
Name: v1alpha1.GitProviderGitea,
GitURL: "https://cnoe.io",
InternalGitURL: "http://internal.cnoe.io",
OrganizationName: v1alpha1.GiteaAdminUserName,
},
},
},
expectedApplicationSet: argov1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "generator-matrix",
Namespace: "argocd",
},
Spec: argov1alpha1.ApplicationSetSpec{
Generators: []argov1alpha1.ApplicationSetGenerator{
{
Matrix: &argov1alpha1.MatrixGenerator{
Generators: []argov1alpha1.ApplicationSetNestedGenerator{
{
Git: &argov1alpha1.GitGenerator{
RepoURL: "",
},
},
},
},
},
},
Template: argov1alpha1.ApplicationSetTemplate{
Spec: argov1alpha1.ApplicationSpec{
Source: &argov1alpha1.ApplicationSource{
RepoURL: "",
},
},
},
},
},
},
}

for i := range cases {
Expand Down Expand Up @@ -502,6 +566,13 @@ func TestReconcileCustomPkgAppSet(t *testing.T) {
if exg.Git != nil {
assert.Equal(t, exg.Git.RepoURL, appset.Spec.Generators[j].Git.RepoURL)
}
if exg.Matrix != nil {
for k := range exg.Matrix.Generators {
if exg.Matrix.Generators[k].Git != nil {
assert.Equal(t, exg.Matrix.Generators[k].Git.RepoURL, appset.Spec.Generators[j].Matrix.Generators[k].Git.RepoURL)
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: generator-matrix
namespace: argocd
spec:
goTemplate: true
goTemplateOptions:
- missingkey=error
generators:
- matrix:
generators:
- git:
repoURL: "cnoe://test1"
revision: HEAD
files:
- path: "**/config.yaml"
template:
metadata:
name: "{{ .name }}"
labels:
environment: "{{ .environment }}"
spec:
project: default
source:
repoURL: "cnoe://test1"
targetRevision: HEAD
path: "{{ .manifestPath }}/manifests"
destination:
server: https://kubernetes.default.svc
namespace: "{{ .namespace }}"
syncPolicy:
syncOptions:
- CreateNamespace=true

0 comments on commit 8099edd

Please sign in to comment.