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

πŸ› (kustomize/v1 and kustomize/v2-alpha) : ComponentConfig scaffolds should not be done by default #2826

Merged
merged 1 commit into from
Aug 5, 2022
Merged

Conversation

laxmikantbpandhare
Copy link
Member

@laxmikantbpandhare laxmikantbpandhare commented Jul 13, 2022

A description of the change

This PR will verify whether the --component-config flag is passed or not. If not then it will not scaffold out the controller_manager_config.yaml file.

The motivation for the change

it fixes #2782

Tests done to ensure the changes:

Init command ( without the --component-config flag)

From this PR:

laxmikantbhaskarpandhare@lpandhar-mac test % kubebuilder init --domain my.domain --repo my.domain/guestbook

Writing kustomize manifests for you to edit...
false
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.12.2
Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api
laxmikantbhaskarpandhare@lpandhar-mac test % tree
.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ PROJECT
β”œβ”€β”€ README.md
β”œβ”€β”€ config
β”‚Β Β  β”œβ”€β”€ default
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ manager_auth_proxy_patch.yaml
β”‚Β Β  β”‚Β Β  └── manager_config_patch.yaml
β”‚Β Β  β”œβ”€β”€ manager
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  └── manager.yaml
β”‚Β Β  β”œβ”€β”€ prometheus
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  └── monitor.yaml
β”‚Β Β  └── rbac
β”‚Β Β      β”œβ”€β”€ auth_proxy_client_clusterrole.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_role.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_role_binding.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_service.yaml
β”‚Β Β      β”œβ”€β”€ kustomization.yaml
β”‚Β Β      β”œβ”€β”€ leader_election_role.yaml
β”‚Β Β      β”œβ”€β”€ leader_election_role_binding.yaml
β”‚Β Β      β”œβ”€β”€ role_binding.yaml
β”‚Β Β      └── service_account.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ hack
β”‚Β Β  └── boilerplate.go.txt
└── main.go

6 directories, 24 files

Init command ( with the changes and passed the --component-config flag)

laxmikantbhaskarpandhare@lpandhar-mac testData % kubebuilder init --domain my.domain --repo my.domain/guestbook --component-config

Writing kustomize manifests for you to edit...
true
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.12.2
Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api
laxmikantbhaskarpandhare@lpandhar-mac testData % tree
.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ PROJECT
β”œβ”€β”€ README.md
β”œβ”€β”€ config
β”‚Β Β  β”œβ”€β”€ default
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ manager_auth_proxy_patch.yaml
β”‚Β Β  β”‚Β Β  └── manager_config_patch.yaml
β”‚Β Β  β”œβ”€β”€ manager
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ controller_manager_config.yaml
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  └── manager.yaml
β”‚Β Β  β”œβ”€β”€ prometheus
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kustomization.yaml
β”‚Β Β  β”‚Β Β  └── monitor.yaml
β”‚Β Β  └── rbac
β”‚Β Β      β”œβ”€β”€ auth_proxy_client_clusterrole.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_role.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_role_binding.yaml
β”‚Β Β      β”œβ”€β”€ auth_proxy_service.yaml
β”‚Β Β      β”œβ”€β”€ kustomization.yaml
β”‚Β Β      β”œβ”€β”€ leader_election_role.yaml
β”‚Β Β      β”œβ”€β”€ leader_election_role_binding.yaml
β”‚Β Β      β”œβ”€β”€ role_binding.yaml
β”‚Β Β      └── service_account.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ hack
β”‚Β Β  └── boilerplate.go.txt
└── main.go

6 directories, 25 files

This will verify that it is working, the controller_manager_config.yaml file got scaffolded only when a flag(--component-config) is passed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 13, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @laxmikantbpandhare. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 13, 2022
@laxmikantbpandhare
Copy link
Member Author

@camilamacedo86 - I verified the field --component-config and then scaffolded accordingly. I have a quick question, I did these changes in v1. Is there an expectation to do it in v2-alpha as well?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 13, 2022
@camilamacedo86
Copy link
Member

Hi @laxmikantbpandhare,

@camilamacedo86 - I verified the field --component-config and then scaffolded accordingly. I have a quick question, I did these changes in v1. Is there an expectation to do it in v2-alpha as well?

