Skip to content

Commit

Permalink
fix: error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
reaver-flomesh committed Jan 5, 2025
1 parent 6dc6df6 commit e28b667
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,22 @@ func (td *FsmTestData) InitTestData(t GinkgoTInterface) error {
// rollback if creation failed
td.T.Error(err)
td.T.Error("Failed to create cluster >>> Rolling Back")

if err := k3dCluster.ClusterDelete(context.TODO(), runtimes.SelectedRuntime, &clusterConfig.Cluster, k3d.ClusterDeleteOpts{SkipRegistryCheck: true}); err != nil {
td.T.Error(err)
td.T.Fatal("Cluster creation FAILED, also FAILED to rollback changes!")
return err
}

td.T.Fatal("Cluster creation FAILED, all changes have been rolled back!")
return err
}
td.T.Logf("Cluster '%s' created successfully!", clusterConfig.Cluster.Name)

td.T.Logf("Updating default kubeconfig with a new context for cluster %s", clusterConfig.Cluster.Name)
if _, err := k3dCluster.KubeconfigGetWrite(context.TODO(), runtimes.SelectedRuntime, &clusterConfig.Cluster, "", &k3dCluster.WriteKubeConfigOptions{UpdateExisting: true, OverwriteExisting: false, UpdateCurrentContext: true}); err != nil {
td.T.Log(err)
td.T.Logf("Failed to write kubeconfig: %s", err)
return err
}
}

Expand Down Expand Up @@ -580,11 +585,11 @@ func (td *FsmTestData) k3dClusterConfig() *k3dCfg.ClusterConfig {
// },
// }

tag := "latest"
if Td.ClusterVersion != "" {
simpleCfg.Image = fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, Td.ClusterVersion)
} else {
simpleCfg.Image = fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, "latest")
tag = Td.ClusterVersion
}
simpleCfg.Image = fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, tag)

if err := config.ProcessSimpleConfig(&simpleCfg); err != nil {
td.T.Fatalf("error processing/sanitizing simple config: %v", err)
Expand Down

0 comments on commit e28b667

Please sign in to comment.