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

Removed awk from kubeadm reset #81494

Merged
merged 1 commit into from
Aug 21, 2019
Merged

Conversation

Klaven
Copy link
Contributor

@Klaven Klaven commented Aug 16, 2019

removed awk usage from kubeadm reset in favor of native golang calls
that are not vulnerable to expansion.

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change

/kind bug

/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:
This PR was created based on results from the security assessment,

Which issue(s) this PR fixes:

Fixes #
xref#/kubernetes/kubeadm/issues/1715

Special notes for your reviewer:

@neolit123 :
Wanted to get feedback. in it's current state it's not very testable. But at the same time I did not want to pollute the core change with changes not related to removing awk.

also, I would not expect a function called absoluteKubeletRunDirectory to unmount directories. but again thought this change would pollute the core change. If it is acceptable I will make a new PR later this week to address this.

Does this PR introduce a user-facing change?:

kubeadm reset: unmount directories under "/var/lib/kubelet" for linux only

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 16, 2019
@Klaven Klaven changed the title removed awk from kubeadm reset [WIP] removed awk from kubeadm reset Aug 16, 2019
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2019
@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 16, 2019
@Klaven Klaven changed the title [WIP] removed awk from kubeadm reset Removed awk from kubeadm reset Aug 16, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2019
@Klaven Klaven changed the title Removed awk from kubeadm reset [WIP] Removed awk from kubeadm reset Aug 16, 2019
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 16, 2019
@Klaven
Copy link
Contributor Author

Klaven commented Aug 16, 2019

Added WIP due to testing needing to be run on at least one of the other platforms. I should be able to do this over the weekend.

Tested on Ubuntu 18.04 server vm and successfully unmounted correct directories.

@Klaven
Copy link
Contributor Author

Klaven commented Aug 16, 2019

/test pull-kubernetes-e2e-gce

@neolit123
Copy link
Member

Added WIP due to testing needing to be run on at least one of the other platforms. I should be able to do this over the weekend.

i think it's fine to merge without testing !linux as its just a NOOP there.

Does this PR introduce a user-facing change?:
perhaps we should add a release note for this one:

kubeadm: unmount directories under "/var/lib/kubelet" for linux only

thanks.

/approve
/priority backlog
/assign @rosti
PTAL too.

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 16, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Klaven, neolit123

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2019
@Klaven Klaven changed the title [WIP] Removed awk from kubeadm reset Removed awk from kubeadm reset Aug 17, 2019
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 17, 2019
@k8s-ci-robot k8s-ci-robot removed the release-note-none Denotes a PR that doesn't merit a release note. label Aug 17, 2019
Copy link
Contributor

@rosti rosti left a comment

Choose a reason for hiding this comment

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

Thanks @Klaven !
Overall, this looks OK, but we may need to think on better platform split for reset (WRT the Windows side of things).

if len(m) < 2 || !strings.HasPrefix(m[1], kubeadmconstants.KubeletRunDirectory) {
continue
}
if err := syscall.Unmount(m[1], syscall.MNT_FORCE); 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.

The original call did not imply MNT_FORCE. Also, that flag is somewhat misleading. It is actually used to force unmount a filesystem, which is a remote one and the connection to the server is lost. It does not force unmount a filesystem if it has opened handles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove this if you like. will have to be tonight as it will mean I need to retest it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this has been removed and tested. (testing methodology posted.) I agree, it's misleading and really not helpful in this case. Also not used on the original so even if we wanted to add it would probably be better to add in new PR.

@@ -0,0 +1,29 @@
// +build !linux
Copy link
Contributor

@rosti rosti Aug 19, 2019

Choose a reason for hiding this comment

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

Let's not do premature platform splitting in reset at this point. It's almost all Linux dependent and we need to have the whole picture in mind to take the best approach.

Copy link
Member

Choose a reason for hiding this comment

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

but this function certainly should not run on _windows.go (NO-OP).

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 I guess I don't understand, if I don't have this file the code will not pass checks because it does not have the functions used in the unmount_linux.go file on windows and mac. For both windows and mac this is a no-op. How are you wanting me to handle compiling for windows and linux if not with this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, we can leave it like this for now, but we may need to redesign and rename the files.
The question is if we should place absoluteKubeletRunDirectory in the platform specific portions of cleanupnode.go? So the idea is to have cleanupnode_unix.go and cleanupnode_windows.go with absoluteKubeletRunDirectory and a few other things in it.

But, certainly, that must be done in another PR.

@Klaven
Copy link
Contributor Author

Klaven commented Aug 20, 2019

my test: (with removal of force)

>  sudo cat /proc/mounts | grep /var/lib/kubelet
/dev/loop5 /var/lib/kubelet ext4 rw,relatime,data=ordered 0 0

> sudo kubeadm reset
....

>  sudo cat /proc/mounts | grep /var/lib/kubelet

umountDirsCmd := fmt.Sprintf("awk '$2 ~ path {print $2}' path=%s/ /proc/mounts | xargs -r umount", absoluteKubeletRunDirectory)
klog.V(1).Infof("[reset] Executing command %q", umountDirsCmd)
umountOutputBytes, err := exec.Command("sh", "-c", umountDirsCmd).Output()
err = unmountKubeletDirectory()
Copy link
Contributor

Choose a reason for hiding this comment

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

A thing, that I've missed on the first run here is, that we need absoluteKubeletRunDirectory to be passed to unmountKubeletDirectory (instead of using a const there).

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

@rosti rosti left a comment

Choose a reason for hiding this comment

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

Thanks @Klaven !
Let's merge these as they are, but first, please, squash your commits.

removed awk from kubeadm reset in favor of native go lang calls
that are not vulnerable to expantion.
@Klaven
Copy link
Contributor Author

Klaven commented Aug 20, 2019

/test pull-kubernetes-kubemark-e2e-gce-big

Copy link
Contributor

@rosti rosti left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 21, 2019
@k8s-ci-robot k8s-ci-robot merged commit 17a1859 into kubernetes:master Aug 21, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.16 milestone Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. 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.

4 participants