From b9eacdc5fcfea4dc5235d43122c41cd3f4f56b94 Mon Sep 17 00:00:00 2001 From: Deshi Xiao Date: Mon, 18 Nov 2024 22:31:38 +0800 Subject: [PATCH] fix: golang build version not set issue 1.add golang version env:VERSION_GOLANG Signed-off-by: Deshi Xiao --- Dockerfile.dapper | 2 +- go.mod | 4 +++- hack/build | 1 + hack/crdgen.go | 2 +- hack/version.sh | 6 +++++- pkg/nodeconfig/nodeconfig.go | 5 ++--- pkg/nodeconfig/nodeconfig_test.go | 16 ++++++++-------- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 63b9b234..6bc75588 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -1,4 +1,4 @@ -ARG GOLANG=golang:1.22.6-alpine3.20 +ARG GOLANG=golang:1.22.8-alpine3.20 FROM ${GOLANG} # Set proxy environment variables diff --git a/go.mod b/go.mod index d577b546..38eec768 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/xiaods/k8e -go 1.22.5 +go 1.22.7 + +toolchain go1.22.9 replace ( github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.11.7 diff --git a/hack/build b/hack/build index 18292bd1..93dd0f3b 100755 --- a/hack/build +++ b/hack/build @@ -21,6 +21,7 @@ buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ') VERSIONFLAGS=" -X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8} + -X ${PKG}/pkg/version.UpstreamGolang=${VERSION_GOLANG} -X ${PKG_K8S_CLIENT}/version.gitVersion=${VERSION} -X ${PKG_K8S_CLIENT}/version.gitCommit=${COMMIT} diff --git a/hack/crdgen.go b/hack/crdgen.go index b9bd6e8a..befc526b 100644 --- a/hack/crdgen.go +++ b/hack/crdgen.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/rancher/wrangler/pkg/crd" + "github.com/rancher/wrangler/v3/pkg/crd" k8ecrd "github.com/xiaods/k8e/pkg/crd" _ "github.com/xiaods/k8e/pkg/generated/controllers/k8e.cattle.io/v1" ) diff --git a/hack/version.sh b/hack/version.sh index 1106631e..19e536b8 100644 --- a/hack/version.sh +++ b/hack/version.sh @@ -60,7 +60,11 @@ if [ -z "$VERSION_CRI_DOCKERD" ]; then VERSION_CRI_DOCKERD="v0.0.0" fi -VERSION_CNIPLUGINS="v1.5.1-k3s1" +VERSION_CNIPLUGINS="v1.6.0-k3s1" + +DEPENDENCIES_URL="https://raw.githubusercontent.com/kubernetes/kubernetes/${VERSION_K8S}/build/dependencies.yaml" +VERSION_GOLANG="go"$(curl -sL "${DEPENDENCIES_URL}" | yq e '.dependencies[] | select(.name == "golang: upstream version").version' -) + if [[ -n "$GIT_TAG" ]]; then if [[ ! "$GIT_TAG" =~ ^"$VERSION_K8S"[+-] ]]; then diff --git a/pkg/nodeconfig/nodeconfig.go b/pkg/nodeconfig/nodeconfig.go index 8783926b..866eaafa 100644 --- a/pkg/nodeconfig/nodeconfig.go +++ b/pkg/nodeconfig/nodeconfig.go @@ -70,7 +70,7 @@ func getNodeEnv() (string, error) { return string(k8eEnvJSON), nil } -// SetNodeConfigAnnotations stores a redacted version of the k8e cli args and +// SetNodeConfigAnnotations stores a redacted version of the k3s cli args and // environment variables as annotations on the node object. It also stores a // hash of the combined args + variables. These are used by other components // to determine if the node configuration has been changed. @@ -92,7 +92,7 @@ func SetNodeConfigAnnotations(nodeConfig *config.Node, node *corev1.Node) (bool, node.Annotations = make(map[string]string) } configHash := h.Sum(nil) - encoded := base32.StdEncoding.EncodeToString(configHash) + encoded := base32.StdEncoding.EncodeToString(configHash[:]) if node.Annotations[NodeConfigHashAnnotation] == encoded { return false, nil } @@ -139,7 +139,6 @@ func isSecret(key string) bool { "-t", "--agent-token", "--datastore-endpoint", - "--cluster-secret", "--etcd-s3-access-key", "--etcd-s3-secret-key", } diff --git a/pkg/nodeconfig/nodeconfig_test.go b/pkg/nodeconfig/nodeconfig_test.go index b9383f34..c9d66cb6 100644 --- a/pkg/nodeconfig/nodeconfig_test.go +++ b/pkg/nodeconfig/nodeconfig_test.go @@ -30,16 +30,16 @@ var FakeNodeWithAnnotation = &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "fakeNode-with-annotation", Annotations: map[string]string{ - NodeArgsAnnotation: `["server"]`, + NodeArgsAnnotation: `["server","--flannel-backend=none"]`, NodeEnvAnnotation: `{"` + TestEnvName + `":"fakeNode-with-annotation"}`, - NodeConfigHashAnnotation: "FIJ7GZ42FJLYYYPQVVRUGKP3RBJGL5YHUJPWGQMBBVF4OQ6MOSWA====", + NodeConfigHashAnnotation: "5E6GSWFRVCOEB3BFFVXKWVD7IQEVJFJAALHPOTCLV7SL33N6SIYA====", }, }, } func Test_UnitSetExistingNodeConfigAnnotations(t *testing.T) { // adding same config - os.Args = []string{version.Program, "server"} + os.Args = []string{version.Program, "server", "--flannel-backend=none"} os.Setenv(version.ProgramUpper+"_NODE_NAME", "fakeNode-with-annotation") nodeUpdated, err := SetNodeConfigAnnotations(FakeNodeConfig, FakeNodeWithAnnotation) if err != nil { @@ -77,22 +77,22 @@ func Test_UnitSetNodeConfigAnnotations(t *testing.T) { args: args{ config: FakeNodeConfig, node: FakeNodeWithAnnotation, - osArgs: []string{version.Program, "server"}, + osArgs: []string{version.Program, "server", "--flannel-backend=none"}, }, want: true, - wantNodeArgs: `["server"]`, + wantNodeArgs: `["server","--flannel-backend","none"]`, wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`, - wantNodeConfigHash: "47ZWLMKZE6NJ7M5KJVPQY4GSJINRZOQEGHOFQFLRQBY3HBQX5HLA====", + wantNodeConfigHash: "DRWW63TXZZGSKLARSFZLNSJ3RZ6VR7LQ46WPKZMSLTSGNI2J42WA====", }, { name: "Set args with equal", args: args{ config: FakeNodeConfig, node: FakeNodeWithNoAnnotation, - osArgs: []string{version.Program, "server", "--write-kubeconfig-mode=777"}, + osArgs: []string{version.Program, "server", "--flannel-backend=none", "--write-kubeconfig-mode=777"}, }, want: true, - wantNodeArgs: `["server","--write-kubeconfig-mode","777"]`, + wantNodeArgs: `["server","--flannel-backend","none","--write-kubeconfig-mode","777"]`, wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`, }, }