kubernetes-sigs / kubebuilder-declarative-pattern

A toolkit for building declarative operators with kubebuilder
Apache License 2.0
254 stars 84 forks source link

Opt-out the kustomize feature via go build tags #299

Closed yuwenma closed 1 year ago

yuwenma commented 1 year ago

Problems:

Description:

This PR split the kustomize hydration to 1. a generic kustomize build and 2. a no-op in different files; It adds a go build constraint without_kustomize to give users the ability to switch to opt out the kustomize feature in build time and no need to change their source code.

Test: This PR is tested using the guestbook example by changing the make run for the following two cases

  1. Preserve existing feature
    make run

output

2023-01-27T23:29:57-08:00   INFO    running kustomize   {"controller": "guestbook-controller", "object": {"name":"guestbook-sample","namespace":"default"}, "namespace": "default", "name": "guestbook-sample", "reconcileID": "fbcb7051-36c0-4358-aafc-5c84c6b96e2a", "kustomizer": "EnabledKustomize"}
  1. Skip kustomize
    # Makefile
    run: manifests generate fmt vet ## Run a controller from your host.
    go run -tags without_kustomize ./main.go
    make run

output

2023-01-27T23:38:37-08:00   INFO    skip running kustomize  {"controller": "guestbook-controller", "object": {"name":"guestbook-sample","namespace":"default"}, "namespace": "default", "name": "guestbook-sample", "reconcileID": "38da0981-8143-43e5-96a4-7e551018758f", "kustomizer": "SkipKustomize"}

UPDATED

go run -tags without_kustomize ./main.go

...
2023-01-28T23:16:16-08:00   ERROR   building deployment objects {"controller": "guestbook-controller", "object": {"name":"guestbook-sample","namespace":"default"}, "namespace": "default", "name": "guestbook-sample", "reconcileID": "b62ee9fb-be37-4094-9bb7-c3cce756c03e", "error": "error running kustomize: kustomize support is not compiled in (built with tag `without_kustomize`)"}
go run ./main.go

2023-01-28T23:19:46-08:00   INFO    running kustomize   {"controller": "guestbook-controller", "object": {"name":"guestbook-sample","namespace":"default"}, "namespace": "default", "name": "guestbook-sample", "reconcileID": "eb7c1f04-771e-45a1-b44f-d1b451357d46", "manifestPath": "channels/packages/guestbook/0.0.1"}
yuwenma commented 1 year ago

/assign @justinsb

justinsb commented 1 year ago

Thanks @yuwenma!

/approve /lgtm

k8s-ci-robot commented 1 year ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, yuwenma

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: - ~~[OWNERS](https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/OWNERS)~~ [justinsb] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
atoato88 commented 1 year ago

LGTM :smile: Should we add documentation about without_kustomize tag?

yuwenma commented 1 year ago

@atoato88 that's a good idea. I updated the doc here https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/pull/301 Please let me know if there's anywhere else I shall update.