Skip to content

Commit

Permalink
fix(appset): Fix name conflict in appset controller (argoproj#16207) (a…
Browse files Browse the repository at this point in the history
…rgoproj#16222)

* fix(16207): Fix name conflict in appset controller

Signed-off-by: gmuselli <geoffrey.muselli@gmail.com>

* fix(16207): e2e

Signed-off-by: gmuselli <geoffrey.muselli@gmail.com>

* Update test/e2e/fixture/applicationsets/utils/fixture.go

Signed-off-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>

---------

Signed-off-by: gmuselli <geoffrey.muselli@gmail.com>
Signed-off-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
  • Loading branch information
2 people authored and vladfr committed Dec 13, 2023
1 parent 00b3cf1 commit 45b03af
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ jobs:
ARGOCD_E2E_K3S: "true"
ARGOCD_IN_CI: "true"
ARGOCD_E2E_APISERVER_PORT: "8088"
ARGOCD_APPLICATION_NAMESPACES: "argocd-e2e-external"
ARGOCD_APPLICATION_NAMESPACES: "argocd-e2e-external,argocd-e2e-external-2"
ARGOCD_SERVER: "127.0.0.1:8088"
GITHUB_TOKEN: ${{ secrets.E2E_TEST_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
GITLAB_TOKEN: ${{ secrets.E2E_TEST_GITLAB_TOKEN }}
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ start-e2e: test-tools-image
start-e2e-local: mod-vendor-local dep-ui-local cli-local
kubectl create ns argocd-e2e || true
kubectl create ns argocd-e2e-external || true
kubectl create ns argocd-e2e-external-2 || true
kubectl config set-context --current --namespace=argocd-e2e
kustomize build test/manifests/base | kubectl apply -f -
kubectl apply -f https://raw.githubusercontent.com/open-cluster-management/api/a6845f2ebcb186ec26b832f60c988537a58f3859/cluster/v1alpha1/0000_04_clusters.open-cluster-management.io_placementdecisions.crd.yaml
Expand All @@ -458,8 +459,8 @@ start-e2e-local: mod-vendor-local dep-ui-local cli-local
ARGOCD_ZJWT_FEATURE_FLAG=always \
ARGOCD_IN_CI=$(ARGOCD_IN_CI) \
BIN_MODE=$(ARGOCD_BIN_MODE) \
ARGOCD_APPLICATION_NAMESPACES=argocd-e2e-external \
ARGOCD_APPLICATIONSET_CONTROLLER_NAMESPACES=argocd-e2e-external \
ARGOCD_APPLICATION_NAMESPACES=argocd-e2e-external,argocd-e2e-external-2 \
ARGOCD_APPLICATIONSET_CONTROLLER_NAMESPACES=argocd-e2e-external,argocd-e2e-external-2 \
ARGOCD_APPLICATIONSET_CONTROLLER_ALLOWED_SCM_PROVIDERS=http://127.0.0.1:8341,http://127.0.0.1:8342,http://127.0.0.1:8343,http://127.0.0.1:8344 \
ARGOCD_E2E_TEST=true \
goreman -f $(ARGOCD_PROCFILE) start ${ARGOCD_START}
Expand Down
2 changes: 1 addition & 1 deletion applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func (r *ApplicationSetReconciler) createInCluster(ctx context.Context, logCtx *
func (r *ApplicationSetReconciler) getCurrentApplications(_ context.Context, applicationSet argov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error) {
// TODO: Should this use the context param?
var current argov1alpha1.ApplicationList
err := r.Client.List(context.Background(), &current, client.MatchingFields{".metadata.controller": applicationSet.Name})
err := r.Client.List(context.Background(), &current, client.MatchingFields{".metadata.controller": applicationSet.Name}, client.InNamespace(applicationSet.Namespace))

if err != nil {
return nil, fmt.Errorf("error retrieving applications: %w", err)
Expand Down
195 changes: 191 additions & 4 deletions test/e2e/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ var (

func TestSimpleListGeneratorExternalNamespace(t *testing.T) {

var externalNamespace = string(utils.ArgoCDExternalNamespace)

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: utils.ArgoCDExternalNamespace,
Namespace: externalNamespace,
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand All @@ -82,10 +84,10 @@ func TestSimpleListGeneratorExternalNamespace(t *testing.T) {
Given(t).
// Create a ListGenerator-based ApplicationSet
When().
SwitchToExternalNamespace().
CreateNamespace(utils.ArgoCDExternalNamespace).Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
CreateNamespace(externalNamespace).Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
Name: "simple-list-generator-external",
Namespace: utils.ArgoCDExternalNamespace,
Namespace: externalNamespace,
},
Spec: v1alpha1.ApplicationSetSpec{
GoTemplate: true,
Expand Down Expand Up @@ -151,6 +153,191 @@ func TestSimpleListGeneratorExternalNamespace(t *testing.T) {

}

func TestSimpleListGeneratorExternalNamespaceNoConflict(t *testing.T) {

var externalNamespace = string(utils.ArgoCDExternalNamespace)
var externalNamespace2 = string(utils.ArgoCDExternalNamespace2)

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: externalNamespace,
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Project: "default",
Source: &argov1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
TargetRevision: "HEAD",
Path: "guestbook",
},
Destination: argov1alpha1.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "guestbook",
},
},
}

expectedAppExternalNamespace2 := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: externalNamespace2,
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Project: "default",
Source: &argov1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
TargetRevision: "HEAD",
Path: "guestbook",
},
Destination: argov1alpha1.ApplicationDestination{
Server: "https://kubernetes.default.svc",
Namespace: "guestbook",
},
},
}

var expectedAppNewNamespace *argov1alpha1.Application
var expectedAppNewMetadata *argov1alpha1.Application

Given(t).
// Create a ListGenerator-based ApplicationSet
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace2).
CreateNamespace(externalNamespace2).Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
Name: "simple-list-generator-external",
Namespace: externalNamespace2,
},
Spec: v1alpha1.ApplicationSetSpec{
GoTemplate: true,
Template: v1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{Name: "{{.cluster}}-guestbook"},
Spec: argov1alpha1.ApplicationSpec{
Project: "default",
Source: &argov1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
TargetRevision: "HEAD",
Path: "guestbook",
},
Destination: argov1alpha1.ApplicationDestination{
Server: "{{.url}}",
Namespace: "guestbook",
},
},
},
Generators: []v1alpha1.ApplicationSetGenerator{
{
List: &v1alpha1.ListGenerator{
Elements: []apiextensionsv1.JSON{{
Raw: []byte(`{"cluster": "my-cluster","url": "https://kubernetes.default.svc"}`),
}},
},
},
},
},
}).Then().Expect(ApplicationsExist([]argov1alpha1.Application{expectedAppExternalNamespace2})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
CreateNamespace(externalNamespace).Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
Name: "simple-list-generator-external",
Namespace: externalNamespace,
},
Spec: v1alpha1.ApplicationSetSpec{
GoTemplate: true,
Template: v1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{Name: "{{.cluster}}-guestbook"},
Spec: argov1alpha1.ApplicationSpec{
Project: "default",
Source: &argov1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
TargetRevision: "HEAD",
Path: "guestbook",
},
Destination: argov1alpha1.ApplicationDestination{
Server: "{{.url}}",
Namespace: "guestbook",
},
},
},
Generators: []v1alpha1.ApplicationSetGenerator{
{
List: &v1alpha1.ListGenerator{
Elements: []apiextensionsv1.JSON{{
Raw: []byte(`{"cluster": "my-cluster","url": "https://kubernetes.default.svc"}`),
}},
},
},
},
},
}).Then().Expect(ApplicationsExist([]argov1alpha1.Application{expectedApp})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace2).
Then().
Expect(ApplicationsExist([]argov1alpha1.Application{expectedAppExternalNamespace2})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
Then().
// Update the ApplicationSet template namespace, and verify it updates the Applications
When().
And(func() {
expectedAppNewNamespace = expectedApp.DeepCopy()
expectedAppNewNamespace.Spec.Destination.Namespace = "guestbook2"
}).
Update(func(appset *v1alpha1.ApplicationSet) {
appset.Spec.Template.Spec.Destination.Namespace = "guestbook2"
}).Then().Expect(ApplicationsExist([]argov1alpha1.Application{*expectedAppNewNamespace})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace2).
Then().
Expect(ApplicationsExist([]argov1alpha1.Application{expectedAppExternalNamespace2})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
Then().
// Update the metadata fields in the appset template, and make sure it propagates to the apps
When().
And(func() {
expectedAppNewMetadata = expectedAppNewNamespace.DeepCopy()
expectedAppNewMetadata.ObjectMeta.Annotations = map[string]string{"annotation-key": "annotation-value"}
expectedAppNewMetadata.ObjectMeta.Labels = map[string]string{
"label-key": "label-value",
}
}).
Update(func(appset *v1alpha1.ApplicationSet) {
appset.Spec.Template.Annotations = map[string]string{"annotation-key": "annotation-value"}
appset.Spec.Template.Labels = map[string]string{
"label-key": "label-value",
}
}).Then().Expect(ApplicationsExist([]argov1alpha1.Application{*expectedAppNewMetadata})).

// verify the ApplicationSet status conditions were set correctly
Expect(ApplicationSetHasConditions("simple-list-generator-external", ExpectedConditions)).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace2).
Then().
Expect(ApplicationsExist([]argov1alpha1.Application{expectedAppExternalNamespace2})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
Then().
// Delete the ApplicationSet, and verify it deletes the Applications
When().
Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{*expectedAppNewMetadata})).
When().
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace2).
Then().
Expect(ApplicationsExist([]argov1alpha1.Application{expectedAppExternalNamespace2})).
When().
Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{expectedAppExternalNamespace2}))
}

