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

[th/make-generate-tidy] makefile: run go mod tidy during make generate #204

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

thom311
Copy link
Contributor

@thom311 thom311 commented Nov 5, 2024

We have multiple go.mod files, this does not seem to agree with operator-sdk. operator-sdk will generate files and call make generate. However, that will then fail because we didn't call go mod tidy for api/ directory.

Note that compared to sriov-network-operator, in dpu-operator we have several go.mod files. That does not seem to agree with operator-sdk, or at least, something is not hooked up right.

Hack make generate to call go mod tidy first.

Otherwise:

  $ git checkout -B C origin/main && \
    git reset --hard HEAD && \
    git clean -fdx && \
    make operator-sdk && \
    ./bin/operator-sdk create webhook --group config --version v1 --kind DpuOperatorConfig --defaulting --programmatic-validation
  branch 'C' set up to track 'origin/main'.
  Reset branch 'C'
  Your branch is up to date with 'origin/main'.
  HEAD is now at e58a9c9c830a Merge pull request #194 from thom311/th/hack-scripts-cleanup
  INFO[0000] Writing kustomize manifests for you to edit...
  ERRO[0000] Unable to find the target #- path: manager_webhook_patch.yaml to uncomment in the file config/default/kustomization.yaml.
  INFO[0000] Writing scaffold for you to edit...
  INFO[0000] api/v1/dpuoperatorconfig_webhook.go
  INFO[0000] api/v1/dpuoperatorconfig_webhook_test.go
  INFO[0000] api/v1/webhook_suite_test.go
  INFO[0000] Update dependencies:
  $ go mod tidy
  INFO[0000] Running make:
  $ make generate
  test -s /data/src/dpu-operator/bin/controller-gen && /data/src/dpu-operator/bin/controller-gen --version | grep -q v0.15.0 || \
  GOBIN=/data/src/dpu-operator/bin GOFLAGS='' go install sigs.k8s.io/controller-tools/cmd/[email protected]
  GOFLAGS='' /data/src/dpu-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
  Error: load packages in root "/data/src/dpu-operator/api": err: exit status 1: stderr: go: updates to go.mod needed; to update it:
          go mod tidy

@openshift-ci openshift-ci bot requested review from bn222 and wizhaoredhat November 5, 2024 12:00
@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 5, 2024
Copy link

openshift-ci bot commented Nov 5, 2024

Hi @thom311. Thanks for your PR.

I'm waiting for a openshift 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-sigs/prow repository.

@bn222
Copy link
Contributor

bn222 commented Nov 5, 2024

/hold

Doesn't this behave the same way if we didn't have a go.mod?

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 5, 2024
@thom311
Copy link
Contributor Author

thom311 commented Nov 5, 2024

Doesn't this behave the same way if we didn't have a go.mod?

This patch has only an effect, when make generate is called.

I don't understand what k8s' make generate is supposed to do. So the answer depends on that.

@bn222
Copy link
Contributor

bn222 commented Nov 5, 2024

I don't think we want to mix make generate with go mod tidy. I think go mod tidy should be run separately.

@thom311
Copy link
Contributor Author

thom311 commented Nov 5, 2024

I don't think we want to mix make generate with go mod tidy. I think go mod tidy should be run separately.

There is a reproducer in the commit message that you can just run.

How do you suggest to solve this differently? Especially seeing that make generate is not run by me directly, but by operator-sdk indirectly?

@thom311 thom311 force-pushed the th/make-generate-tidy branch from 403b03c to 23e2c38 Compare November 5, 2024 14:04
@bn222
Copy link
Contributor

bn222 commented Nov 5, 2024

It think the right place is make vendor , and we also need to extend make vendor-check

@thom311 thom311 force-pushed the th/make-generate-tidy branch from 23e2c38 to 27588b8 Compare November 5, 2024 16:01
Makefile Show resolved Hide resolved
@thom311 thom311 force-pushed the th/make-generate-tidy branch 4 times, most recently from e79c2f1 to 1a9a7a0 Compare November 5, 2024 20:33
Makefile Outdated Show resolved Hide resolved
@thom311 thom311 force-pushed the th/make-generate-tidy branch from 1a9a7a0 to 3a8b7b4 Compare November 5, 2024 20:56
@bn222
Copy link
Contributor

