Skip to content

internal/plugins: Add kustomize as a prerequisite of Makefile's bundle target #4090

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

Conversation

miguelsorianod
Copy link
Contributor

@miguelsorianod miguelsorianod commented Oct 22, 2020

Description of the change:

bundle target in the autogenerated Makefile for new golang based operator projects generated
by the operator-sdk make use of the kustomize CLI tool. This commit adds the kustomize Makefile
target as a prerequisite of the bundle target.

Motivation for the change:

When running make bundle an error is returned if kustomize is not previously installed in $PATH.

Execution example:

msoriano@localhost:~/go/src/github.com/3scale/apicast-operator (update-operator-sdk-to-110)$ make bundle
which: no kustomize in (/home/msoriano/.rbenv/shims:/home/msoriano/.rbenv/bin:/home/msoriano/.nvm/versions/node/v10.21.0/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/msoriano/.local/bin:/home/msoriano/bin:/usr/local/go/bin:/home/msoriano/go/bin)
/home/msoriano/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
operator-sdk-v1.1.0 generate kustomize manifests -q
cd config/manager && /home/msoriano/go/bin/kustomize edit set image controller=controller:latest
/bin/bash: /home/msoriano/go/bin/kustomize: No such file or directory
make: *** [Makefile:126: bundle] Error 127

Checklist

If the pull request includes user-facing changes, extra documentation is required:

@miguelsorianod
Copy link
Contributor Author

Hi,

I've also added a new separate commit containing a changelog fragment. If you see it ok and you want me to squash it just tell me.

Let me know if there's something else I might be missing.

Thank you.