Terrific ! yes, we need to also fix the v2-alpha kustomize plugin.

@camilamacedo86
Copy link
Member

/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 Jul 14, 2022
@laxmikantbpandhare
Copy link
Member Author

Hi @laxmikantbpandhare,

@camilamacedo86 - I verified the field --component-config and then scaffolded accordingly. I have a quick question, I did these changes in v1. Is there an expectation to do it in v2-alpha as well?

Terrific ! yes, we need to also fix the v2-alpha kustomize plugin.

OK, I will update that too and then will do the squash of the commits.

@laxmikantbpandhare
Copy link
Member Author

laxmikantbpandhare commented Jul 14, 2022

@camilamacedo86 - I went through the tests that are failing and found that they are failing in kustomize build

It is because kustomization.yaml file as shown below, it required controller_manager_config.yaml file to be present. But as we did the change, that only allow that file to be generated when component-config got passed.

resources:
- manager.yaml

generatorOptions:
  disableNameSuffixHash: true

configMapGenerator:
- name: manager-config
  files:
  - controller_manager_config.yaml

The solution for this is, that I need to modify the test cases and enable the component-config field so that the controller_manager_config.yaml file will be generated WDYT?

@laxmikantbpandhare laxmikantbpandhare changed the title ✨ ComponentConfig scaffolds should not be done by default πŸ› ComponentConfig scaffolds should not be done by default Jul 19, 2022
@laxmikantbpandhare laxmikantbpandhare changed the title πŸ› ComponentConfig scaffolds should not be done by default πŸ› (kustomize/v1 and kustomize/v2-alpha) : ComponentConfig scaffolds should not be done by default Jul 19, 2022
@laxmikantbpandhare
Copy link
Member Author

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 19, 2022
@camilamacedo86
Copy link
Member

camilamacedo86 commented Jul 20, 2022

Hi @laxmikantbpandhare,

Regards the comment : #2826 (comment)

That means:

  • We should ONLY add to the default kustomization the content which is relevant to the component config when the flag is used (So we also need to address this one)
  • We also need to add this step to the documents for those that want to use the component-config on projects that were not init with the flag
  • We need to have a new test on the e2e tests for v3 and v4 that verifies a project scaffold with component-config

Could you look to address these needs? WDYT?

@laxmikantbpandhare
Copy link
Member Author

laxmikantbpandhare commented Jul 20, 2022

Hi @laxmikantbpandhare,

Regards the comment : #2826 (comment)

That means:

  • We should ONLY add to the default kustomization the content which is relevant to the component config when the flag is used (So we also need to address this one)
  • We also need to add this step to the documents for those that want to use the component-config on projects that were not init with the flag
  • We need to have a new test on the e2e tests for v3 and v4 that verifies a project scaffold with component-config

Could you look to address these needs? WDYT?

@camilamacedo86 - Got your point and agree with the suggestions. I will update the PR soon.

@SayakMukhopadhyay
Copy link

SayakMukhopadhyay commented Jul 21, 2022

Hi @camilamacedo86 I am trying to align my own project to incorporate these changes manually (since its already scaffolded). A clarification regarding the last comment which might be important for this PR too

We should ONLY add to the default kustomization the content which is relevant to the component config when the flag is used

Is the generatorOptions required when creating the project without the config flag. In other words, without the flag should the kustomization.yaml be

resources:
- manager.yaml

or

resources:
- manager.yaml

generatorOptions:
  disableNameSuffixHash: true

I am pretty sure that all of

configMapGenerator:
- name: manager-config
  files:
  - controller_manager_config.yaml

needs to be removed though.

Copy link

@SayakMukhopadhyay SayakMukhopadhyay left a comment

Choose a reason for hiding this comment

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

I dont know if this is something that you intend to fix but just thought to mention that the ManagerConfigPatch is also something that should depend on whether the config flag is pased or not. The generated patch is referencing the controller_manager_config.yaml which won't exist and is sure to confuse users.
https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/common/kustomize/v1/scaffolds/internal/templates/config/kdefault/manager_config_patch.go

Also notice how the kustomize.yaml referencing the above patch is commenting out the line to include the patch

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
{{ if not .ComponentConfig }}#{{ end }}- manager_config_patch.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml

