Skip to content

Commit

Permalink
changes based on review comments
Browse files Browse the repository at this point in the history
Signed-off-by: John Pitman <jpitman@redhat.com>
  • Loading branch information
jopit authored and jgwest committed Oct 12, 2023
1 parent 770525a commit 38c6f30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 97 deletions.
10 changes: 5 additions & 5 deletions cluster-agent/utils/argocd_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func SetupArgoCD(ctx context.Context, apiHost string, argoCDNamespace string, k8
}
logutil.LogAPIResourceChangeEvent(serviceAccount.Namespace, serviceAccount.Name, serviceAccount, logutil.ResourceCreated, log)
} else {
// Some other error occured
// Some other error occurred
return fmt.Errorf("error on Get service account: %w", err)
}

Expand Down Expand Up @@ -365,7 +365,7 @@ func SetupArgoCD(ctx context.Context, apiHost string, argoCDNamespace string, k8
}
logutil.LogAPIResourceChangeEvent(secret.Namespace, secret.Name, secret, logutil.ResourceCreated, log)
} else {
// Some other error occured
// Some other error occurred
return fmt.Errorf("error on Get secret: %w", err)
}

Expand Down Expand Up @@ -401,7 +401,7 @@ func SetupArgoCD(ctx context.Context, apiHost string, argoCDNamespace string, k8
}
logutil.LogAPIResourceChangeEvent(clusterRole.Namespace, clusterRole.Name, clusterRole, logutil.ResourceCreated, log)
} else {
// Some other error occured
// Some other error occurred
return fmt.Errorf("error on Get cluster role: %w", err)
}

Expand Down Expand Up @@ -441,7 +441,7 @@ func SetupArgoCD(ctx context.Context, apiHost string, argoCDNamespace string, k8
}
logutil.LogAPIResourceChangeEvent(clusterRoleBinding.Namespace, clusterRoleBinding.Name, clusterRoleBinding, logutil.ResourceCreated, log)
} else {
// Some other error occured
// Some other error occurred
return fmt.Errorf("error on Get cluster role binding: %w", err)
}

Expand Down Expand Up @@ -532,7 +532,7 @@ func SetupArgoCD(ctx context.Context, apiHost string, argoCDNamespace string, k8
}
logutil.LogAPIResourceChangeEvent(clusterSecret.Namespace, clusterSecret.Name, clusterSecret, logutil.ResourceCreated, log)
} else {
// Some other error occured
// Some other error occurred
return fmt.Errorf("error on Get cluster secret:: %w", err)
}

