Skip to content

Commit

Permalink
pkg_managers: gomod: Fix the Go toolchain selection conditions
Browse files Browse the repository at this point in the history
When commit d9d1620 enabled full Go 1.21 support the semantics it used
for the Go toolchain selection conditions was very unfortunate as it
revolved too much around the 'go_max_version' variable which at the
time was set to be 1.21. The problem there is that once we try bumping
the max version to say 1.22 the conditions stop making sense and as a
bonus the existing tests start failing. The reasons for that are the
following:
  - we're not actually planning on updating the container image with
    each Go version we're going to support unless absolutely necessary;
    that is thanks to the GOTOOLCHAIN=auto mechanism introduced by 1.21
    that will download any new toolchain as needed automatically
  - without changing unit tests we suddenly can't pass the trivial
    condition on selecting the old fallback 1.20 if the existing unit
    test's base Go release is 1.21.X and the new max supported version
    is 1.22

Tweak the selection conditions so that they finally make sense
semantically:
- use go_max_version only to check incoming requests for incompatible
  new releases
- otherwise always explicitly compare against 1.21 and only fall back
  to 1.20 if the base release is above 1.21 which would lead to
  dirtying the source repo due to compatibility issues on Golang's side

Fixes: d9d1620

Signed-off-by: Erik Skultety <eskultet@redhat.com>
  • Loading branch information
eskultety committed Jun 3, 2024
1 parent 2ebe401 commit 17ddbf1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cachito/workers/pkg_managers/gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ def _select_go_toolchain(go_mod_file: Path) -> Go:
go = Go()
target_version = None
go_max_version = pkgver.Version("1.21")
go_121_version = pkgver.Version("1.21")
go_base_version = go.version
go_mod_version_msg = "go.mod reported versions: '{}'[go], '{}'[toolchain]"

Expand Down Expand Up @@ -1111,13 +1112,13 @@ def _select_go_toolchain(go_mod_file: Path) -> Go:
f"Required/recommended Go toolchain version '{target_version}' is not supported yet.",
)

if target_version >= go_max_version:
if target_version >= go_121_version:
# Project makes use of Go >=1.21:
# - always use the 'X.Y.0' toolchain to make sure GOTOOLCHAIN=auto fetches anything newer
# - container environments need to have it pre-installed
# - local environments will always install 1.21.0 SDK and then pull any newer toolchain
go = Go(release="go1.21.0")
elif go_base_version >= go_max_version:
elif go_base_version >= go_121_version:
# Starting with Go 1.21, Go doesn't try to be semantically backwards compatible in that
# the 'go X.Y' line now denotes the minimum required version of Go, not a "suggested"
# version. What it means in practice is that a Go toolchain >= 1.21 enforces the biggest
Expand Down

0 comments on commit 17ddbf1

Please sign in to comment.