func TestSimpleListGenerator(t *testing.T) {

expectedApp := argov1alpha1.Application{
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/cluster_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import (

func TestSimpleClusterGeneratorExternalNamespace(t *testing.T) {

var externalNamespace = string(utils.ArgoCDExternalNamespace)

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1-guestbook",
Namespace: utils.ArgoCDExternalNamespace,
Namespace: externalNamespace,
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand All @@ -49,8 +51,8 @@ func TestSimpleClusterGeneratorExternalNamespace(t *testing.T) {
// Create a ClusterGenerator-based ApplicationSet
When().
CreateClusterSecret("my-secret", "cluster1", "https://kubernetes.default.svc").
SwitchToExternalNamespace().
CreateNamespace(utils.ArgoCDExternalNamespace).
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
CreateNamespace(externalNamespace).
Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
Name: "simple-cluster-generator",
},
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/clusterdecisiongenerator_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ var tenSec = int64(10)

func TestSimpleClusterDecisionResourceGeneratorExternalNamespace(t *testing.T) {

var externalNamespace = string(utils.ArgoCDExternalNamespace)

expectedApp := argov1alpha1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1-guestbook",
Namespace: utils.ArgoCDExternalNamespace,
Namespace: externalNamespace,
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -61,8 +63,8 @@ func TestSimpleClusterDecisionResourceGeneratorExternalNamespace(t *testing.T) {
CreatePlacementDecisionConfigMap("my-configmap").
CreatePlacementDecision("my-placementdecision").
StatusUpdatePlacementDecision("my-placementdecision", clusterList).
CreateNamespace(utils.ArgoCDExternalNamespace).
SwitchToExternalNamespace().
CreateNamespace(externalNamespace).
SwitchToExternalNamespace(utils.ArgoCDExternalNamespace).
Create(v1alpha1.ApplicationSet{ObjectMeta: metav1.ObjectMeta{
Name: "simple-cluster-generator",
},
Expand Down
Loading

0 comments on commit 45b03af

Please sign in to comment.