Skip to content

Commit

Permalink
feature: check if there is a running cluster, if exist, should not mo…
Browse files Browse the repository at this point in the history
…unt new image.
  • Loading branch information
Stevent-fei committed Feb 28, 2023
1 parent e6117de commit c594c3b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/sealer/cmd/cluster/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func runWithClusterfile(clusterFile string, runFlags *types.RunFlags) error {
}

cf.SetCluster(*cluster)

imageName := cluster.Spec.Image
imageEngine, err := imageengine.NewImageEngine(options.EngineGlobalConfigurations{})
if err != nil {
Expand Down Expand Up @@ -219,6 +220,11 @@ func runWithClusterfile(clusterFile string, runFlags *types.RunFlags) error {
}

func createNewCluster(imageEngine imageengine.Interface, cf clusterfile.Interface, imageSpec *imagev1.ImageSpec, mode string) error {
//check cluster
if err := checkClusterIsExists(cf); err != nil {
return err
}

cluster := cf.GetCluster()
infraDriver, err := infradriver.NewInfraDriver(&cluster)
if err != nil {
Expand Down Expand Up @@ -416,3 +422,16 @@ func installApplication(appImageName string, envs []string, app *v2.Application,

return nil
}

func checkClusterIsExists(cf clusterfile.Interface) error {
rawCluster := cf.GetCluster()
file, err := clusterfile.NewClusterFile(nil)
if err == nil {
cluster := file.GetCluster()
if cluster.Spec.Image != rawCluster.Spec.Image {
return fmt.Errorf("the cluster image already exists, please uninstall the current cluster and install another version of the cluster image")
}
return fmt.Errorf("this cluster image has already been installed, please do not repeat the operation")
}
return nil
}

0 comments on commit c594c3b

Please sign in to comment.