Skip to content

Commit

Permalink
chore: upgrade to go 1.20 (#12014)
Browse files Browse the repository at this point in the history
* chore: Upgrade Golang to 1.19 (#10176) (#10186)

* Upgrade Golang to 1.19

Signed-off-by: OmarKalloush <omar.kalloush@optimumpartners.co>

* go mod tidy with go 1.19

Signed-off-by: OmarKalloush <omar.kalloush@optimumpartners.co>

* Replace deprecated ioutil

Signed-off-by: OmarKalloush <omar.kalloush@optimumpartners.co>

* make codegen changes

Signed-off-by: OmarKalloush <omar.kalloush@optimumpartners.co>

* Codegen Changes

Signed-off-by: OmarKalloush <omar.kalloush@optimumpartners.co>

chore: upgrade golangci-lint to 1.50.1

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

missed a spot

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

tidy

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

fix bad merge

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

Author:    Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-Authored-By: OmarKalloush <omar.kalloush@optimumpartners.co>

fix indentation

fix lint and codegen

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* 1.20

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix lint errors

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix "syntax error: unexpected var after top level declaration" in "make test-race-local"

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: OmarKalloush <100078273+OmarKalloush@users.noreply.github.com>
  • Loading branch information
crenshaw-dev and omarkalloush committed Feb 17, 2023
1 parent 58a3079 commit e75cf73
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
# Golang version to use across CI steps
GOLANG_VERSION: '1.18'
GOLANG_VERSION: '1.20'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # v3.3.1
with:
version: v1.46.2
version: v1.51.0
args: --timeout 10m --exclude SA5011 --verbose

test-go:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
types: [ labeled, unlabeled, opened, synchronize, reopened ]

env:
GOLANG_VERSION: '1.18'
GOLANG_VERSION: '1.20'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- "!release-v0*"

env:
GOLANG_VERSION: '1.18'
GOLANG_VERSION: '1.20'

permissions:
contents: read
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG BASE_IMAGE=docker.io/library/ubuntu:22.04
# Initial stage which pulls prepares build dependencies and CLI tooling we need for our final image
# Also used as the image in CI jobs so needs all dependencies
####################################################################################################
FROM docker.io/library/golang:1.18 AS builder
FROM docker.io/library/golang:1.20 AS builder

RUN echo 'deb http://deb.debian.org/debian buster-backports main' >> /etc/apt/sources.list

Expand Down Expand Up @@ -101,7 +101,7 @@ RUN HOST_ARCH=$TARGETARCH NODE_ENV='production' NODE_ONLINE_ENV='online' NODE_OP
####################################################################################################
# Argo CD Build stage which performs the actual build of Argo CD binaries
####################################################################################################
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.18 AS argocd-build
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.20 AS argocd-build

WORKDIR /go/src/github.com/argoproj/argo-cd

Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ cli: test-tools-image

.PHONY: cli-local
cli-local: clean-debug
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${CLI_NAME} ./cmd
CGO_ENABLED=0 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${CLI_NAME} ./cmd

.PHONY: gen-resources-cli-local
gen-resources-cli-local: clean-debug
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${GEN_RESOURCES_CLI_NAME} ./hack/gen-resources/cmd
CGO_ENABLED=0 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${GEN_RESOURCES_CLI_NAME} ./hack/gen-resources/cmd

.PHONY: release-cli
release-cli: clean-debug build-ui
Expand Down Expand Up @@ -266,19 +266,19 @@ manifests: test-tools-image
# consolidated binary for cli, util, server, repo-server, controller
.PHONY: argocd-all
argocd-all: clean-debug
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${BIN_NAME} ./cmd
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${BIN_NAME} ./cmd

.PHONY: server
server: clean-debug
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-server ./cmd
CGO_ENABLED=0 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-server ./cmd

.PHONY: repo-server
repo-server:
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-repo-server ./cmd
CGO_ENABLED=0 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-repo-server ./cmd

.PHONY: controller
controller:
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-application-controller ./cmd
CGO_ENABLED=0 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-application-controller ./cmd

.PHONY: build-ui
build-ui:
Expand All @@ -294,7 +294,7 @@ ifeq ($(DEV_IMAGE), true)
IMAGE_TAG="dev-$(shell git describe --always --dirty)"
image: build-ui
DOCKER_BUILDKIT=1 docker build --platform=linux/amd64 -t argocd-base --target argocd-base .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd ./cmd
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd ./cmd
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-server
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-application-controller
ln -sfn ${DIST_DIR}/argocd ${DIST_DIR}/argocd-repo-server
Expand Down Expand Up @@ -368,7 +368,7 @@ build: test-tools-image
# Build all Go code (local version)
.PHONY: build-local
build-local:
go build -v `go list ./... | grep -v 'resource_customizations\|test/e2e'`
GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go build -v `go list ./... | grep -v 'resource_customizations\|test/e2e'`

# Run all unit tests
#
Expand Down Expand Up @@ -579,7 +579,7 @@ list:

.PHONY: applicationset-controller
applicationset-controller:
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-applicationset-controller ./cmd
GODEBUG="tarinsecurepath=0,zipinsecurepath=0" CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/argocd-applicationset-controller ./cmd

.PHONY: checksums
checksums:
Expand Down
16 changes: 7 additions & 9 deletions applicationset/generators/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func (g *GitGenerator) generateParamsForGitDirectories(appSetGenerator *argoproj
}

log.WithFields(log.Fields{
"allPaths": allPaths,
"total": len(allPaths),
"repoURL": appSetGenerator.Git.RepoURL,
"revision": appSetGenerator.Git.Revision,
"allPaths": allPaths,
"total": len(allPaths),
"repoURL": appSetGenerator.Git.RepoURL,
"revision": appSetGenerator.Git.Revision,
"pathParamPrefix": appSetGenerator.Git.PathParamPrefix,
}).Info("applications result from the repo service")

Expand Down Expand Up @@ -127,9 +127,7 @@ func (g *GitGenerator) generateParamsForGitFiles(appSetGenerator *argoprojiov1al
return nil, fmt.Errorf("unable to process file '%s': %v", path, err)
}

for index := range paramsArray {
res = append(res, paramsArray[index])
}
res = append(res, paramsArray...)
}
return res, nil
}
Expand Down Expand Up @@ -183,7 +181,7 @@ func (g *GitGenerator) generateParamsFromGitFile(filePath string, fileContent []
}
pathParamName := "path"
if pathParamPrefix != "" {
pathParamName = pathParamPrefix+"."+pathParamName
pathParamName = pathParamPrefix + "." + pathParamName
}
params[pathParamName] = path.Dir(filePath)
params[pathParamName+".basename"] = path.Base(params[pathParamName].(string))
Expand Down Expand Up @@ -251,7 +249,7 @@ func (g *GitGenerator) generateParamsFromApps(requestedApps []string, appSetGene
} else {
pathParamName := "path"
if appSetGenerator.Git.PathParamPrefix != "" {
pathParamName = appSetGenerator.Git.PathParamPrefix+"."+pathParamName
pathParamName = appSetGenerator.Git.PathParamPrefix + "." + pathParamName
}
params[pathParamName] = a
params[pathParamName+".basename"] = path.Base(a)
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/argoproj/argo-cd/v2

go 1.18
go 1.20

require (
code.gitea.io/sdk/gitea v0.15.1
Expand Down Expand Up @@ -104,18 +104,21 @@ require (
)

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/antonmedv/expr v1.9.0
github.com/coreos/go-oidc/v3 v3.4.0
github.com/gosimple/slug v1.13.1
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5
github.com/robfig/cron/v3 v3.0.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.31.0
go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1
go.opentelemetry.io/otel/sdk v1.11.1
)

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/antonmedv/expr v1.9.0
github.com/coreos/go-oidc/v3 v3.4.0
github.com/robfig/cron/v3 v3.0.1
)