pkg/plugins/common/kustomize/v1/scaffolds/init.go Outdated Show resolved Hide resolved
pkg/plugins/common/kustomize/v2-alpha/scaffolds/init.go Outdated Show resolved Hide resolved
@laxmikantbpandhare
Copy link
Member Author

laxmikantbpandhare commented Jul 21, 2022

Hi @camilamacedo86 I am trying to align my own project to incorporate these changes manually (since its already scaffolded). A clarification regarding the last comment which might be important for this PR too

We should ONLY add to the default kustomization the content which is relevant to the component config when the flag is used

Is the generatorOptions required when creating the project without the config flag. In other words, without the flag should the kustomization.yaml be

resources:
- manager.yaml

or

resources:
- manager.yaml

generatorOptions:
  disableNameSuffixHash: true

I am pretty sure that all of

configMapGenerator:
- name: manager-config
  files:
  - controller_manager_config.yaml

needs to be removed though.

Yes, you are correct.

We are removing the below completely.

configMapGenerator:
- name: manager-config
  files:
  - controller_manager_config.yaml

I will update the PR soon.

@laxmikantbpandhare
Copy link
Member Author

laxmikantbpandhare commented Aug 5, 2022

@SayakMukhopadhyay @camilamacedo86 - Updated the PR with the new changes that we discussed for default/kustomization.yaml scaffolding. Could you please review once.

@SayakMukhopadhyay
Copy link

SayakMukhopadhyay commented Aug 5, 2022

@laxmikantbpandhare please correct me if I am wrong, from what I understand, if the ComponentConfig is disabled
instead of

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml

the resultant section of the kustomization.yaml would be

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@laxmikantbpandhare very nice work.
Just a few nits and could you please squash the commits?

@laxmikantbpandhare
Copy link
Member Author

@laxmikantbpandhare please correct me if I am wrong, from what I understand, if the ComponentConfig is disabled instead of

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml

the resultant section of the kustomization.yaml would be

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type

@SayakMukhopadhyay Yes, I will remove those comments as well.

@laxmikantbpandhare
Copy link
Member Author

@laxmikantbpandhare very nice work. Just a few nits and could you please squash the commits?

Sure @camilamacedo86

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Great πŸ₯‡

/approved

In a follow up we need to create a plugin that does this config.
Then, we might also implement the edit subcommand to do the required changes

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2022
@camilamacedo86 camilamacedo86 requested review from everettraven and removed request for joelanford August 5, 2022 10:24
@laxmikantbpandhare
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-19-16

@laxmikantbpandhare
Copy link
Member Author

Great πŸ₯‡

/approved

In a follow up we need to create a plugin that does this config. Then, we might also implement the edit subcommand to do the required changes

Yes @camilamacedo86, I will work on those as well.

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Just a couple minor nits from me. Other than that it looks great! Great work @laxmikantbpandhare !

docs/book/src/component-config-tutorial/api-changes.md Outdated Show resolved Hide resolved
pkg/plugins/common/kustomize/v1/scaffolds/init.go Outdated Show resolved Hide resolved
pkg/plugins/common/kustomize/v2-alpha/scaffolds/init.go Outdated Show resolved Hide resolved
updated testdata

update v2-alpha and modified tests and added component-confit flag in it

modified tests and enables componenet config flag

removed unnecessary addition componenent config flag in v2 whenre this flag is not available

removed for tests

modified kustomization.yml file

modified testdata

added end to end tests with component config field marked as true

line length is more than 122 characters

mis spell

updated doc

modified docs

modified docs

modified default kustomization file too

updated scaffold condition

worked on review comments

updated according to code review comments
Copy link
Contributor

@everettraven everettraven 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 Aug 5, 2022
@k8s-ci-robot k8s-ci-robot merged commit 20828c7 into kubernetes-sigs:master Aug 5, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, everettraven, laxmikantbpandhare

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

@everettraven
Copy link
Contributor

Oops, I forgot that an LGTM on this repo auto merges.

@camilamacedo86 is it okay that this has merged?

@laxmikantbpandhare
Copy link
Member Author

Oops, I forgot that an LGTM on this repo auto merges.

@camilamacedo86 is it okay that this has merged?

No worries, thanks for your comments.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meta - ComponentConfig scaffolds should not be done by default
5 participants