Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 committed Jan 16, 2024
1 parent dd8cd73 commit 65cdd09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 16 additions & 5 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
`
}

0 comments on commit 65cdd09

Please sign in to comment.