Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure multi source spec is handled #124

Merged
merged 2 commits into from
Jan 5, 2024
Merged
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
9 changes: 7 additions & 2 deletions pkg/controllers/custompackage/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *Reconciler) reconcileCustomPackage(ctx context.Context, resource *v1alp
synced := true
if app.Spec.HasMultipleSources() {
for j := range app.Spec.Sources {
s := app.Spec.Sources[j]
s := &app.Spec.Sources[j]
res, repo, sErr := r.reconcileArgocdSource(ctx, resource, appName, resource.Spec.ArgoCD.ApplicationFile, s.RepoURL)
if sErr != nil {
return res, sErr
Expand Down Expand Up @@ -190,8 +190,13 @@ func (r *Reconciler) reconcileGitRepo(ctx context.Context, resource *v1alpha1.Cu
}
return nil
})
// it's possible for an application to specify the same directory multiple times in the spec.
// if there is a repository already created for this package, no further action is necessary.
if !errors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

return repo, err
}

return repo, err
return repo, nil
}

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
Expand Down
32 changes: 32 additions & 0 deletions pkg/controllers/custompackage/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ func TestReconcileCustomPkg(t *testing.T) {
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "test3",
Namespace: "test",
UID: "abc",
},
Spec: v1alpha1.CustomPackageSpec{
Replicate: true,
GitServerURL: "https://cnoe.io",
InternalGitServeURL: "http://internal.cnoe.io",
ArgoCD: v1alpha1.ArgoCDPackageSpec{
ApplicationFile: filepath.Join(cwd, "test/resources/customPackages/testDir/app2.yaml"),
Name: "my-app2",
Namespace: "argocd",
},
},
},
}

for _, n := range []string{"argocd", "test"} {
Expand Down Expand Up @@ -182,4 +199,19 @@ func TestReconcileCustomPkg(t *testing.T) {
t.Fatalf("expected %s arogapp : %v", n, err)
}
}

localApp2 := argov1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app2",
Namespace: "argocd",
},
}
err = c.Get(context.Background(), client.ObjectKeyFromObject(&localApp2), &localApp2)
if err != nil {
t.Fatalf("failed getting my-app2 %v", err)
}

if strings.HasPrefix(localApp2.Spec.Sources[0].RepoURL, "cnoe://") {
t.Fatalf("cnoe:// prefix should be removed")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app2
namespace: argocd
spec:
destination:
namespace: my-app2
server: "https://kubernetes.default.svc"
sources:
- repoURL: cnoe://app2
targetRevision: HEAD
path: "one"
- repoURL: cnoe://app2
targetRevision: HEAD
path: "two"
project: default
syncPolicy:
automated:
selfHeal: true
syncOptions:
- CreateNamespace=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: argocd
labels:
abc: ded
notused: remove-me
spec:
containers:
- image: alpine:3.18
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
name: busybox
restartPolicy: Always
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: argocd
labels:
abc: ded
notused: remove-me
spec:
containers:
- image: alpine:3.18
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
name: busybox
restartPolicy: Always