Expand Down
12 changes: 7 additions & 5 deletions cluster-agent/utils/argocd_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ var _ = Describe("Test SetupArgoCD()", func() {

When("SetupArgoCD() is called", func() {
It("creates the required service account, secret, cluster role, rolebinding and cluster secret", func() {
By("starting a goroutine to add a token to the secret created by SetupArogCD()")
By("starting a goroutine to add a token to the secret created by SetupArgoCD()")
startSecretUpdater(ctx, k8sClient)

By("calling SetupArgoCD()")
err := SetupArgoCD(ctx, apiHost, namespace.Name, k8sClient, logger)
Expect(err).ToNot(HaveOccurred())

By("ensuring the sevice account was created")
By("ensuring the service account was created")
serviceAccount := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: ArgoCDManagerServiceAccountName,
Expand Down Expand Up @@ -149,10 +149,10 @@ var _ = Describe("Test SetupArgoCD()", func() {

When("SetupArgoCD() is called and the resources already exist", func() {
It("creates the required service account, secret, cluster role, rolebinding and cluster secret", func() {
By("starting a goroutine to add a token to the secret created by SetupArogCD()")
By("starting a goroutine to add a token to the secret created by SetupArgoCD()")
startSecretUpdater(ctx, k8sClient)

By("creating the sevice account")
By("creating the service account")
serviceAccount := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: ArgoCDManagerServiceAccountName,
Expand Down Expand Up @@ -209,6 +209,8 @@ var _ = Describe("Test SetupArgoCD()", func() {
},
},
}
err = k8sClient.Create(ctx, clusterRole)
Expect(err).ToNot(HaveOccurred())

By("creating the cluster role binding")
clusterRoleBinding := &rbac.ClusterRoleBinding{
Expand Down Expand Up @@ -248,7 +250,7 @@ var _ = Describe("Test SetupArgoCD()", func() {
err = SetupArgoCD(ctx, apiHost, namespace.Name, k8sClient, logger)
Expect(err).ToNot(HaveOccurred())

By("ensuring the sevice account was updated")
By("ensuring the service account was updated")
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(serviceAccount), serviceAccount)
Expect(err).ToNot(HaveOccurred())
Expect(serviceAccount.Secrets).To(BeEmpty())
Expand Down
98 changes: 11 additions & 87 deletions tests-e2e/argocd/argocd_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ var _ = Describe("Standalone ArgoCD instance E2E tests", func() {

})

It("should create ArgoCD resource and application, wait for it to be installed and synced", func() {

testStandaloneArgoCD := func(testUpdate bool) {
By("creating ArgoCD resource")
ctx := context.Background()
log := log.FromContext(ctx)
Expand All @@ -71,6 +70,12 @@ var _ = Describe("Standalone ArgoCD instance E2E tests", func() {
err = argocdv1.SetupArgoCD(ctx, apiHost, argocdNamespace, k8sClient, log)
Expect(err).ToNot(HaveOccurred())

if testUpdate {
By("ensuring the SetupArgoCD function works even if resources already exist in kube-system namespace")
err = argocdv1.SetupArgoCD(ctx, apiHost, argocdNamespace, k8sClient, log)
Expect(err).ToNot(HaveOccurred())
}

destinationNamespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: fixture.NewArgoCDInstanceDestNamespace,
Expand Down Expand Up @@ -124,95 +129,14 @@ var _ = Describe("Standalone ArgoCD instance E2E tests", func() {
appFixture.HaveSyncStatusCode(appv1.SyncStatusCodeSynced),
appFixture.HaveHealthStatusCode(health.HealthStatusHealthy),
))
}

It("should create ArgoCD resource and application, wait for it to be installed and synced", func() {
testStandaloneArgoCD(false)
})

It("should update existing ArgoCD resources, create an application, wait for it to be installed and synced", func() {

By("creating ArgoCD resource")
ctx := context.Background()
log := log.FromContext(ctx)

config, err := fixture.GetSystemKubeConfig()
Expect(err).ToNot(HaveOccurred())
apiHost := config.Host

k8sClient, err := fixture.GetKubeClient(config)
Expect(err).ToNot(HaveOccurred())

err = argocdv1.ReconcileNamespaceScopedArgoCD(ctx, argocdCRName, argocdNamespace, k8sClient, log)
Expect(err).ToNot(HaveOccurred())

By("ensuring ArgoCD service resource exists")
argocdInstance := &apps.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: argocdCRName + "-server", Namespace: argocdNamespace},
}

Eventually(argocdInstance, "60s", "5s").Should(k8s.ExistByName(k8sClient))
Expect(err).ToNot(HaveOccurred())

By("ensuring ArgoCD resource exists in kube-system namespace")
err = argocdv1.SetupArgoCD(ctx, apiHost, argocdNamespace, k8sClient, log)
Expect(err).ToNot(HaveOccurred())

By("ensuring the SetupArgoCD function works even if resources already exist in kube-system namespace")
err = argocdv1.SetupArgoCD(ctx, apiHost, argocdNamespace, k8sClient, log)
Expect(err).ToNot(HaveOccurred())

destinationNamespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: fixture.NewArgoCDInstanceDestNamespace,
},
}

if fixture.EnableNamespaceBackedArgoCD {
destinationNamespace.Labels = map[string]string{
"argocd.argoproj.io/managed-by": argocdNamespace,
}
}

err = k8sClient.Create(ctx, destinationNamespace)
Expect(err).ToNot(HaveOccurred())

By("creating ArgoCD application")
app := appv1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "argo-app-6",
Namespace: argocdNamespace,
},
Spec: appv1.ApplicationSpec{
Source: &appv1.ApplicationSource{
RepoURL: "https://github.com/redhat-appstudio/managed-gitops",
Path: "resources/test-data/sample-gitops-repository/environments/overlays/dev",
TargetRevision: "HEAD",
},
Destination: appv1.ApplicationDestination{
Name: argocdv1.ClusterSecretName,
Namespace: destinationNamespace.Name,
},
},
}

err = k8s.Create(&app, k8sClient)
Expect(err).ToNot(HaveOccurred())

cs := argocdv1.NewCredentialService(nil, true)
Expect(cs).ToNot(BeNil())

By("calling AppSync and waiting for it to return with no error")
Eventually(func() bool {
GinkgoWriter.Println("Attempting to sync application: ", app.Name)
err := argocdv1.AppSync(context.Background(), app.Name, "", app.Namespace, k8sClient, cs, true)
GinkgoWriter.Println("- AppSync result: ", err)
return err == nil
}).WithTimeout(time.Minute * 4).WithPolling(time.Second * 1).Should(BeTrue())

Eventually(app, "2m", "1s").Should(
SatisfyAll(
appFixture.HaveSyncStatusCode(appv1.SyncStatusCodeSynced),
appFixture.HaveHealthStatusCode(health.HealthStatusHealthy),
))

testStandaloneArgoCD(true)
})
})
})

0 comments on commit 38c6f30

Please sign in to comment.