From 65cdd0910477344660f63a354781e54d82bad24d Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Tue, 16 Jan 2024 15:39:46 +0800 Subject: [PATCH] fix --- .github/workflows/e2e-test.yaml | 2 +- cmd/create.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index e0dec886..12a1b152 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -110,5 +110,5 @@ jobs: echo "Running kubecm create..." echo "********************************************************************************" bin/kubecm ls - bin/kubecm create --user e2e -n default --cluster-role view --context-name kind-3rd-kind + bin/kubecm create --user e2e --namespace default --cluster-role view --context-name kind-3rd-kind kubectl get all --kubeconfig e2e-kubeconfig.yaml \ No newline at end of file diff --git a/cmd/create.go b/cmd/create.go index 22f8271c..deeae12f 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -18,6 +18,7 @@ import ( "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "os" + "time" ) // CreateCommand clean command struct @@ -208,10 +209,20 @@ func (co *CreateOptions) approveCSR() error { // createKubeConfig create kubeconfig func (co *CreateOptions) createKubeConfig(privateKey *rsa.PrivateKey) error { - // get CSR and extract certificate - csr, err := co.clientSet.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), co.userName, metav1.GetOptions{}) - if err != nil { - return err + var csr *certificatesv1.CertificateSigningRequest + var err error + for i := 0; i < 3; i++ { // Retry up to 3 times + csr, err = co.clientSet.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), co.userName, metav1.GetOptions{}) + if err != nil { + return err + } + + if len(csr.Status.Certificate) != 0 { + break + } + + // Sleep for a second before retrying + time.Sleep(1 * time.Second) } certData := csr.Status.Certificate @@ -369,6 +380,6 @@ func createExample() string { # Create new KubeConfig(experiment) kubecm create # Create new KubeConfig(experiment) with flags -kubecm create --user test -n default --cluster-role view --context-name kind-kind +kubecm create --user test --namespace default --cluster-role view --context-name kind-kind ` }