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

bugfix: dynamically switch apiVersion of JoinConfiguration to adapt to different versions of k8s #1112

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/fsnotify/fsnotify v1.4.10-0.20200417215612-7f4cf4dd2b52 // indirect
github.com/google/uuid v1.1.2
github.com/gorilla/mux v1.7.4
github.com/hashicorp/go-version v1.6.0
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtadm/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ preferences: {}
`

KubeadmJoinConf = `
apiVersion: kubeadm.k8s.io/v1beta3
apiVersion: {{.apiVersion}}
kind: JoinConfiguration
discovery:
file:
Expand Down
17 changes: 17 additions & 0 deletions pkg/yurtadm/util/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"strings"
"time"

"github.com/hashicorp/go-version"
pkgerrors "github.com/pkg/errors"
batchv1 "k8s.io/api/batch/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -355,6 +356,22 @@ func SetKubeadmJoinConfig(data joindata.YurtJoinData) error {
ctx["containerRuntimeEndpoint"] = nodeReg.CRISocket
}

v1, err := version.NewVersion(data.KubernetesVersion())
if err != nil {
return err
}
v2, err := version.NewVersion("v1.22.0")
if err != nil {
return err
}
// This is to adapt the apiVersion of JoinConfiguration
// https://kubernetes.io/docs/reference/config-api/kubeadm-config.v1beta3/
if v1.LessThan(v2) {
ctx["apiVersion"] = "kubeadm.k8s.io/v1beta2"
} else {
ctx["apiVersion"] = "kubeadm.k8s.io/v1beta3"
}

kubeadmJoinTemplate, err := templates.SubsituteTemplate(constants.KubeadmJoinConf, ctx)
if err != nil {
return err
Expand Down