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

RFC: Makefile: fetch GOLANG_VERSION from go.mod #1047

Open
wants to merge 1 commit into
base: incubation
Choose a base branch
from

Conversation

ykaliuta
Copy link
Contributor

@ykaliuta ykaliuta commented Jun 10, 2024

A bit of automation for golang version update.

For local builds make it possible to set it only once in go.mod (it actually means minimal required version, but in the project it is used as the version for builds) and then reuse it for Dockerfiles:

  • pass it as the build argument for normal image build (Dockerfile);
  • use it for TOOLBOX_GOLANG_VERSION for toolbox.Dockerfile.

For compatibility to keep workflow of overriding IMAGE_BUILD_FLAGS --build-arg USE_LOCAL working introduce another variable IMAGE_BUILD_FLAGS_ALL to combine GOLANG_VERSION build argument with the passed IMAGE_BUILD_FLAGS.

Add target golang-version-update to update the default version in the Dockerfiles to avoid doing it manually in all of the places and just commit then for the case of using Dockerfile without Makefile. So, to do the version upgrade in the repo one should:

  1. update the version in go.mod
  2. run make golang-version-update
  3. commit the changes to git and create a pull request

This change does not affect integration, version their should still be updated separatly.

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

A bit of automation for golang version update.

For local builds make it possible to set it only once in go.mod (it
actually means minimal required version, but in the project it is
used as the version for builds) and then reuse it for Dockerfiles:
- pass it as the build argument for normal image build (Dockerfile);
- use it for TOOLBOX_GOLANG_VERSION for toolbox.Dockerfile.

For compatibility to keep workflow of overriding IMAGE_BUILD_FLAGS
--build-arg USE_LOCAL working introduce another variable
IMAGE_BUILD_FLAGS_ALL to combine GOLANG_VERSION build argument with
the passed IMAGE_BUILD_FLAGS.

Add target golang-version-update to update the default version in
the Dockerfiles to avoid doing it manually in all of the places and
just commit then for the case of using Dockerfile without Makefile.

This change does not affect integration, version their should still
be updated separatly.

Signed-off-by: Yauheni Kaliuta <[email protected]>
@openshift-ci openshift-ci bot requested review from asanzgom and etirelli June 10, 2024 11:46
Copy link

openshift-ci bot commented Jun 10, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ykaliuta. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@ykaliuta ykaliuta requested review from bartoszmajsak, zdtsw and VaishnaviHire and removed request for etirelli and asanzgom June 10, 2024 11:46
for f in Dockerfiles/*; do \
sed -i -e 's/\(ARG GOLANG_VERSION=\).*/\1$(GOLANG_VERSION)/g' $$f ; \
done

Copy link
Member

Choose a reason for hiding this comment

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

but "make build" is still using the local Go, which can be different version from go.mod, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. But it is out of scope of go updates (#811) anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

@ykaliuta Can you list steps one needs to take now in order to perform a correct golang version bump for this project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure:

  1. update the version in go.mod
  2. run make golang-version-update
  3. commit the changes to git and create a pull request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally do not see it really necessary to have default version in the Dockerfiles, #811 (comment) but I was told that people can use it

@@ -73,6 +73,7 @@ YQ_VERSION ?= v4.12.2
ENVTEST_K8S_VERSION = 1.24.2
ENVTEST_PACKAGE_VERSION = v0.0.0-20240320141353-395cfc7486e6
CRD_REF_DOCS_VERSION = 0.0.11
GOLANG_VERSION := $(shell sed -n '/^go/s/go \(.*\)/\1/p' < go.mod)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the name shouldn't be REQUIRED_GOLANG_VERSION. IIUC the goal here is to ensure we build against this exact version.

@@ -93,6 +94,7 @@ E2E_TEST_FLAGS = "--skip-deletion=false" -timeout 20m # See README.md, default g
# set to "true" to use local instead
# see target "image-build"
IMAGE_BUILD_FLAGS ?= --build-arg USE_LOCAL=false
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 see this one used anywhere after rename. Am I missing some other piece that depends on IMAGE_BUILD_FLAGS? Or is it intended now to be a customization point for the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see this one used anywhere after rename. Am I missing some other piece that depends on IMAGE_BUILD_FLAGS? Or is it intended now to be a customization point for the caller?

Yes, for you :) I remember you told that you have it in some alias.

for f in Dockerfiles/*; do \
sed -i -e 's/\(ARG GOLANG_VERSION=\).*/\1$(GOLANG_VERSION)/g' $$f ; \
done

Copy link
Contributor

Choose a reason for hiding this comment

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

@ykaliuta Can you list steps one needs to take now in order to perform a correct golang version bump for this project?

@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

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.

@ykaliuta ykaliuta mentioned this pull request Nov 28, 2024
5 tasks
@biswassri
Copy link
Contributor

@ykaliuta From this comment I think we no longer want to go this route? Or are we still evaluating this?

@ykaliuta
Copy link
Contributor Author

@ykaliuta From this comment I think we no longer want to go this route? Or are we still evaluating this?

We still can discuss it, the PR is RFC as you can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants