Skip to content

Commit

Permalink
support config k8s resource server (openyurtio#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
huiwq1990 authored Mar 3, 2022
1 parent 3fcf604 commit b5159af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
36 changes: 24 additions & 12 deletions pkg/yurtctl/cmd/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type joinOptions struct {
unsafeSkipCAVerification bool
ignorePreflightErrors []string
nodeLabels string
kubernetesResourceServer string
}

// newJoinOptions returns a struct ready for being used for creating cmd join flags.
Expand All @@ -78,6 +79,7 @@ func newJoinOptions() *joinOptions {
caCertHashes: make([]string, 0),
unsafeSkipCAVerification: false,
ignorePreflightErrors: make([]string, 0),
kubernetesResourceServer: yurtconstants.DefaultKubernetesResourceServer,
}
}

Expand Down Expand Up @@ -159,21 +161,26 @@ func addJoinConfigFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
&joinOptions.nodeLabels, options.NodeLabels, joinOptions.nodeLabels,
"Sets the labels for joining node",
)
flagSet.StringVar(
&joinOptions.kubernetesResourceServer, options.KubernetesResourceServer, joinOptions.kubernetesResourceServer,
"Sets the address for downloading k8s node resources",
)
}

type joinData struct {
joinNodeData *joindata.NodeRegistration
apiServerEndpoint string
token string
tlsBootstrapCfg *clientcmdapi.Config
clientSet *clientset.Clientset
ignorePreflightErrors sets.String
organizations string
pauseImage string
yurthubImage string
kubernetesVersion string
caCertHashes sets.String
nodeLabels map[string]string
joinNodeData *joindata.NodeRegistration
apiServerEndpoint string
token string
tlsBootstrapCfg *clientcmdapi.Config
clientSet *clientset.Clientset
ignorePreflightErrors sets.String
organizations string
pauseImage string
yurthubImage string
kubernetesVersion string
caCertHashes sets.String
nodeLabels map[string]string
kubernetesResourceServer string
}

// newJoinData returns a new joinData struct to be used for the execution of the kubeadm join workflow.
Expand Down Expand Up @@ -238,6 +245,7 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
CRISocket: opt.criSocket,
Organizations: opt.organizations,
},
kubernetesResourceServer: opt.kubernetesResourceServer,
}

// parse node labels
Expand Down Expand Up @@ -331,3 +339,7 @@ func (j *joinData) CaCertHashes() sets.String {
func (j *joinData) NodeLabels() map[string]string {
return j.nodeLabels
}

func (j *joinData) KubernetesResourceServer() string {
return j.kubernetesResourceServer
}
1 change: 1 addition & 0 deletions pkg/yurtctl/cmd/join/joindata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ type YurtJoinData interface {
CaCertHashes() sets.String
NodeLabels() map[string]string
IgnorePreflightErrors() sets.String
KubernetesResourceServer() string
}
2 changes: 1 addition & 1 deletion pkg/yurtctl/cmd/join/phases/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func runPrepare(c workflow.RunData) error {
if err := system.SetSELinux(); err != nil {
return err
}
if err := kubernetes.CheckAndInstallKubelet(data.KubernetesVersion()); err != nil {
if err := kubernetes.CheckAndInstallKubelet(data.KubernetesResourceServer(), data.KubernetesVersion()); err != nil {
return err
}
if err := kubernetes.SetKubeletService(); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/yurtctl/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ const (
YurthubStaticPodFileName = "yurthub.yaml"
PauseImagePath = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2"

CniUrlFormat = "https://aliacs-edge-k8s-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/public/pkg/openyurt/cni/%s/cni-plugins-linux-%s-%s.tgz"
KubeUrlFormat = "https://dl.k8s.io/%s/kubernetes-node-linux-%s.tar.gz"
TmpDownloadDir = "/tmp"
FlannelIntallFile = "https://aliacs-edge-k8s-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/public/pkg/openyurt/flannel.yaml"
CniUrlFormat = "https://aliacs-edge-k8s-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/public/pkg/openyurt/cni/%s/cni-plugins-linux-%s-%s.tgz"
DefaultKubernetesResourceServer = "dl.k8s.io"
KubeUrlFormat = "https://%s/%s/kubernetes-node-linux-%s.tar.gz"
TmpDownloadDir = "/tmp"
FlannelIntallFile = "https://aliacs-edge-k8s-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/public/pkg/openyurt/flannel.yaml"

EdgeNode = "edge"
CloudNode = "cloud"
Expand Down
3 changes: 3 additions & 0 deletions pkg/yurtctl/kubernetes/kubeadm/app/cmd/options/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ const (

// YurtHubImage flag sets the yurthub image for worker node.
YurtHubImage = "yurthub-image"

// KubernetesResourceServer flag sets the address for download k8s node resources.
KubernetesResourceServer = "kubernetes-resource-server"
)
4 changes: 2 additions & 2 deletions pkg/yurtctl/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func GetKubeControllerManagerHANodes(cliSet *kubernetes.Clientset) ([]string, er
}

//CheckAndInstallKubelet install kubelet and kubernetes-cni, skip install if they exist.
func CheckAndInstallKubelet(clusterVersion string) error {
func CheckAndInstallKubelet(kubernetesResourceServer, clusterVersion string) error {
if strings.Contains(clusterVersion, "-") {
clusterVersion = strings.Split(clusterVersion, "-")[0]
}
Expand All @@ -737,7 +737,7 @@ func CheckAndInstallKubelet(clusterVersion string) error {

if !kubeletExist {
//download and install kubernetes-node
packageUrl := fmt.Sprintf(constants.KubeUrlFormat, clusterVersion, runtime.GOARCH)
packageUrl := fmt.Sprintf(constants.KubeUrlFormat, kubernetesResourceServer, clusterVersion, runtime.GOARCH)
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 {
Expand Down

0 comments on commit b5159af

Please # to comment.