-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix]: add pre-check that If the cluster already exists #2023
Conversation
ce8e3bd
to
58fedfa
Compare
cmd/sealer/cmd/cluster/run.go
Outdated
return err | ||
} | ||
|
||
if ok := strings.Contains(string(context), args[0]); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need check if cluster image same, if not same, the user also can't run cluster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uer API to marshal it.
6699f98
to
fe1f2d5
Compare
@Stevent-fei i have two questions:
|
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -115,6 +117,30 @@ func NewRunCmd() *cobra.Command { | |||
app, extension, nil, imageEngine, runFlags.Mode) | |||
} | |||
|
|||
if exist := osi.IsFileExist(common.GetDefaultClusterfile()); exist { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not use file existing to do this pre-check, try get it from clusterfile.NewClusterFile(nil)
,
if not found, no cluster.
if have ,return run error
Codecov ReportPatch coverage has no change and project coverage change:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #2023 +/- ##
==========================================
- Coverage 18.89% 13.10% -5.80%
==========================================
Files 96 260 +164
Lines 8918 22236 +13318
==========================================
+ Hits 1685 2913 +1228
- Misses 7003 18938 +11935
- Partials 230 385 +155
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 164 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
635ae1a
to
c594c3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
c594c3b
to
ef20494
Compare
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -427,6 +433,19 @@ func installApplication(appImageName string, envs []string, app *v2.Application, | |||
return nil | |||
} | |||
|
|||
func checkClusterIsExists(cf clusterfile.Interface) error { | |||
rawCluster := cf.GetCluster() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rawCluster/desiredCluster/g
cmd/sealer/cmd/cluster/run.go
Outdated
func checkClusterIsExists(cf clusterfile.Interface) error { | ||
rawCluster := cf.GetCluster() | ||
file, err := clusterfile.NewClusterFile(nil) | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err!=nil && match some regular,return nil
1d0af38
to
777cd49
Compare
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -510,3 +517,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi | |||
} | |||
return nil | |||
} | |||
|
|||
func checkClusterIsExists(cf clusterfile.Interface) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not good use err to identify the check result. i assume we could return check result and error.
@Stevent-fei . it ok for me to do pre-check, such as cluster image . however , that is just one item need to check . it is better that if we add a check list to do this. |
a5ed0e2
to
ae156e5
Compare
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -510,3 +518,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi | |||
} | |||
return nil | |||
} | |||
|
|||
func checkClusterIsExists(cf clusterfile.Interface) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func checkClusterIsExists(cluster v2.cluster) (string, error) {
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -510,3 +518,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi | |||
} | |||
return nil | |||
} | |||
|
|||
func checkClusterIsExists(cf clusterfile.Interface) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this func to different file Or utils, and add UT test.
cmd/sealer/cmd/cluster/run.go
Outdated
if err == nil { | ||
cluster := clusterFile.GetCluster() | ||
if cluster.Spec.Image != rawCluster.Spec.Image { | ||
return "exist", fmt.Errorf("the cluster image already exists, please uninstall the current cluster and install another version of the cluster image") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"exist" is not good, you should use const such as "SameImageName" Or something to identity it
cmd/sealer/cmd/cluster/run.go
Outdated
@@ -235,6 +237,12 @@ func runWithClusterfile(clusterFile string, runFlags *types.RunFlags) error { | |||
} | |||
|
|||
func runClusterImage(imageEngine imageengine.Interface, cf clusterfile.Interface, imageSpec *imagev1.ImageSpec, mode string) error { | |||
//check cluster | |||
checkClusterFile, err := checkClusterIsExists(cf) | |||
if checkClusterFile == "exist" && err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why &&? Return err if it is not nil.
384a336
to
e383428
Compare
@@ -236,6 +238,11 @@ func runWithClusterfile(clusterFile string, runFlags *types.RunFlags) error { | |||
|
|||
func runClusterImage(imageEngine imageengine.Interface, cf clusterfile.Interface, imageSpec *imagev1.ImageSpec, mode string) error { | |||
cluster := cf.GetCluster() | |||
//check cluster | |||
checkClusterFile, err := utils.CheckClusterIsExists(cluster) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is err?
@@ -256,3 +259,15 @@ func GetClusterClient() *k8s.Client { | |||
} | |||
return nil | |||
} | |||
|
|||
func CheckClusterIsExists(cluster v2.Cluster) (string, error) { | |||
clusterFile, _, err := clusterfile.GetActualClusterFile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should retrun err fast
if err == nil { | ||
newClusterfile := clusterFile.GetCluster() | ||
if cluster.Spec.Image != newClusterfile.Spec.Image { | ||
return clusterExists, fmt.Errorf("the cluster image already exists, please uninstall the current cluster and install another version of the cluster image") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not return fmt.Errorf
e383428
to
f2eff17
Compare
Describe what this PR does / why we need it
When the sealer runs, it will check in advance whether there is a deployed cluster image. If there is, and the version is inconsistent, then an error will be reported. If the version is consistent, then skip. If not, install normally
exist:
not exist:
Does this pull request fix one issue?
Fixes #2022
Describe how you did it
Describe how to verify it
Special notes for reviews