require (
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/google/go-github/v45 v45.2.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions hack/gen-resources/generators/application_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewApplicationGenerator(argoClientSet *appclientset.Clientset, clientSet *k
}

func (pg *ApplicationGenerator) buildRandomSource(repositories []*v1alpha1.Repository) (*v1alpha1.ApplicationSource, error) {
rand.Seed(time.Now().Unix())
repoNumber := rand.Int() % len(repositories)
seed := rand.New(rand.NewSource(time.Now().Unix()))
repoNumber := seed.Int() % len(repositories)
return &v1alpha1.ApplicationSource{
RepoURL: repositories[repoNumber].Repo,
Path: "helm-guestbook",
Expand All @@ -49,8 +49,8 @@ func (ag *ApplicationGenerator) buildSource(opts *util.GenerateOpts, repositorie
}

func (pg *ApplicationGenerator) buildRandomDestination(opts *util.GenerateOpts, clusters []v1alpha1.Cluster) (*v1alpha1.ApplicationDestination, error) {
rand.Seed(time.Now().Unix())
clusterNumber := rand.Int() % len(clusters)
seed := rand.New(rand.NewSource(time.Now().Unix()))
clusterNumber := seed.Int() % len(clusters)
return &v1alpha1.ApplicationDestination{
Namespace: opts.Namespace,
Name: clusters[clusterNumber].Name,
Expand Down
2 changes: 1 addition & 1 deletion hack/installers/install-lint-tools.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -eux -o pipefail

GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
2 changes: 1 addition & 1 deletion hack/known_types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func init() {%s
}
}

return os.WriteFile(outputPath, []byte(res), 0644)
return os.WriteFile(outputPath, []byte(res+"\n"), 0644)
},
}
command.Flags().StringVar(&docsOutputPath, "docs", "", "Docs output file path")
Expand Down
2 changes: 1 addition & 1 deletion hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ report() {

trap 'report' EXIT

go test $TEST_FLAGS -failfast $* 2>&1 | tee $TEST_RESULTS/test.out
GODEBUG="tarinsecurepath=0,zipinsecurepath=0" go test $TEST_FLAGS -failfast $* 2>&1 | tee $TEST_RESULTS/test.out
14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN ln -s /usr/lib/$(uname -m)-linux-gnu /usr/lib/linux-gnu

FROM docker.io/library/node:12.18.4-buster as node

FROM docker.io/library/golang:1.18 as golang
FROM docker.io/library/golang:1.20 as golang

FROM docker.io/library/registry:2.8 as registry

Expand Down
2 changes: 1 addition & 1 deletion test/remote/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG BASE_IMAGE=docker.io/library/ubuntu:22.04

FROM golang:1.18 AS go
FROM golang:1.20 AS go

RUN go install github.com/mattn/goreman@latest && \
go install github.com/kisielk/godepgraph@latest
Expand Down
2 changes: 1 addition & 1 deletion util/argo/normalizers/corev1_known_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 46 additions & 3 deletions util/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -390,24 +392,65 @@ func TestCreateServerTLSConfig(t *testing.T) {
})
}

// getCert does the same thing as tls.AppendCertsFromPEM, but throws an error if something goes wrong.
func getCert(pemCerts []byte) (*x509.Certificate, error) {
block, _ := pem.Decode(pemCerts)
if block == nil {
return nil, errors.New("failed to decode pem block")
}
if block.Type != "CERTIFICATE" || len(block.Headers) != 0 {
return nil, errors.New("encountered something other than a certificate")
}

certBytes := block.Bytes
cert, err := x509.ParseCertificate(certBytes)
if err != nil {
return nil, err
}
return cert, nil
}

func getCertFromFile(path string) (*x509.Certificate, error) {
certBytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
return getCert(certBytes)
}

func TestLoadX509CertPool(t *testing.T) {
t.Run("Successfully load single cert", func(t *testing.T) {
p, err := LoadX509CertPool("testdata/valid_tls.crt")
require.NoError(t, err)
require.NotNil(t, p)
assert.Len(t, p.Subjects(), 1)

cert, err := getCertFromFile("testdata/valid_tls.crt")
require.NoError(t, err)
groundTruthPool := x509.NewCertPool()
groundTruthPool.AddCert(cert)

assert.True(t, groundTruthPool.Equal(p))
})
t.Run("Successfully load single existing cert from multiple list", func(t *testing.T) {
p, err := LoadX509CertPool("testdata/invalid_tls.crt", "testdata/valid_tls.crt")
require.NoError(t, err)
require.NotNil(t, p)
assert.Len(t, p.Subjects(), 1)

cert, err := getCertFromFile("testdata/valid_tls.crt")
require.NoError(t, err)
groundTruthPool := x509.NewCertPool()
groundTruthPool.AddCert(cert)

assert.True(t, groundTruthPool.Equal(p))
})
t.Run("Only non-existing certs in list", func(t *testing.T) {
p, err := LoadX509CertPool("testdata/invalid_tls.crt", "testdata/valid_tls2.crt")
require.NoError(t, err)
require.NotNil(t, p)
assert.Len(t, p.Subjects(), 0)

groundTruthPool := x509.NewCertPool()

assert.True(t, groundTruthPool.Equal(p))
})
t.Run("Invalid cert in requested cert list", func(t *testing.T) {
p, err := LoadX509CertPool("testdata/empty_tls.crt", "testdata/valid_tls2.crt")
Expand Down

0 comments on commit e75cf73

Please sign in to comment.