Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
E2E tests should use application-controller serviceaccount, rather th…
Browse files Browse the repository at this point in the history
…an applicationset-controller serviceaccount (#434)
  • Loading branch information
jgwest committed Dec 30, 2021
1 parent b6024ae commit c280764
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 28 deletions.
83 changes: 58 additions & 25 deletions test/e2e/fixture/applicationsets/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,68 @@ func (a *Actions) CreateClusterSecret(secretName string, clusterName string, clu

fixtureClient := utils.GetE2EFixtureK8sClient()

bearerToken, err := GetServiceAccountBearerToken(fixtureClient.KubeClientset, utils.ArgoCDNamespace, "argocd-applicationset-controller")

// bearerToken
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: utils.ArgoCDNamespace,
Labels: map[string]string{
argocommon.LabelKeySecretType: argocommon.LabelValueSecretTypeCluster,
utils.TestingLabel: "true",
var serviceAccountName string

// Look for a service account matching '*application-controller*'
err := wait.Poll(500*time.Millisecond, 30*time.Second, func() (bool, error) {

serviceAccountList, err := fixtureClient.KubeClientset.CoreV1().ServiceAccounts(utils.ArgoCDNamespace).List(context.Background(), metav1.ListOptions{})
if err != nil {
fmt.Println("Unable to retrieve ServiceAccount list", err)
return false, nil
}

// If 'application-controller' service account is present, use that
for _, sa := range serviceAccountList.Items {
if strings.Contains(sa.Name, "application-controller") {
serviceAccountName = sa.Name
return true, nil
}
}

// Otherwise, use 'default'
for _, sa := range serviceAccountList.Items {
if sa.Name == "default" {
serviceAccountName = sa.Name
return true, nil
}
}

return false, nil
})

if err == nil {
var bearerToken string
bearerToken, err = GetServiceAccountBearerToken(fixtureClient.KubeClientset, utils.ArgoCDNamespace, serviceAccountName)

// bearerToken
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: utils.ArgoCDNamespace,
Labels: map[string]string{
argocommon.LabelKeySecretType: argocommon.LabelValueSecretTypeCluster,
utils.TestingLabel: "true",
},
},
},
Data: map[string][]byte{
"name": []byte(clusterName),
"server": []byte(clusterServer),
"config": []byte("{\"username\":\"foo\",\"password\":\"foo\"}"),
},
}
Data: map[string][]byte{
"name": []byte(clusterName),
"server": []byte(clusterServer),
"config": []byte("{\"username\":\"foo\",\"password\":\"foo\"}"),
},
}

// If the bearer token is available, use it rather than the fake username/password
if bearerToken != "" && err == nil {
secret.Data = map[string][]byte{
"name": []byte(clusterName),
"server": []byte(clusterServer),
"config": []byte("{\"bearerToken\":\"" + bearerToken + "\"}"),
// If the bearer token is available, use it rather than the fake username/password
if bearerToken != "" && err == nil {
secret.Data = map[string][]byte{
"name": []byte(clusterName),
"server": []byte(clusterServer),
"config": []byte("{\"bearerToken\":\"" + bearerToken + "\"}"),
}
}
}

_, err = fixtureClient.KubeClientset.CoreV1().Secrets(secret.Namespace).Create(context.Background(), secret, metav1.CreateOptions{})
_, err = fixtureClient.KubeClientset.CoreV1().Secrets(secret.Namespace).Create(context.Background(), secret, metav1.CreateOptions{})
}

a.describeAction = fmt.Sprintf("creating cluster Secret '%s'", secretName)
a.lastOutput, a.lastError = "", err
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/fixture/applicationsets/consequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/argoproj/pkg/errors"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// this implements the "then" part of given/when/then
Expand Down Expand Up @@ -75,7 +74,7 @@ func (c *Consequences) app(name string) *argov1alpha1.Application {
func (c *Consequences) apps() []argov1alpha1.Application {

fixtureClient := utils.GetE2EFixtureK8sClient()
list, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(utils.ArgoCDNamespace).List(context.Background(), v1.ListOptions{})
list, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(utils.ArgoCDNamespace).List(context.Background(), metav1.ListOptions{})
errors.CheckError(err)

if list == nil {
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/fixture/applicationsets/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ func getDiff(orig, new argov1alpha1.Application) (string, error) {

// getConditionDiff returns a string containing a comparison result of two ApplicationSetCondition (for test output/debug purposes)
func getConditionDiff(orig, new []v1alpha1.ApplicationSetCondition) (string, error) {
if len(orig) != len(new) {
return fmt.Sprintf("mismatch between condition sizes: %v %v", len(orig), len(new)), nil
}

var bytes []byte

for index, _ := range orig {
for index := range orig {
b, _, err := diff.CreateTwoWayMergePatch(orig[index], new[index], orig[index])
if err != nil {
return "", err
Expand Down

0 comments on commit c280764

Please sign in to comment.