Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Stevent-fei
Copy link
Collaborator

@Stevent-fei Stevent-fei commented Feb 10, 2023

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:
image

not exist:
image

Does this pull request fix one issue?

Fixes #2022

Describe how you did it

Describe how to verify it

Special notes for reviews

return err
}

if ok := strings.Contains(string(context), args[0]); !ok {
Copy link
Collaborator

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.

Copy link
Collaborator

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.

@kakaZhou719
Copy link
Member

@Stevent-fei i have two questions:

  1. how to determine there is an existed cluster?
  2. should we add this pre-check logic to all create process?

@@ -115,6 +117,30 @@ func NewRunCmd() *cobra.Command {
app, extension, nil, imageEngine, runFlags.Mode)
}

if exist := osi.IsFileExist(common.GetDefaultClusterfile()); exist {
Copy link
Member

@kakaZhou719 kakaZhou719 Feb 28, 2023

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

@kakaZhou719 kakaZhou719 changed the title feature: check if there is a running cluster, if exist, should not mount new image [bugfix]: add pre-check that If the cluster already exists Feb 28, 2023
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2023

Codecov Report

Patch coverage has no change and project coverage change: -5.80 ⚠️

Comparison is base (a51d0ec) 18.89% compared to head (f2eff17) 13.10%.

📣 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     
Flag Coverage Δ
e2e-tests 9.22% <ø> (?)
unit-tests 18.87% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cmd/sealer/cmd/utils/cluster.go 32.04% <0.00%> (-1.68%) ⬇️

... 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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Stevent-fei Stevent-fei force-pushed the fix_sealer_run_bug branch 3 times, most recently from 635ae1a to c594c3b Compare February 28, 2023 09:51
Copy link
Collaborator

@starnop starnop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -427,6 +433,19 @@ func installApplication(appImageName string, envs []string, app *v2.Application,
return nil
}

func checkClusterIsExists(cf clusterfile.Interface) error {
rawCluster := cf.GetCluster()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rawCluster/desiredCluster/g

func checkClusterIsExists(cf clusterfile.Interface) error {
rawCluster := cf.GetCluster()
file, err := clusterfile.NewClusterFile(nil)
if err == nil {
Copy link
Collaborator

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

@Stevent-fei Stevent-fei force-pushed the fix_sealer_run_bug branch 2 times, most recently from 1d0af38 to 777cd49 Compare March 9, 2023 08:39
@@ -510,3 +517,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi
}
return nil
}

func checkClusterIsExists(cf clusterfile.Interface) error {
Copy link
Member

@kakaZhou719 kakaZhou719 Mar 10, 2023

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.

@kakaZhou719
Copy link
Member

@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.

@Stevent-fei Stevent-fei force-pushed the fix_sealer_run_bug branch 2 times, most recently from a5ed0e2 to ae156e5 Compare March 10, 2023 02:43
@@ -510,3 +518,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi
}
return nil
}

func checkClusterIsExists(cf clusterfile.Interface) (string, error) {
Copy link
Member

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) {

@@ -510,3 +518,16 @@ func prepareMaterials(infraDriver infradriver.InfraDriver, imageEngine imageengi
}
return nil
}

func checkClusterIsExists(cf clusterfile.Interface) (string, error) {
Copy link
Member

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.

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")
Copy link
Member

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

@@ -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 {
Copy link
Member

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.

@Stevent-fei Stevent-fei force-pushed the fix_sealer_run_bug branch 2 times, most recently from 384a336 to e383428 Compare March 10, 2023 05:32
@@ -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)
Copy link
Member

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()
Copy link
Member

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")
Copy link
Member

@kakaZhou719 kakaZhou719 Mar 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sealer run]check if there is a running cluster, if exist, should not mount new image.
5 participants