Skip to content

Commit

Permalink
tests: Do not error if ServiceAccount exists
Browse files Browse the repository at this point in the history
In the integration test suite, we should not raise an error if the
desired ServiceAccount already exists. The `pipeline` ServiceAccount in
particular can exist in some Tekton distributions (ex: OpenShift
Pipelines).
  • Loading branch information
adambkaplan committed Nov 6, 2020
1 parent bf68646 commit fa89454
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/integration/utils/service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ package utils
import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// This class is intended to host all CRUD calls for testing secrets primitive resources

// CreateSAFromName generate a vanilla service-account
// with the provided name
// CreateSAFromName creates a simple ServiceAccount with the provided name if it does not exist.
func (t *TestBuild) CreateSAFromName(saName string) error {
client := t.Clientset.CoreV1().ServiceAccounts(t.Namespace)
_, err := client.Create(&corev1.ServiceAccount{
_, err := client.Get(saName, metav1.GetOptions{})
// If the service account already exists, no error is returned
if err == nil {
return nil
}
if !apierrors.IsNotFound(err) {
return err
}
_, err = client.Create(&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: saName,
}})
if err != nil {
return err
}
return nil
return err
}

// GetSA retrieves an existing service-account by name
Expand Down

0 comments on commit fa89454

Please sign in to comment.