-
Notifications
You must be signed in to change notification settings - Fork 39.7k
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: refactor the dry-run logic #126776
kubeadm: refactor the dry-run logic #126776
Conversation
/triage accepted |
174edd6
to
451fa49
Compare
451fa49
to
f277228
Compare
f277228
to
7dc40c5
Compare
/retitle kubeadm: refactor the dry-run logic this is ready for review |
@@ -176,7 +176,7 @@ func resetConfigDir(configPathDir string, dirsToClean []string, isDryRun bool) { | |||
} | |||
} | |||
} else { | |||
fmt.Printf("[reset] Would delete files: %v\n", filesToClean) | |||
fmt.Printf("[dryrun] Would delete files: %v\n", filesToClean) |
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 file path be quoted using %q?
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.
filesToClean is a slice of strings, so that's why here is %v
5b0a316
to
47f4232
Compare
updated |
/lgtm |
LGTM label has been added. Git tree hash: bc73c16edff62f82ad6ed983f48d13f07018621a
|
/lgtm |
objBytes, err := d.marshalFunc(obj, gv) | ||
if err == nil { | ||
fmt.Fprintln(d.writer, "[dryrun] Attached object:") | ||
fmt.Fprintf(d.writer, "%s", objBytes) |
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.
Don't we need to use fmt.Fprinln()
here?
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.
changed to:
fmt.Fprintln(d.writer, string(objBytes))
NVM, i missed your review above. |
47f4232
to
693d4b3
Compare
@SataQiu updated. |
The current dryrun client implemnetation is suboptimal and sparse. It has the following problems: - When an object CREATE or UPDATE reaches the default dryrun client the operation is a NO-OP, which means subsequent GET calls must fully emulate the object that exists in the store. - There are multiple implmentations of a DryRunGetter interface such the one in init_dryrun.go but there are no implementations for reset, upgrade, join. - There is a specific DryRunGetter that is backed by a real client in clientbacked_dryrun.go, but this is used for upgrade and does not work in conjuction with a fake client. This commit does the following changes: - Removes all existing *dryrun*.go implementations. - Add a new DryRun implementation in dryrun.go that implements 3 clients - fake clientset, real clientset, real dynamic client. - The DryRun object uses the method chaining pattern. - Allows the user opt-in into real clients only if needed, by passing a real kubeconfig. By default only constructs a fake client. - The default reactor chain for the fake client, always logs the object action, then for GET or LIST actions attempts to use the real dynamic client to get the object. If a real object does not exist it attempts to get the object from the fake object store. - The user can prepend or append reactors to the chain. - All known needed reactors for operations during init, join, reset, upgrade are added as methods of the DryRun struct. - Adds detailed unit test for the DryRun struct and its methods including reactors. Additional changes: - Use the new DryRun implementation in all command workflows - init, join, reset, upgrade. - Ensure that --dry-run works even if there is no active cluster by returning faked objects. For join, a faked cluster-info with a fake bootstrap token and CA are used.
693d4b3
to
30f9893
Compare
/lgtm |
LGTM label has been added. Git tree hash: 9f3c027fa029ac074dfd473646137e1ee4e369c6
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: neolit123, pacoxu 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 |
/hold cancel |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
The current dryrun client implemnetation is suboptimal
and sparse. It has the following problems:
the operation is a NO-OP, which means subsequent GET calls must
fully emulate the object that exists in the store.
such the one in init_dryrun.go but there are no implementations
for reset, upgrade, join.
client in clientbacked_dryrun.go, but this is used for upgrade
and does not work in conjuction with a fake client.
This commit does the following changes:
3 clients - fake clientset, real clientset, real dynamic client.
a real kubeconfig. By default only constructs a fake client.
object action, then for GET or LIST actions attempts to use the
real dynamic client to get the object. If a real object does not
exist it attempts to get the object from the fake object store.
reset, upgrade are added as methods of the DryRun struct.
including reactors.
Additional changes:
init, join, reset, upgrade.
by returning faked objects. For join, a faked cluster-info
with a fake bootstrap token and CA are used.
Which issue(s) this PR fixes:
Fixes kubernetes/kubeadm#2653
Fixes kubernetes/kubeadm#1932
Special notes for your reviewer:
NONE
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: