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

Enable kustomize in kubectl #70875

Merged
merged 7 commits into from Dec 19, 2018

Conversation

Liujingfang1
Copy link
Contributor

@Liujingfang1 Liujingfang1 commented Nov 9, 2018

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR is the implementation of KEP to enable kustomize in kubectl.

When -f <dir> is passed to a kubectl command, it will look for a kustomization.yaml file. If kustomization.yaml is found, a kustomize build will be run to get the list of expanded resources. This list of resources is then passed to kubectl commands. If there is no kustomization.yaml in the directory, kubectl will behave the same as current.

To apply a kustomization directory

kubectl apply -f <dir>

To get resources of a kustomization directory applied to a cluster

kubectl get -f <dir>

To delete a kustomization directory applied to a cluster

kubectl delete -f <dir>

Special notes for your reviewer:

This PR contains 6 commits.

  • The first three of them is to vendor kustomize.
  • The 4th commit is the change in resource builder to use Kustomization when it it enabled.
  • The 5th one adds some unit test for Builder.
  • The 6th commit is to enable kustomization in kubectl commands.

Kubectl will have kustomization enabled by default.
Other cli-runtime consumers may choose if they want to enable or not kustomization by a Boolean variable.

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

Enable customize in kubectl: kubectl will be able to recognize directories with kustomization.YAML

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/XXL Denotes a PR that changes 1000+ 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 Nov 9, 2018
@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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 9, 2018
@Liujingfang1
Copy link
Contributor Author

/cc @pwittrock @soltysh @seans3

@Liujingfang1
Copy link
Contributor Author

/cc @monopole

@Liujingfang1 Liujingfang1 changed the title Enable kustomize Enable kustomize in kubectl Nov 9, 2018
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 10, 2018
@@ -452,7 +457,10 @@ func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, ext
if err != nil {
return err
}

if isKustomizationDir(path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is backwards compatible. Anyone using kubectl create -f DIR will see something different happen after this change lands, which means existing CLI workflows could break.

Copy link
Member

Choose a reason for hiding this comment

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

I just tested the behaviour. kubectl create and kubectl apply both fail with a kustomization.yaml present:

error: error validating ".../k8s.io/examples/guestbook-go/kustomization.yaml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false

It looks like we have a separate issue, which is that we don't validate all files before starting to apply, which is contrary to what I would have expected.

But I don't think users can be using kubectl create -f DIR or kubectl apply -f DIR today with a dir containing kustomization.yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarterclayton The existing kubectl doesn't work with directories with a kustomization.yaml as @justinsb explained. With this PR, kubectl will be able to recognize a directory with a kustomization.yaml. For any directories without kustomization.yaml, there is no change in kubectl's behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

If someone has validate=false off, what happens? If it also fails, then my primary concern is addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With validate=false, it fails with similar error

error: unable to decode "kustomization.yaml": Object 'Kind' is missing in `<truncated>`

@Liujingfang1 Liujingfang1 force-pushed the enable-kustomize branch 2 times, most recently from a401eca to b426d83 Compare November 12, 2018 21:46
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 12, 2018
@seans3
Copy link
Contributor

seans3 commented Nov 12, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 12, 2018
@Liujingfang1 Liujingfang1 force-pushed the enable-kustomize branch 2 times, most recently from 90bac14 to 3c4901b Compare November 12, 2018 23:56
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 16, 2018
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 17, 2018
@Liujingfang1
Copy link
Contributor Author

As discussed offline, we can remove the opt out. I added a commit for that. @pwittrock PTAL

@Liujingfang1
Copy link
Contributor Author

/retest

2 similar comments
@Liujingfang1
Copy link
Contributor Author

/retest

@Liujingfang1
Copy link
Contributor Author

/retest

@BenTheElder
Copy link
Member

/test pull-kubernetes-godeps

@@ -463,7 +471,10 @@ func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, ext
if path != paths && ignoreFile(path, extensions) {
return nil
}

if filepath.Base(path) == constants.KustomizationFileName {
Copy link
Member

Choose a reason for hiding this comment

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

This will be changed to check the GVK of the kustomization file in an immediate follow up.

fSys := fs.MakeRealFS()
f := k8sdeps.NewFactory()
var out bytes.Buffer
cmd := build.NewCmdBuild(&out, fSys, f.ResmapF, f.TransformerF)
Copy link
Member

Choose a reason for hiding this comment

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

In an immediate follow up this should be a library that takes options.

@pwittrock
Copy link
Member

/approve

@pwittrock
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 Dec 18, 2018
@pwittrock
Copy link
Member

Follow up issues tracked here:
kubernetes/kubectl#570

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@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 Dec 18, 2018
@pwittrock
Copy link
Member

@soltysh removing hold. @JiangtianLi is working on a follow up.

@Liujingfang1
Copy link
Contributor Author

/test pull-kubernetes-integration

@pwittrock
Copy link
Member

/test

@pwittrock
Copy link
Member

/test pull-kubernetes-e2e-gce

@anguslees
Copy link
Member

anguslees commented Jan 11, 2019

I'm only just learning about kustomize, but I am a bit alarmed about what I'm reading and the implications for this PR. With this PR, can I just pwn the world by putting a malicious kustomize.yaml in a popular manifest examples site somewhere?

Consider:

# kustomize.yaml - don't try this at home.
secretGenerator:
- name: allyourbase
  commands:
    # or any other malicious command
    foo: "echo backdoorkey >> $HOME/.ssh/authorized_keys"

In particular, with this PR, I think kubectl apply -f http://that/repo" suddenly becomes able to modify the local machine, not just the target cluster, even with --dry-run.

@BenTheElder
Copy link
Member

BenTheElder commented Jan 11, 2019 via email

@pwittrock
Copy link
Member

Discussion of changes to the UX integration were raised and are being talked through in kubernetes/kubectl#570. The outcome of those discussions will be folded into the KEP before reintegrating: kubernetes/enhancements#684

Additionally there were some security concerns raised that require changes, such as limiting process callouts: kubernetes-sigs/kustomize#683. The new capabilities added by kustomize will be reviewed from a security perspective prior to reintegration.

PR to revert: #72805

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/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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet