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

Upgrade Go to 1.23 #6647

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Upgrade Go to 1.23 #6647

merged 3 commits into from
Sep 9, 2024

Conversation

antoninbas
Copy link
Contributor

@antoninbas antoninbas commented Aug 30, 2024

  • Update some for loops in response to the following change introduced in Go 1.22: each iteration of the loop creates new variables, to avoid accidental sharing bugs. As a result of this change, a few existing loop variables had become heap-allocated, so we updated the loop to avoid the extra allocation. Other loops that were affected by the change (compiling differently), but for which the loop variable was stack-allocated, were reviewed individually and when it made sense, the loop was refactored to avoid the extra variable copy. The go test -gcflags=-d=loopvar=2 command was used to find affected loops.

  • The antrea/codegen image was updated to use Go 1.23. No changes in generated files.

  • golangci-lint was updated to the latest available version (v1.60.3)

    • govet reported some invalid usages of printf, which was addressed; this lead to some refactoring of the antctl check code
    • a new gosec rule (G115), which looks for potential integer overflows when converting between integer types, caused a lot of errors to be reported in the codebase. There were too many errors to be addressed as part of this PR, so we only handled a few of them for which the fix was straightforward. When the rule implementation is improved (so that it reports fewer false positives), we should review all errors and address them as needed.

Fixes #6644

@antoninbas antoninbas changed the title Upgarde Go to 1.23 Upgrade Go to 1.23 Aug 30, 2024
* Update some for loops in response to the following change introduced
  in Go 1.22: each iteration of the loop creates new variables, to avoid
  accidental sharing bugs. As a result of this change, a few existing
  loop variables had become heap-allocated, so we updated the loop to
  avoid the extra allocation. Other loops that were affected by the
  change (compiling differently), but for which the loop variable was
  stack-allocated, were reviewed individually and when it made sense,
  the loop was refactored to avoid the extra variable copy. The `go test
  -gcflags=-d=loopvar=2` command was used to find affected loops.
* The antrea/codegen image was updated to use Go 1.23. No changes in
  generated files.
* golangci-lint was updated to the latest available version (v1.60.3)

    - govet reported some invalid usages of printf, which was addressed;
      this lead to some refactoring of the `antctl check` code
    - a new gosec rule (G115), which looks for potential integer
      overflows when converting between integer types, caused a lot of
      errors to be reported in the codebase. There were too many errors
      to be addressed as part of this PR, so we only handled a few of
      them for which the fix was straightforward. When the rule
      implementation is improved (so that it reports fewer false
      positives), we should review all errors and address them as needed.

Fixes antrea-io#6644

Signed-off-by: Antonin Bas <[email protected]>
Signed-off-by: Antonin Bas <[email protected]>
@@ -216,13 +216,14 @@ func GenerateRandomNamespace(baseName string) string {
}

func Teardown(ctx context.Context, client kubernetes.Interface, clusterName string, namespace string) {
fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", clusterName)+"Deleting installation tests setup...\n")
logger := NewLogger(fmt.Sprintf("[%s] ", clusterName))
Copy link
Member

Choose a reason for hiding this comment

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

could we add a Logger parameter to Teardown and remove clusterName?

@@ -233,8 +234,8 @@ func Teardown(ctx context.Context, client kubernetes.Interface, clusterName stri
return false, nil
})
if err != nil {
fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", clusterName)+"Setup deletion failed\n")
logger.Success("Setup deletion failed")
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
logger.Success("Setup deletion failed")
logger.Fail("Setup deletion failed")

} else {
fmt.Fprintf(os.Stdout, fmt.Sprintf("[%s] ", clusterName)+"Setup deletion successful\n")
logger.Fail("Setup deletion successful")
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
logger.Fail("Setup deletion successful")
logger.Success("Setup deletion successful")

Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

No new comments after quan's, LGTM overall

@@ -22,7 +22,7 @@ function echoerr {
}

ANTREA_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2-build.2"
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2-build.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

One question: I assume this image is already uploaded?

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, I already pushed it

Signed-off-by: Antonin Bas <[email protected]>
@antoninbas antoninbas requested a review from tnqn September 3, 2024 17:32
@antoninbas
Copy link
Contributor Author

/test-all

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@antoninbas
Copy link
Contributor Author

/test-all

2 similar comments
@antoninbas
Copy link
Contributor Author

/test-all

@XinShuYang
Copy link
Contributor

/test-all

@antoninbas
Copy link
Contributor Author

/test-e2e
/test-conformance

@antoninbas
Copy link
Contributor Author

/test-e2e

@antoninbas antoninbas merged commit d75cc53 into antrea-io:main Sep 9, 2024
54 of 58 checks passed
@antoninbas antoninbas deleted the bump-go-to-1.23 branch September 9, 2024 17:05
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.

Upgrade Go to 1.23
4 participants