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

kubeadm: fix kubeadm reset logic #74072

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions cmd/kubeadm/app/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ func NewCmdReset(in io.Reader, out io.Writer) *cobra.Command {
kubeadmutil.CheckErr(err)

kubeConfigFile = cmdutil.FindExistingKubeConfig(kubeConfigFile)
client, err = getClientset(kubeConfigFile, false)
kubeadmutil.CheckErr(err)
if _, err := os.Stat(kubeConfigFile); !os.IsNotExist(err) {
Copy link
Member

@yagonobre yagonobre Feb 14, 2019

Choose a reason for hiding this comment

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

Should we test just err == nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's safe to continue with reset if we encounter something different than ErrNotExist. The rest of the stat(2) possible errors are bad enough for us to stop after the call to getClientset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rosti

The rest of the stat(2) possible errors are bad enough for us to stop after the call to getClientset

isn't is what kubeadmutil.CheckErr(err) is called for?

client, err = getClientset(kubeConfigFile, false)
kubeadmutil.CheckErr(err)
}

if criSocketPath == "" {
criSocketPath, err = resetDetectCRISocket(client)
Expand Down Expand Up @@ -298,10 +300,12 @@ func resetConfigDir(configPathDir, pkiPathDir string) {
}

func resetDetectCRISocket(client clientset.Interface) (string, error) {
// first try to connect to the cluster for the CRI socket
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "reset", false)
if err == nil {
return cfg.NodeRegistration.CRISocket, nil
if client != nil {
// first try to connect to the cluster for the CRI socket
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "reset", false)
if err == nil {
return cfg.NodeRegistration.CRISocket, nil
}
}

// if this fails, try to detect it
Expand Down