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

Check file path before Initialize crd #2207

Closed
wants to merge 1 commit into from

Conversation

my-git9
Copy link
Member

@my-git9 my-git9 commented Jul 17, 2022

What type of PR is this?
/kind bug

What this PR does / why we need it:
1.When we run karmadactl init --kube-image-registry=registry.cn-hangzhou.aliyuncs.com/google_containers --crds /root/crds.tar.gz
2.If the crds dir do not has patches or bases, like

$ ls crds
crd.yaml  net.yaml
  1. The output:

image

  1. What do we expect:
    Command output file does not exist, and exit

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
The test result:
image

Does this PR introduce a user-facing change?:

Check if the file path exists before Initialize crd.

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 17, 2022
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 17, 2022
@my-git9 my-git9 force-pushed the filepath1 branch 3 times, most recently from d778ca1 to 962cd11 Compare July 17, 2022 13:17
@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 17, 2022
@my-git9
Copy link
Member Author

my-git9 commented Jul 18, 2022

/cc @lonelyCZ @RainbowMango

@my-git9
Copy link
Member Author

my-git9 commented Aug 1, 2022

/cc @prodanlabs

@my-git9
Copy link
Member Author

my-git9 commented Aug 1, 2022

/assign @prodanlabs

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from prodanlabs after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@RainbowMango
Copy link
Member

Sorry for letting this sit.
I think this is a reasonable improvement. @my-git9 would you like to rebase and re-open this PR? You can just assign it to me.

@my-git9
Copy link
Member Author

my-git9 commented Jul 12, 2023

Sorry for letting this sit. I think this is a reasonable improvement. @my-git9 would you like to rebase and re-open this PR? You can just assign it to me.

Sure, thanks

@my-git9
Copy link
Member Author

my-git9 commented Jul 12, 2023

/assign @RainbowMango

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

I'll try to get back on this by this week.
@chaosi-zju Would you like to take a look?

Copy link
Member

@chaosi-zju chaosi-zju left a comment

Choose a reason for hiding this comment

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

Hello, thank you for your important commit! Review is ongoing, and my viewpoint just for reference only.

if os.IsNotExist(err) {
return err
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Hello, I wanna why if err != nil && !os.IsNotExist(err), we not return the err but return nil?

how about like this:

func PathExist(path string) error {
    _, err := os.Stat(path)
    if err != nil && !os.IsExist(err) {
        return err
    }
    return nil
}

if err := utils.PathExists(dir + "/crds/bases"); err != nil {
return err
}
basesCRDsFiles := utils.ListFiles(dir + "/crds/bases")
Copy link
Member

Choose a reason for hiding this comment

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

Hi, have you tested if this dir is just a empty dir, if there is any other unexpected failure?

}
}

if err := utils.PathExists(dir + "/crds/patches"); 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.

ditto

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Just looked into it.
The root cause seems that the filepath.Walk might arise an error(like no such file or directory) when visiting the path(in this case it is the non-exist /crds/bases), this error should be handled but accidentally be ignored at here:

if !info.IsDir() {
.

Currently, we lack an efficient way to validate a specified crd.tar.gz, this approach just focuses on checking if crds/base and crds/patches exist or not, it's a little bit restrictive. E.g. what if these paths exist but don't have the expected files? (I didn't test it, just a guess, it will make things worse, because it may mask the issue and allow the entire installation process to continue, giving the user a false impression of successful installation, which I mean it is worse.)

So, my opinion is either to establish a comprehensive validation mechanism for the crds.tar.gz based on this issue or temporarily postpone this issue.

Signed-off-by: xin.li <xin.li@daocloud.io>
@my-git9
Copy link
Member Author

my-git9 commented Jul 17, 2023

Yes, it seems that this PR has a lot of limitations

@RainbowMango
Copy link
Member

/close

Please reopen it if you think we still need it.

@karmada-bot
Copy link
Collaborator

@RainbowMango: Closed this PR.

In response to this:

/close

Please reopen it if you think we still need it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants