Skip to content

Commit

Permalink
Attempt to fix e2e test flakiness
Browse files Browse the repository at this point in the history
- In PR tektoncd#550 the e2e test for taskrunTimeOut failed with reason " message: 'References a Task arendelle-2j8ft/giraffe that doesn''t exist:  translating
I0226 14:05:06.851]       Build to Pod: serviceaccounts "default" not found'"

Theory: ServiceAccount 'default' in test namespace is created with some delay but the
taskrun reconciliation is triggered before that which causes this type
of failure

Fix: Once namespace is created call wait function to make sure SA is
created.
  • Loading branch information
Shash Reddy committed Feb 26, 2019
1 parent 3ee62a6 commit f5cd1c1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
knativetest "github.com/knative/pkg/test"
"github.com/knative/pkg/test/logging"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

// Mysteriously by k8s libs, or they fail to create `KubeClient`s from config. Apparently just importing it is enough. @_@ side effects @_@. https://github.com/kubernetes/client-go/issues/242
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand All @@ -57,7 +59,7 @@ func setup(t *testing.T, logger *logging.BaseLogger) (*clients, string) {

c := newClients(t, knativetest.Flags.Kubeconfig, knativetest.Flags.Cluster, namespace)
createNamespace(namespace, logger, c.KubeClient)

verifyServiceAccountExistence(namespace, logger, c.KubeClient)
return c, namespace
}

Expand Down Expand Up @@ -113,6 +115,21 @@ func createNamespace(namespace string, logger *logging.BaseLogger, kubeClient *k
}
}

func verifyServiceAccountExistence(namespace string, logger *logging.BaseLogger, kubeClient *knativetest.KubeClient) {
defaultSA := "default"
logger.Infof("Verify SA %q is created in namespace %q", defaultSA, namespace)

if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
_, err := kubeClient.Kube.CoreV1().ServiceAccounts(namespace).Get(defaultSA, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
return false, nil
}
return true, err
}); err != nil {
logger.Fatalf("Failed to get SA %q in namespace %q for tests: %s", defaultSA, namespace, err)
}
}

// TestMain initializes anything global needed by the tests. Right now this is just log and metric
// setup since the log and metric libs we're using use global state :(
func TestMain(m *testing.M) {
Expand Down

0 comments on commit f5cd1c1

Please sign in to comment.