Skip to content

Commit

Permalink
support yurtadm join to join multiple master nodes (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
windydayc authored Aug 26, 2022
1 parent 277c2eb commit 83d0d2d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/util/kubernetes/kubeadm/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,13 @@ var (
ControlPlaneComponents = []string{KubeAPIServer, KubeControllerManager, KubeScheduler}

// MinimumControlPlaneVersion specifies the minimum control plane version kubeadm can deploy
MinimumControlPlaneVersion = version.MustParseSemantic("v1.21.0")
MinimumControlPlaneVersion = version.MustParseSemantic("v1.18.0")

// MinimumKubeletVersion specifies the minimum version of kubelet which kubeadm supports
MinimumKubeletVersion = version.MustParseSemantic("v1.21.0")
MinimumKubeletVersion = version.MustParseSemantic("v1.18.0")

// CurrentKubernetesVersion specifies current Kubernetes version supported by kubeadm
CurrentKubernetesVersion = version.MustParseSemantic("v1.22.0")
CurrentKubernetesVersion = version.MustParseSemantic("v1.18.0")

// SupportedEtcdVersion lists officially supported etcd versions with corresponding Kubernetes releases
SupportedEtcdVersion = map[uint8]string{
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/kubernetes/kubeadm/app/discovery/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"context"
"fmt"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -57,7 +58,8 @@ func RetrieveBootstrapConfig(data joindata.YurtJoinData) (*clientcmdapi.Config,

clusterinfo := kubeconfigutil.GetClusterFromKubeConfig(cfg)
return kubeconfigutil.CreateWithToken(
fmt.Sprintf("https://%s", data.ServerAddr()),
// If there are multiple master IP addresses, take the first one here
fmt.Sprintf("https://%s", strings.Split(data.ServerAddr(), ",")[0]),
"kubernetes",
TokenUser,
clusterinfo.CertificateAuthorityData,
Expand All @@ -79,7 +81,8 @@ func retrieveValidatedConfigInfo(client clientset.Interface, data joindata.YurtJ
return nil, err
}

endpoint := data.ServerAddr()
// If there are multiple master IP addresses, take the first one here
endpoint := strings.Split(data.ServerAddr(), ",")[0]
insecureBootstrapConfig := buildInsecureBootstrapKubeConfig(endpoint, "kubernetes")
clusterName := insecureBootstrapConfig.Contexts[insecureBootstrapConfig.CurrentContext].Cluster

Expand Down
2 changes: 2 additions & 0 deletions pkg/yurtadm/cmd/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
if len(args) > 1 {
klog.Warningf("[preflight] WARNING: More than one API server endpoint supplied on command line %v. Using the first one.", args)
}
// if join multiple masters, apiServerEndpoint may be like:
// 1.2.3.4:6443,1.2.3.5:6443,1.2.3.6:6443
apiServerEndpoint = args[0]
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/yurtadm/cmd/join/phases/joinnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -168,8 +169,16 @@ func addYurthubStaticYaml(data joindata.YurtJoinData, podManifestPath string) er
}
}

// There can be multiple master IP addresses
serverAddrs := strings.Split(data.ServerAddr(), ",")
for i := 0; i < len(serverAddrs); i++ {
serverAddrs[i] = fmt.Sprintf("https://%s", serverAddrs[i])
}

kubernetesServerAddrs := strings.Join(serverAddrs, ",")

ctx := map[string]string{
"kubernetesServerAddr": fmt.Sprintf("https://%s", data.ServerAddr()),
"kubernetesServerAddr": kubernetesServerAddrs,
"image": data.YurtHubImage(),
"joinToken": data.JoinToken(),
"workingMode": data.NodeRegistration().WorkingMode,
Expand Down
3 changes: 2 additions & 1 deletion pkg/yurtadm/cmd/join/phases/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func runPreflight(c workflow.RunData) error {
Discovery: kubeadmapi.Discovery{
TLSBootstrapToken: data.JoinToken(),
BootstrapToken: &kubeadmapi.BootstrapTokenDiscovery{
APIServerEndpoint: data.ServerAddr(),
// If there are multiple master IP addresses, take the first one here
APIServerEndpoint: strings.Split(data.ServerAddr(), ",")[0],
Token: data.JoinToken()},
},
ControlPlane: nil,
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtadm/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func CheckAndInstallKubelet(kubernetesResourceServer, clusterVersion string) err
savePath := fmt.Sprintf("%s/kubernetes-node-linux-%s.tar.gz", constants.TmpDownloadDir, runtime.GOARCH)
klog.V(1).Infof("Download kubelet from: %s", packageUrl)
if err := util.DownloadFile(packageUrl, savePath, 3); err != nil {
return fmt.Errorf("Download kuelet fail: %w", err)
return fmt.Errorf("Download kubelet fail: %w", err)
}
if err := util.Untar(savePath, constants.TmpDownloadDir); err != nil {
return err
Expand Down

0 comments on commit 83d0d2d

Please sign in to comment.