From 345be8c7b5863da4acaa848cf11d95b068603a28 Mon Sep 17 00:00:00 2001 From: "tao.yang" Date: Mon, 6 May 2024 13:56:30 +0800 Subject: [PATCH] e2e fix: add service account log Signed-off-by: tao.yang --- framework/serviceaccounts.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/framework/serviceaccounts.go b/framework/serviceaccounts.go index 12d7b4ec..2b84475f 100644 --- a/framework/serviceaccounts.go +++ b/framework/serviceaccounts.go @@ -4,9 +4,12 @@ package framework import ( "context" + "fmt" + "time" + corev1 "k8s.io/api/core/v1" + api_errors "k8s.io/apimachinery/pkg/api/errors" "sigs.k8s.io/controller-runtime/pkg/client" - "time" ) func (f *Framework) GetServiceAccount(saName, namespace string) (*corev1.ServiceAccount, error) { @@ -36,13 +39,26 @@ func (f *Framework) WaitServiceAccountReady(saName, namespace string, timeout ti for { select { default: - as, _ := f.GetServiceAccount(saName, namespace) + as, err := f.GetServiceAccount(saName, namespace) + b := api_errors.IsNotFound(err) + if b { + f.Log("service account: %s/%s not found", namespace, saName) + time.Sleep(time.Second) + continue + } + + if err != nil { + f.Log("failed to get service account, error %v ", err) + time.Sleep(time.Second) + continue + } + if as != nil { return nil } - time.Sleep(time.Second) + case <-ctx.Done(): - return ErrTimeOut + return fmt.Errorf("%w: failed to wait for service account to be ready", ErrTimeOut) } } }