bn222 commented Nov 6, 2024

/unhold
/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 6, 2024
@thom311
Copy link
Contributor Author

thom311 commented Nov 6, 2024

Note that the build target also includes the generate target (build is also the default target). That means, a plain make or make build now also runs go mod tidy. That seems wrong that a build tries to generate/tidy the source files.

But I think the problem of that is that it's wrong that build does a generate. The problem is not that generate should not do a go mod tidy.

@bn222
Copy link
Contributor

bn222 commented Nov 13, 2024

/test make-e2e-test

@thom311 thom311 force-pushed the th/make-generate-tidy branch 2 times, most recently from 9f6f831 to f6fcd36 Compare November 18, 2024 09:13
@openshift-ci-robot
Copy link

/test remaining-required

@thom311 thom311 force-pushed the th/make-generate-tidy branch from f6fcd36 to ba1959a Compare November 18, 2024 16:57
@openshift-ci-robot
Copy link

/test remaining-required

@vrindle
Copy link
Contributor

vrindle commented Nov 19, 2024

/test make-e2e-test

Copy link

openshift-ci bot commented Nov 19, 2024

@thom311: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/make-fast-e2e-test 3a8b7b4 link true /test make-fast-e2e-test

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

`TMP_DIR := $(shell mktemp -d)` causes everytime we call `make` to leak
a temporary directory "/tmp/tmp.*/". We could fix that by always using
the same directory ("/tmp/something") or by concatenating all make steps
with `TMPDIR=$(mktemp ...) && cd $TMPDIR && ...`.

Instead, add and use a "scripts/check-gittree-for-diff.sh" script.

That is useful, because the make targets "{generate,vendor}-check" are
basically the same. We can implement them both by calling the script.
And by having a stand-alone bash scripts, it's easier to review (as it's
not a shell scripted escaped inside make).

Also, `make vendor-check` now just calls `make vendor`. Previously, it
reimplemnted how vendoring works.
@thom311 thom311 force-pushed the th/make-generate-tidy branch from ba1959a to 79a3482 Compare November 21, 2024 14:55
@thom311
Copy link
Contributor Author

thom311 commented Nov 21, 2024

See similar comment from @bn222 here:

This prevents separate commits with vendor

That part is now dropped. make generate will no longer also depend on vendor target. Which defeats most of the purpose of why this commit was done. However, that part will temporarily come back in #213.

@bn222
Copy link
Contributor

bn222 commented Nov 21, 2024

/lgtm
/approve
/ok-to-test

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 21, 2024
Copy link

openshift-ci bot commented Nov 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bn222, thom311

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 21, 2024
@openshift-ci-robot
Copy link

/test remaining-required

@openshift-merge-bot openshift-merge-bot bot merged commit 99f3e30 into openshift:main Nov 21, 2024
8 checks passed
@thom311 thom311 deleted the th/make-generate-tidy branch November 21, 2024 17:37
@openshift-bot
Copy link

[ART PR BUILD NOTIFIER]

Distgit: dpu-operator
This PR has been included in build dpu-operator-container-v4.19.0-202411212037.p0.g99f3e30.assembly.stream.el9.
All builds following this will include this PR.

@openshift-bot
Copy link

[ART PR BUILD NOTIFIER]

Distgit: dpu-cni
This PR has been included in build dpu-cni-container-v4.19.0-202411212037.p0.g99f3e30.assembly.stream.el9.
All builds following this will include this PR.

@openshift-bot
Copy link

[ART PR BUILD NOTIFIER]

Distgit: dpu-daemon
This PR has been included in build dpu-daemon-container-v4.19.0-202411212037.p0.g99f3e30.assembly.stream.el9.
All builds following this will include this PR.

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. lgtm 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants