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

add -k flag in cli-runtime and kubectl to process kustomization directories #74140

Merged
merged 7 commits into from
Feb 27, 2019

Conversation

Liujingfang1
Copy link
Contributor

@Liujingfang1 Liujingfang1 commented Feb 15, 2019

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR implements the 2nd Customize integration KEP

Which issue(s) this PR fixes:
Fixes kubernetes/enhancements#633

Special notes for your reviewer:
This PR adds -k flag into FilenameFlags in cli-runtime.
Kubectl consumes FilenameFlags in different sub commands.

Does this PR introduce a user-facing change?:
yes

The examples in kubectl apply/get/delete are updated to support `-k` which uses a `kustomization.yaml` file

@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. 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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 15, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @Liujingfang1. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 15, 2019
@Liujingfang1
Copy link
Contributor Author

Liujingfang1 commented Feb 15, 2019

/sig-cli
/assign @pwittrock @seans3 @liggitt @monopole

pkg/kubectl/cmd/apply/apply.go Outdated Show resolved Hide resolved
Recursive bool
}

func (o *FilenameOptions) Validate() error {
if len(o.Filenames) > 0 && len(o.Kustomize) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

it's likely many FilenameOptions/Builder users will not call this new method. should this validation go into Builder#FilenameParam and append to Builder#errs instead?

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 added two functions to FilenameOptions: Validate() and IsSourceEmpty().

Validate() is to make sure there is no -f and -k conflicts. This function is needed wherever FilenameOptions is used. So it makes sense to move it into Builder#FilenameParam.

IsSourceEmpty() is to check both -f and -k are not set. This is used to make sure at least one of -f and -k is specified. There are subcommands such as apply. Previously, -f is required in those subcommands. So we need to change them to require one of -f and -k.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validate now is triggered inside FilenameParam function. In addition, I renamed IsSourceEmpty() to RequireFilenameOrKustomize.

@k8s-ci-robot k8s-ci-robot added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Feb 19, 2019
@Liujingfang1
Copy link
Contributor Author

/assign @soltysh @monopole

@Liujingfang1
Copy link
Contributor Author

By this change, -k is added to all kubectl subcommands that are with a -f flag. Does it make sense? Do we need to restrict -k to a smaller set of subcommands?


return &DeleteFlags{
FileNameFlags: &genericclioptions.FileNameFlags{Usage: usage, Filenames: &filenames, Recursive: &recursive},
FileNameFlags: &genericclioptions.FileNameFlags{Usage: usage, Filenames: &filenames, Kustomize: &kustomize, Recursive: &recursive},
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this use the helpers.go? We should at least document 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.

DeleteFlags composes common flag struct used for commands requiring deletion logic, such as kubectl delete and kubectl apply. It contains FileNameFlags, which is then converted to FileNameOptions.

While in other subcommand options, FileNameOptions is directly used instead of FileNameFlags. helpers.go contains functions to add -k and -f for FileNameOptions, but not for FileNameFlags.

In the future, I think the logic of adding flags should be moved to cli-runtime. Do we convert all current FileNameOptions to FileNameFlags or keep both of them? I'm not sure. @juanvallejo What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment to this code explaining why it doesn't use helpers.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about

// Not using helpers.go it since provides function to add '-k' for FileNameOptions, but not FileNameFlags

@@ -103,11 +103,6 @@ func NewCmdCreate(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cob
Long: createLong,
Example: createExample,
Run: func(cmd *cobra.Command, args []string) {
if cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to keep printing the helper message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can keep it. The change would be like

if cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames, o.FilenameOptions.Kustomize) {
	ioStreams.ErrOut.Write([]byte("Error: must specify one of -f and -k\n\n"))
	defaultRunFunc := cmdutil.DefaultSubCommandRun(ioStreams.ErrOut)
	defaultRunFunc(cmd, args)
	return
}

Copy link
Member

Choose a reason for hiding this comment

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

SGTM. If we want to change this behavior in the future it should be a separate discussion.

@@ -223,6 +223,21 @@ __EOF__
# cleanup
kubectl delete -f hack/testdata/service-revision2.yaml "${kube_flags[@]}"

## kubectl apply -k somedir
kubectl apply -k hack/testdata/kustomize
Copy link
Member

Choose a reason for hiding this comment

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

lets add a test for every command that supports this if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about adding tests to the existing test files for apply, diff, create, delete, get?

Copy link
Member

Choose a reason for hiding this comment

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

+1

@@ -115,6 +115,9 @@ var (
# Apply the configuration in pod.json to a pod.
kubectl apply -f ./pod.json

# Apply resources from a directory containing kustomization.yaml.
Copy link
Member

Choose a reason for hiding this comment

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

# Apply resources from a directory containing kustomization.yaml. - e.g. dir/kustomization.yaml
kubectl apply -k dir/

@pwittrock
Copy link
Member

/ok-to-test

@pwittrock
Copy link
Member

/retest

directory: "../../../artifacts/kustomization/should-not-load.yaml",
expectErr: true,
errMsg: "must be a directory to be a root",
},
Copy link
Member

Choose a reason for hiding this comment

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

Add an error for specifying the kustomization file directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added one test with

directory: filepath.Join(dir, "kustomization.yaml"),

@Liujingfang1
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce

@pwittrock
Copy link
Member

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2019
@pwittrock
Copy link
Member

/lgtm
/approve

@pwittrock
Copy link
Member

pwittrock commented Feb 27, 2019

/hold

Added hold for @apelisse

@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 Feb 27, 2019
@pwittrock
Copy link
Member

/unassign @soltysh
/unassign @monopole
/unassign @seans3

@apelisse
Copy link
Member

/approve

@pwittrock
Copy link
Member

pwittrock commented Feb 27, 2019

/assign @dims

For staging/publishing

@dims
Copy link
Member

dims commented Feb 27, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, dims, Liujingfang1, pwittrock

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 Feb 27, 2019
@pwittrock
Copy link
Member

/hold cancel

@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 Feb 27, 2019
@k8s-ci-robot k8s-ci-robot merged commit 81e6407 into kubernetes:master Feb 27, 2019
@liggitt liggitt added this to the v1.14 milestone Jun 10, 2019
@liggitt liggitt removed the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Feb 18, 2020
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 area/release-eng Issues or PRs related to the Release Engineering subproject 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

integrate Kustomize into kubectl
9 participants