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
Implement kubeadm reset #34807
Implement kubeadm reset #34807
Conversation
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.
This worked great on CentOS, just a few questions and one very minor request for changes.
@@ -150,7 +150,7 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight | |||
} | |||
|
|||
if !skipPreFlight { | |||
fmt.Println("<cmd/init> Running pre-flight checks") | |||
fmt.Println("Running pre-flight checks") |
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.
Intentional?
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.
Yep, I think we decided to drop it
At least it was dropped in join
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.
Drop it.
PortOpenCheck{port: 10250}, | ||
PortOpenCheck{port: 10251}, | ||
PortOpenCheck{port: 10252}, |
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.
Did these turn out to not be necessary?
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.
This is for the node, 10251 and 10252 for cm and scheduler and 8080 for unsecured apiserver
exec.Command("sh", "-c", "cat /proc/mounts | awk '{print $2}' | grep '/var/lib/kubelet' | xargs umount").Run() | ||
|
||
dirsToRemove := []string{"/var/lib/kubelet", "/var/lib/etcd", "/etc/kubernetes"} | ||
fmt.Printf("Deleting the stateful directories: [%v]\n", dirsToRemove) |
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.
This shows up as: Deleting the stateful directories: [[/var/lib/kubelet /var/lib/etcd /etc/kubernetes]]
Can probably drop the [] in code.
|
||
fmt.Printf("Stopping all running docker containers...") | ||
if err := exec.Command("sh", "-c", "docker ps -q | xargs docker kill").Run(); err != nil { | ||
fmt.Printf("failed to stop the running containers") |
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 we actually clean these up or just kill? My reset script I'd been clearing them out entirely.
Also should we only hit containers with a k8s prefix?
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.
Thinking we may want to filter to k8s containers only, I could envision a developer deciding to init master on their workstation.
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.
I thought about that, leads to more work, but is probably worth it
Not sure if we should remove them though... the user might want to read logs
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.
I think we should use docker rm --force --volumes
here.
the user might want to read logs
Maybe, but more user will complain about disk space used up by those containers.
fmt.Printf("Stopping the %s service...\n", serviceToStop) | ||
initSystem.ServiceStop(serviceToStop) | ||
} else { | ||
fmt.Printf("no supported init system detected, skipping service checks for %s. kubeadm reset may not have full effect now.\n", serviceToStop) |
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 doesn't initsystem.GetInitSystem()
return that string as an error?
|
||
fmt.Printf("Unmounting directories in /var/lib/kubelet...\n") | ||
// Don't check for errors here, since umount will return a non-zero exit code if there is no directories to umount | ||
exec.Command("sh", "-c", "cat /proc/mounts | awk '{print $2}' | grep '/var/lib/kubelet' | xargs umount").Run() |
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.
I think find /var/lib/kubelet | xargs -n 1 findmnt -n -t tmpfs -o TARGET -T | uniq | xargs -r umount
is cleaner.
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 you depend on awk
, you don't have to use grep
, i.e. awk '$2 ~ /\/var\/lib\/kubelet { print $2 }' | xargs umount
, or even awk '$2 ~ /\/var\/lib\/kubelet { system("umount "$2) }
, on the other hand you don't even have to shell out...
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.
I think we should improve that later on...
I don't think find /var/lib/kubelet | xargs -n 1 findmnt -n -t tmpfs -o TARGET -T | uniq | xargs -r umount
is better because it will do a find in the whole /var/lib/kubelet dir which may be large.
/proc/mounts
is a very small file with the information we need.
I couldn't get awk working standalone, so someone can take that as a fun thing improve later :)
|
||
fmt.Printf("Stopping all running docker containers...") | ||
if err := exec.Command("sh", "-c", "docker ps -q | xargs docker kill").Run(); err != nil { | ||
fmt.Printf("failed to stop the running containers") |
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.
I think we should use docker rm --force --volumes
here.
the user might want to read logs
Maybe, but more user will complain about disk space used up by those containers.
I'd like to get this lgtm'd ASAP, if @mikedanese could do it, it would be awesome! (Ilya is offline now) |
Jenkins verification failed for commit e4268db1a84db9667d3a8745905f95965b9547fe. Full PR test history. The magic incantation to run this job again is |
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
Applying @dgoodwin's LGTM |
} | ||
|
||
func RunReset(out io.Writer, cmd *cobra.Command, skipPreFlight bool) 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.
Why the empty line?
fmt.Println("Running pre-flight checks") | ||
err := preflight.RunResetCheck() | ||
if err != nil { | ||
return err |
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.
This will break pre-flight checks. It should be return &preflight.PreFlightError{Msg: err.Error()}}
instead.
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.
Ah, I copied as it was for init and join after the original preflight PR, which seems to have had this bug then.
Will fix
Fixed @pires' comments, waiting for the build to be green before applying lgtm again |
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
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
Automatic merge from submit-queue kubeadm join: Added support for config file. As more behavior (#34719, #34807, fix for #33641) is added to `kubeadm join`, this will be eventually very much needed. Makes sense to go in sooner rather than later. Also references #34501 and #34884. /cc @luxas @mikedanese
@kubernetes/sig-cluster-lifecycle
This change is