Skip to content

Commit

Permalink
fix: golang build version not set issue
Browse files Browse the repository at this point in the history
1.add golang version env:VERSION_GOLANG

Signed-off-by: Deshi Xiao <[email protected]>
  • Loading branch information
xiaods committed Nov 18, 2024
1 parent dd8440c commit 96ba9b4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions hack/build
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion hack/crdgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 5 additions & 1 deletion hack/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/nodeconfig/nodeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -92,7 +92,10 @@ 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[:])
fmt.Println("=========================================================")
fmt.Println(encoded)
fmt.Println("=========================================================")
if node.Annotations[NodeConfigHashAnnotation] == encoded {
return false, nil
}
Expand Down Expand Up @@ -139,7 +142,6 @@ func isSecret(key string) bool {
"-t",
"--agent-token",
"--datastore-endpoint",
"--cluster-secret",
"--etcd-s3-access-key",
"--etcd-s3-secret-key",
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/nodeconfig/nodeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "MEHHZN5JQ7FNHXRPULUTET64QOCL7KRKKHN2YBD5MQV62OFLCWXA====",
},
},
}

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 {
Expand Down Expand Up @@ -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: "MEHHZN5JQ7FNHXRPULUTET64QOCL7KRKKHN2YBD5MQV62OFLCWXA====",
},
{
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"}`,
},
}
Expand Down

0 comments on commit 96ba9b4

Please sign in to comment.