@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from ddd4f07 to f93eee1 Compare October 22, 2020 18:59
# Migration can be defined to automatically add a section to
# the migration guide. This is required for breaking changes.
migration:
header: (Golang based operators) Update Makefile's bundle task
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
header: (Golang based operators) Update Makefile's bundle task
header: (Golang based operators) Update Makefile's bundle target

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment on lines 25 to 26
In the `Makefile` file add the `kustomize` target as
a prerequisite of the `bundle` target.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In the `Makefile` file add the `kustomize` target as
a prerequisite of the `bundle` target.
In the `Makefile` file, replace `bundle: manifests` with `bundle: manifests kustomize` to call
the kustomize target when the `bundle` target is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment on lines 5 to 7
Add `kustomize` as a prerequiste target of the `bundle`
target in the autogenerated Makefile on Golang based
operator projects.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Add `kustomize` as a prerequiste target of the `bundle`
target in the autogenerated Makefile on Golang based
operator projects.
For Golang based operators, fix an error faced when the [kustomize](https://kubernetes-sigs.github.io/kustomize/) is not installed locally and the Makefile target `bundle` is used by adding the kustomize target on 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.

Changed. Instead of when the kustomize is not installed locally... I've written when the kustomize binary is not installed locally...

Copy link
Contributor

@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.

It shows fine for me. Just some nits.
However, @estroz wdyt ?

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2020
@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from f93eee1 to 0f0271d Compare October 22, 2020 19:23
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2020
@miguelsorianod
Copy link
Contributor Author

Do you want me to squash the changelog fragment commit into the other commit?

@estroz
Copy link
Member

estroz commented Oct 22, 2020

You can also remove the explicit make kustomize from our samples generators: here, here, and here. All make targets that require kustomize should call it as a dependency, so a samples generator should error out if one does not.

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

One nit and I'd like to see the samples generator updated so we know this change works as intended.

Comment on lines 5 to 8
For Golang based operators, fix an error faced when the
[kustomize](https://kubernetes-sigs.github.io/kustomize/)
binary is not installed locally and the Makefile target
`bundle` is used by adding the kustomize target on it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For Golang based operators, fix an error faced when the
[kustomize](https://kubernetes-sigs.github.io/kustomize/)
binary is not installed locally and the Makefile target
`bundle` is used by adding the kustomize target on it.
Added the `kustomize` make dependency to the `bundle` target scaffolded
for Golang projects to install `kustomize` before running.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 changed. However, take into account that the previous text was suggested by @camilamacedo86, so, whatever you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that we had defined the standard of For Golang based operators, For Helm based operators and etc ...
However, it is fine 👍 I am ok with the new wording suggested by @estroz as well.

@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from 0f0271d to 489ea48 Compare October 22, 2020 20:37
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2020
@miguelsorianod
Copy link
Contributor Author

miguelsorianod commented Oct 22, 2020

Hi,

You can also remove the explicit make kustomize from our samples generators: here, here, and here. All make targets that require kustomize should call it as a dependency, so a samples generator should error out if one does not.

If I'm understanding correctly, we can now remove the explicit call to the kustomize Makefile target in the sample generators code due to we've added the kustomize target as a prerequisite of the bundle target, and this target is indirectly called through the method RunOlmIntegration (defined in hack/generate/samples/internal/pkg/utils.go) that is called for all of the operator types (Go, Ansible, Helm).

I've applied the changes to remove those explicit calls.

In the case of Ansible and Helm the kustomize target was already a prerequisite of the bundle target Makefile so I understand those explicit calls in those generators could already have been removed from the samples generator code without the changes in this PR

I've done the following to verify the newer changes:

  1. Remove the kustomize binary from my $PATH
  2. Execute make generate
  3. Verify that no changes have been applied in the testdata directory.

Also, to verify that the order in which the generators are run doesn't affect the execution I've executed the generation of each sample generator individually by temporarily commenting code for the others in hack/generate/samples/generate_all.go.

Additionally, interestingly enough, I've observed that Ansible and Helm generators install the kustomize binary in the bin directory relative to the corresponding sample project. However, with Go that's not the case. In Go's case it is installed in $GOBIN/kustomize. Is that intentional for some reason?

As you can see, the kustomize target in Go's generated Makefile (testdata/go/memcached-operator/Makefile) is:

kustomize:
ifeq (, $(shell which kustomize))
  @{ \
  set -e ;\
  KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
  cd $$KUSTOMIZE_GEN_TMP_DIR ;\
  go mod init tmp ;\
  go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
  rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
  }
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

Whereas for Ansible (testdata/ansible/memcached-operator/Makefile) and Helm (testdata/helm/memcached-operator/Makefile) is:

kustomize:
ifeq (, $(shell which kustomize 2>/dev/null))
  @{ \
  set -e ;\
  mkdir -p bin ;\
  curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\
  }
KUSTOMIZE=$(realpath ./bin/kustomize)
else
KUSTOMIZE=$(shell which kustomize)
endif

Notice the difference in how it is installed.

@estroz
Copy link
Member

estroz commented Oct 22, 2020

In Go's case it is installed in $GOBIN/kustomize. Is that intentional for some reason

If you're asking if Go projects need to install kustomize differently, then no. I'd like to see the non-go get download method implemented in the Go plugin upstream (related issue: kubernetes-sigs/kubebuilder#1351).

Copy link
Contributor

@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.

@miguelsorianod
Copy link
Contributor Author

Regarding the binary location: I've taken a look at the related issue and I've found the following PR too kubernetes-sigs/kubebuilder#1711
Is that PR related to the issue?

If I can help somehow with this tell me. I'd be happy to contribute.

Thanks.

@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from 489ea48 to cbd1d56 Compare October 23, 2020 11:04
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2020
@miguelsorianod
Copy link
Contributor Author

I've force-pushed content to reexecute tests, as continuous-integration/travis-ci/pr failed on the e2e tests for some reason. I executed them locally with make test-e2e-go and they've run successfully.

@miguelsorianod
Copy link
Contributor Author

miguelsorianod commented Oct 23, 2020

It seems travis tests failed again, but now on the ansible e2e test:

0.04s$ travis_setup_go

gimme: given '1.15.x' but no release for '1.15' found

gimme: given '1.15.x' but no release for '1.15' found

Failed to run gimme

The command "travis_setup_go" failed and exited with 86 during .

Force-pushed again to reexecute tests

@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from cbd1d56 to 2ed4ac7 Compare October 23, 2020 12:33
@camilamacedo86
Copy link
Contributor

Hi @miguelsorianod,

Could you please rebase your PR with master and push it? Also, if some job Travis fails that has no relation with the changes in your PR not worry it is a flake and we can re-stat the specific job to get this merged. If you need please feel free to ping me in the slack as well.

…e target

`bundle` target in the autogenerated Makefile for new golang based operator projects generated
by the operator-sdk make use of the `kustomize` CLI tool. This commit adds the `kustomize` Makefile
target as a prerequisite of the `bundle` target.
…arget

It is not needed anymore due to `make bundle` target already contains
the `kustomize` target as a prerequisite.
@miguelsorianod miguelsorianod force-pushed the add-missing-makefile-bundle-prerequisite branch from 2ed4ac7 to 8c9989f Compare October 23, 2020 12:49
@miguelsorianod
Copy link
Contributor Author

Rebased and pushed

@estroz estroz merged commit 33e37ef into operator-framework:master Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants