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 reset: add support for dry-run #107512

Merged

Conversation

SataQiu
Copy link
Member

@SataQiu SataQiu commented Jan 13, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

kubeadm reset: add support for dry-run

Which issue(s) this PR fixes:

Fixes kubernetes/kubeadm#2636

Special notes for your reviewer:

Does this PR introduce a user-facing change?

kubeadm: add support for dry running "kubeadm reset". The new flag "kubeadm reset --dry-run" is similar to the existing flag for "kubeadm init/join/upgrade" and allows you to see what changes would be applied.

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 13, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SataQiu

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 area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 13, 2022
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thanks @SataQiu
noticed a couple of small changes that we can do on the side, but other than that this seems good.

cmd/kubeadm/app/cmd/phases/reset/cleanupnode.go Outdated Show resolved Hide resolved
cmd/kubeadm/app/cmd/phases/reset/cleanupnode.go Outdated Show resolved Hide resolved
cmd/kubeadm/app/cmd/phases/reset/removeetcdmember.go Outdated Show resolved Hide resolved
@neolit123
Copy link
Member

(no change required)

just wanted to note that, i was trying to figure out if we are consistent in how we print dryrun actions. do we prefix with the command name e.g. [reset] or do we always prefix with [dryrun].

it seems we do both and it's not very consistent.

grep "\[dryrun\]" * -rnI

app/phases/controlplane/manifests.go:106:			fmt.Printf("[dryrun] Would create users and groups for %+v to run as non-root\n", componentNames)
app/phases/controlplane/manifests.go:130:				fmt.Printf("[dryrun] Would update static pod manifest for %q to run run as non-root\n", componentName)
app/phases/upgrade/health.go:107:		fmt.Printf("[dryrun] Would create the Job %q in namespace %q and wait until it completes\n", jobName, ns)
app/phases/upgrade/postupgrade.go:254:		fmt.Printf("[dryrun] Would ensure that %q includes a CRI endpoint URL scheme\n", filePath)
app/phases/etcd/local.go:149:		fmt.Printf("[dryrun] Would add etcd member: %s\n", etcdPeerAddress)
app/phases/etcd/local.go:167:		fmt.Println("[dryrun] Would wait for the new etcd member to join the cluster")
app/phases/etcd/local.go:267:			fmt.Printf("[dryrun] Would create users and groups for %q to run as non-root\n", kubeadmconstants.Etcd)
app/phases/etcd/local.go:268:			fmt.Printf("[dryrun] Would update static pod manifest for %q to run run as non-root\n", kubeadmconstants.Etcd)
app/util/apiclient/dryrunclient.go:128:						fmt.Println("[dryrun] Returning faked GET response:")
app/util/apiclient/dryrunclient.go:153:						fmt.Println("[dryrun] Returning faked LIST response:")
app/util/apiclient/dryrunclient.go:215:	fmt.Fprintf(w, "[dryrun] Would perform action %s on resource %q in API group \"%s/%s\"\n", strings.ToUpper(action.GetVerb()), action.GetResource().Resource, group, action.GetResource().Version)
app/util/apiclient/dryrunclient.go:219:		fmt.Fprintf(w, "[dryrun] Resource name: %q\n", namedAction.GetName())
app/util/apiclient/dryrunclient.go:227:			fmt.Println("[dryrun] Attached object:")
app/util/apiclient/dryrunclient.go:235:		fmt.Fprintf(w, "[dryrun] Attached patch:\n\t%s\n", strings.Replace(string(patchAction.GetPatch()), `\"`, `"`, -1))
app/util/apiclient/dryrunclient_test.go:40:			expectedBytes: []byte(`[dryrun] Would perform action GET on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:41:[dryrun] Resource name: "kubernetes"
app/util/apiclient/dryrunclient_test.go:47:			expectedBytes: []byte(`[dryrun] Would perform action GET on resource "clusterrolebindings" in API group "rbac.authorization.k8s.io/v1"
app/util/apiclient/dryrunclient_test.go:48:[dryrun] Resource name: "system:node"
app/util/apiclient/dryrunclient_test.go:54:			expectedBytes: []byte(`[dryrun] Would perform action LIST on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:67:			expectedBytes: []byte(`[dryrun] Would perform action CREATE on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:82:			expectedBytes: []byte(`[dryrun] Would perform action PATCH on resource "nodes" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:83:[dryrun] Resource name: "my-node"
app/util/apiclient/dryrunclient_test.go:84:[dryrun] Attached patch:
app/util/apiclient/dryrunclient_test.go:91:			expectedBytes: []byte(`[dryrun] Would perform action DELETE on resource "pods" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:92:[dryrun] Resource name: "my-pod"
app/util/apiclient/clientbacked_dryrun.go:132:		fmt.Println("[dryrun] The GET request didn't yield any result, the API Server returned a NotFound error.")
app/util/dryrun/dryrun.go:78:		fmt.Fprintf(w, "[dryrun] Would write file %q with content:\n", outputFilePath)
app/util/dryrun/dryrun.go:94:	fmt.Println("[dryrun] Would wait for the API Server's /healthz endpoint to return 'ok'")
app/util/dryrun/dryrun.go:100:	fmt.Printf("[dryrun] Would wait for the Pods with the label %q in the %s namespace to become Running\n", kvLabel, metav1.NamespaceSystem)
app/util/dryrun/dryrun.go:106:	fmt.Printf("[dryrun] Would wait for the %q Pod in the %s namespace to be deleted\n", podName, metav1.NamespaceSystem)
app/util/dryrun/dryrun.go:112:	fmt.Printf("[dryrun] Would make sure the kubelet %q endpoint is healthy\n", healthzEndpoint)
app/util/dryrun/dryrun.go:149:		fmt.Printf("[dryrun] Wrote certificates, kubeconfig files and control plane manifests to the %q directory\n", manifestDir)
app/util/dryrun/dryrun.go:156:		fmt.Printf("[dryrun] Wrote certificates and kubeconfig files to the %q directory\n", manifestDir)
app/util/dryrun/dryrun.go:159:	fmt.Println("[dryrun] The certificates or kubeconfig files would not be printed due to their sensitive nature")
app/util/dryrun/dryrun.go:160:	fmt.Printf("[dryrun] Please examine the %q directory for details about what would be written\n", manifestDir)
app/cmd/phases/join/controlplanejoin.go:139:		fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
app/cmd/phases/join/controlplanejoin.go:197:		fmt.Printf("[dryrun] Would mark node %s as a control-plane\n", cfg.NodeRegistration.Name)
app/cmd/phases/join/kubelet.go:173:		fmt.Println("[dryrun] Would stop the kubelet")
app/cmd/phases/join/kubelet.go:190:		fmt.Println("[dryrun] Would start the kubelet")
app/cmd/phases/upgrade/node/kubeletconfig.go:121:				fmt.Println("[dryrun] would update the node CRI socket path to include an URL scheme")
app/cmd/phases/init/etcd.go:96:				fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
app/cmd/upgrade/apply.go:173:		fmt.Println("[dryrun] Finished dryrunning successfully!")


but overall that does not seem like a big issue, i think we should keep only global dryrun utilities prefixed with [dryrun]
such an utility is app/util/apiclient/dryrunclient.go and not sure what else qualifies.

i think having [reset] Would ... for this PR is fine.

@neolit123
Copy link
Member

/priority backlog
/triage accepted

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 13, 2022
@SataQiu SataQiu force-pushed the support-reset-dryrun-20220113 branch from 93c14aa to e91c829 Compare January 14, 2022 03:07
@SataQiu
Copy link
Member Author

SataQiu commented Jan 14, 2022

(no change required)

just wanted to note that, i was trying to figure out if we are consistent in how we print dryrun actions. do we prefix with the command name e.g. [reset] or do we always prefix with [dryrun].

it seems we do both and it's not very consistent.

grep "\[dryrun\]" * -rnI

app/phases/controlplane/manifests.go:106:			fmt.Printf("[dryrun] Would create users and groups for %+v to run as non-root\n", componentNames)
app/phases/controlplane/manifests.go:130:				fmt.Printf("[dryrun] Would update static pod manifest for %q to run run as non-root\n", componentName)
app/phases/upgrade/health.go:107:		fmt.Printf("[dryrun] Would create the Job %q in namespace %q and wait until it completes\n", jobName, ns)
app/phases/upgrade/postupgrade.go:254:		fmt.Printf("[dryrun] Would ensure that %q includes a CRI endpoint URL scheme\n", filePath)
app/phases/etcd/local.go:149:		fmt.Printf("[dryrun] Would add etcd member: %s\n", etcdPeerAddress)
app/phases/etcd/local.go:167:		fmt.Println("[dryrun] Would wait for the new etcd member to join the cluster")
app/phases/etcd/local.go:267:			fmt.Printf("[dryrun] Would create users and groups for %q to run as non-root\n", kubeadmconstants.Etcd)
app/phases/etcd/local.go:268:			fmt.Printf("[dryrun] Would update static pod manifest for %q to run run as non-root\n", kubeadmconstants.Etcd)
app/util/apiclient/dryrunclient.go:128:						fmt.Println("[dryrun] Returning faked GET response:")
app/util/apiclient/dryrunclient.go:153:						fmt.Println("[dryrun] Returning faked LIST response:")
app/util/apiclient/dryrunclient.go:215:	fmt.Fprintf(w, "[dryrun] Would perform action %s on resource %q in API group \"%s/%s\"\n", strings.ToUpper(action.GetVerb()), action.GetResource().Resource, group, action.GetResource().Version)
app/util/apiclient/dryrunclient.go:219:		fmt.Fprintf(w, "[dryrun] Resource name: %q\n", namedAction.GetName())
app/util/apiclient/dryrunclient.go:227:			fmt.Println("[dryrun] Attached object:")
app/util/apiclient/dryrunclient.go:235:		fmt.Fprintf(w, "[dryrun] Attached patch:\n\t%s\n", strings.Replace(string(patchAction.GetPatch()), `\"`, `"`, -1))
app/util/apiclient/dryrunclient_test.go:40:			expectedBytes: []byte(`[dryrun] Would perform action GET on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:41:[dryrun] Resource name: "kubernetes"
app/util/apiclient/dryrunclient_test.go:47:			expectedBytes: []byte(`[dryrun] Would perform action GET on resource "clusterrolebindings" in API group "rbac.authorization.k8s.io/v1"
app/util/apiclient/dryrunclient_test.go:48:[dryrun] Resource name: "system:node"
app/util/apiclient/dryrunclient_test.go:54:			expectedBytes: []byte(`[dryrun] Would perform action LIST on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:67:			expectedBytes: []byte(`[dryrun] Would perform action CREATE on resource "services" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:82:			expectedBytes: []byte(`[dryrun] Would perform action PATCH on resource "nodes" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:83:[dryrun] Resource name: "my-node"
app/util/apiclient/dryrunclient_test.go:84:[dryrun] Attached patch:
app/util/apiclient/dryrunclient_test.go:91:			expectedBytes: []byte(`[dryrun] Would perform action DELETE on resource "pods" in API group "core/v1"
app/util/apiclient/dryrunclient_test.go:92:[dryrun] Resource name: "my-pod"
app/util/apiclient/clientbacked_dryrun.go:132:		fmt.Println("[dryrun] The GET request didn't yield any result, the API Server returned a NotFound error.")
app/util/dryrun/dryrun.go:78:		fmt.Fprintf(w, "[dryrun] Would write file %q with content:\n", outputFilePath)
app/util/dryrun/dryrun.go:94:	fmt.Println("[dryrun] Would wait for the API Server's /healthz endpoint to return 'ok'")
app/util/dryrun/dryrun.go:100:	fmt.Printf("[dryrun] Would wait for the Pods with the label %q in the %s namespace to become Running\n", kvLabel, metav1.NamespaceSystem)
app/util/dryrun/dryrun.go:106:	fmt.Printf("[dryrun] Would wait for the %q Pod in the %s namespace to be deleted\n", podName, metav1.NamespaceSystem)
app/util/dryrun/dryrun.go:112:	fmt.Printf("[dryrun] Would make sure the kubelet %q endpoint is healthy\n", healthzEndpoint)
app/util/dryrun/dryrun.go:149:		fmt.Printf("[dryrun] Wrote certificates, kubeconfig files and control plane manifests to the %q directory\n", manifestDir)
app/util/dryrun/dryrun.go:156:		fmt.Printf("[dryrun] Wrote certificates and kubeconfig files to the %q directory\n", manifestDir)
app/util/dryrun/dryrun.go:159:	fmt.Println("[dryrun] The certificates or kubeconfig files would not be printed due to their sensitive nature")
app/util/dryrun/dryrun.go:160:	fmt.Printf("[dryrun] Please examine the %q directory for details about what would be written\n", manifestDir)
app/cmd/phases/join/controlplanejoin.go:139:		fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
app/cmd/phases/join/controlplanejoin.go:197:		fmt.Printf("[dryrun] Would mark node %s as a control-plane\n", cfg.NodeRegistration.Name)
app/cmd/phases/join/kubelet.go:173:		fmt.Println("[dryrun] Would stop the kubelet")
app/cmd/phases/join/kubelet.go:190:		fmt.Println("[dryrun] Would start the kubelet")
app/cmd/phases/upgrade/node/kubeletconfig.go:121:				fmt.Println("[dryrun] would update the node CRI socket path to include an URL scheme")
app/cmd/phases/init/etcd.go:96:				fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
app/cmd/upgrade/apply.go:173:		fmt.Println("[dryrun] Finished dryrunning successfully!")

but overall that does not seem like a big issue, i think we should keep only global dryrun utilities prefixed with [dryrun] such an utility is app/util/apiclient/dryrunclient.go and not sure what else qualifies.

i think having [reset] Would ... for this PR is fine.

I'm also in favor of your proposal. Would ... already indicates that the action is not actually performed, and using the prefix to reflect its execution phase will be better.

Copy link
Member

@neolit123 neolit123 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 Jan 14, 2022
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit 19a3702 into kubernetes:master Jan 14, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Jan 14, 2022
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/feature Categorizes issue or PR as related to a new feature. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubeadm reset: add support for dry-run
4 participants