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

Switch from arguments to an input structure for kubectl command #106159

Merged
merged 2 commits into from
Nov 12, 2021

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Nov 4, 2021

What type of PR is this?

/kind cleanup
/priority backlog
/sig cli

What this PR does / why we need it:

This PR:

  1. introduces new WithWrapConfigFn function allowing to provider a wrapper for client config
  2. switches kubectl from using multiple arguments to using a structure when constructing kubectl command.

This is alternative to #104926

Special notes for your reviewer:

/assign @eddiezane
/cc @dovholuknf

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/cli Categorizes an issue or PR as relevant to SIG CLI. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 4, 2021
@soltysh
Copy link
Contributor Author

soltysh commented Nov 4, 2021

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. area/kubectl approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 4, 2021
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 4, 2021
@soltysh
Copy link
Contributor Author

soltysh commented Nov 4, 2021

/assign @dims
for cmd approval

@dovholuknf
Copy link

I am happy to confirm that these changes, from the outside consumer point of view, are exactly what's needed by me. works perfectly and simplifies our code too as well as making the api cleaner.

@soltysh
Copy link
Contributor Author

soltysh commented Nov 4, 2021

/hold
it looks like this PR breaks -v6 I'll dig into it

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 4, 2021
Comment on lines +392 to +395
func (f *ConfigFlags) WithWrapConfigFn(wrapConfigFn func(*rest.Config) *rest.Config) *ConfigFlags {
f.WrapConfigFn = wrapConfigFn
return f
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to allow chaining of these functions? This is really what I meant when I said this should be a slice.

func main() {
	flags := genericclioptions.NewConfigFlags(false)
	flags = flags.WithWrapConfigFn(func(config *rest.Config) *rest.Config {
		fmt.Println("wrap 1")
		return config
	})
	flags = flags.WithWrapConfigFn(func(config *rest.Config) *rest.Config {
		fmt.Println("wrap 2")
		return config
	})
	flags.ToRESTConfig()
}

// wrap 2
// wrap 1
// Unsure of the order we'd want here.

Or am I missing something here?

Suggested change
func (f *ConfigFlags) WithWrapConfigFn(wrapConfigFn func(*rest.Config) *rest.Config) *ConfigFlags {
f.WrapConfigFn = wrapConfigFn
return f
}
func (f *ConfigFlags) WithWrapConfigFn(wrapConfigFn func(*rest.Config) *rest.Config) *ConfigFlags {
if f.WrapConfigFn == nil {
f.WrapConfigFn = wrapConfigFn
} else {
old := f.WrapConfigFn
f.WrapConfigFn = func(config *rest.Config) *rest.Config {
return old(wrapConfigFn(config))
}
}
return f
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since WrapConfigFn both accepts and returns *rest.Config you can chain then together on your own, and pass that into WithWrapConfigFn that's why I don't think we need or want to make this a slice.

@dovholuknf
Copy link

fwiw, for me the change that broke the -v6 flag was due to how the command is executed. prior it was simply created from the factory and then executed. now for -v6 to function one needs to to invoke the command using cli.Run. the default kubectl.go file was updated already and works fine.

I adapted my code to use cli.Run and I can confirm -v6 works for me.

@soltysh
Copy link
Contributor Author

soltysh commented Nov 4, 2021

/hold cancel
the problem was elsewhere

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 4, 2021
@eddiezane
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2021
@dims
Copy link
Member

dims commented Nov 9, 2021

the cmd/ changes are straight forward and LGTM

/approve
/lgtm

@eddiezane
Copy link
Member

/assign @lavalamp

@dims
Copy link
Member

dims commented Nov 12, 2021

/assign @thockin @liggitt

for /cmd approval (looks like we are light on approvers, gonna add myself)

@dims
Copy link
Member

dims commented Nov 12, 2021

/approve
/lgtm

(for the record)

@smarterclayton
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, eddiezane, smarterclayton, soltysh

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 Nov 12, 2021
@k8s-ci-robot k8s-ci-robot merged commit 763916a into kubernetes:master Nov 12, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Nov 12, 2021
@soltysh soltysh deleted the config_wrapper branch November 16, 2021 11:40
@soltysh
Copy link
Contributor Author

soltysh commented Nov 16, 2021

for /cmd approval (looks like we are light on approvers, gonna add myself)

I've went ahead and added cli-maintaners for the missing bits in #106451

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/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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-none Denotes a PR that doesn't merit a release note. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

None yet

9 participants