mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: cluster e2e test case
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1"
|
||||
@@ -89,9 +91,18 @@ func (clusterConfig *KubeClusterConfig) PostRegistration(ctx context.Context, cl
|
||||
if clusterConfig.CreateNamespace == "" {
|
||||
return nil
|
||||
}
|
||||
if err := ensureNamespaceExists(ctx, cli, clusterConfig.ClusterName, clusterConfig.CreateNamespace); err != nil {
|
||||
_ = DetachCluster(ctx, cli, clusterConfig.ClusterName, DetachClusterManagedClusterKubeConfigPathOption(clusterConfig.FilePath))
|
||||
return fmt.Errorf("failed to ensure %s namespace installed in cluster %s: %w", clusterConfig.CreateNamespace, clusterConfig.ClusterName, err)
|
||||
// retry 3 times.
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := ensureNamespaceExists(ctx, cli, clusterConfig.ClusterName, clusterConfig.CreateNamespace); err != nil {
|
||||
// Cluster gateway discovers the cluster maybe be deferred, so we should retry.
|
||||
if strings.Contains(err.Error(), "no such cluster") {
|
||||
time.Sleep(time.Second * 1)
|
||||
continue
|
||||
}
|
||||
_ = DetachCluster(ctx, cli, clusterConfig.ClusterName, DetachClusterManagedClusterKubeConfigPathOption(clusterConfig.FilePath))
|
||||
return fmt.Errorf("failed to ensure %s namespace installed in cluster %s: %w", clusterConfig.CreateNamespace, clusterConfig.ClusterName, err)
|
||||
}
|
||||
break
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -206,23 +206,23 @@ func delete(path string) *http.Response {
|
||||
}
|
||||
|
||||
func decodeResponseBody(resp *http.Response, dst interface{}) error {
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("response code is not 200: %d", resp.StatusCode)
|
||||
}
|
||||
if resp.Body == nil {
|
||||
return fmt.Errorf("response body is nil")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dst != nil {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(body, dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("response code is not 200: %d body: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user