Skip to content

Commit

Permalink
Add support for the conversion between kind and OpenYurt cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Peeknut committed Mar 11, 2021
1 parent cae9e8d commit 10dff86
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 68 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ make WHAT=cmd/yurtctl
```

The `yurtctl` binary can be found at `_output/bin`. To convert an existing Kubernetes cluster to an OpenYurt cluster,
the following simple command line can be used(support kubernetes clusters that managed by minikube, kubeadm and ACK):
the following simple command line can be used(support kubernetes clusters that managed by minikube, kubeadm, ACK and kind):

```bash
_output/bin/yurtctl convert --provider [minikube|kubeadm|ack]
_output/bin/yurtctl convert --provider [minikube|kubeadm|ack|kind]
```

To uninstall OpenYurt and revert back to the original Kubernetes cluster settings, you can run the following command:
Expand Down
4 changes: 2 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ cd openyurt
make WHAT=cmd/yurtctl
```

`yurtctl` 的二进制文件位于_output /bin 目录。如果需要将已存在的 Kubernetes 集群转换为 OpenYurt 集群,你可以使用如下简单的命令(目前支持minikube, kubeadm, ack三种工具安装的kubernetes集群):
`yurtctl` 的二进制文件位于_output /bin 目录。如果需要将已存在的 Kubernetes 集群转换为 OpenYurt 集群,你可以使用如下简单的命令(目前支持minikube, kubeadm, ack, kind 四种工具安装的kubernetes集群):

```bash
_output/bin/yurtctl convert --provider [minikube|kubeadm|ack]
_output/bin/yurtctl convert --provider [minikube|kubeadm|ack|kind]
```

要卸载 OpenYurt 并恢复为原始的 Kubernetes 集群设置,请运行以下命令:
Expand Down
1 change: 0 additions & 1 deletion config/yurtctl-servant/Dockerfile

This file was deleted.

85 changes: 37 additions & 48 deletions hack/lib/release-images.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2020 The OpenYurt Authors.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,7 +26,7 @@ YURT_BUILD_IMAGE="golang:1.13-alpine"
readonly -a YURT_BIN_TARGETS=(
yurthub
yurt-controller-manager
yurtctl-servant
yurtctl
yurt-tunnel-server
yurt-tunnel-agent
yurt-app-manager
Expand All @@ -41,7 +41,7 @@ readonly -a SUPPORTED_ARCH=(
readonly SUPPORTED_OS=linux

readonly -a bin_targets=(${WHAT:-${YURT_BIN_TARGETS[@]}})
readonly -a bin_targets_without_servant=("${bin_targets[@]/yurtctl-servant}")
readonly -a bin_targets_process_servant=("${bin_targets[@]/yurtctl-servant/yurtctl}")
readonly -a target_arch=(${ARCH:-${SUPPORTED_ARCH[@]}})
readonly region=${REGION:-us}

Expand Down Expand Up @@ -74,7 +74,7 @@ function build_multi_arch_binaries() {
cd /opt/src; umask 0022; \
rm -rf ${YURT_LOCAL_BIN_DIR}/* ;"
for arch in ${target_arch[@]}; do
sub_commands+="GOARCH=$arch bash ./hack/make-rules/build.sh $(echo ${bin_targets_without_servant[@]}); "
sub_commands+="GOARCH=$arch bash ./hack/make-rules/build.sh $(echo ${bin_targets_process_servant[@]}); "
done
sub_commands+="chown -R $(id -u):$(id -g) /opt/src/_output"

Expand All @@ -83,21 +83,46 @@ function build_multi_arch_binaries() {

function build_docker_image() {
for arch in ${target_arch[@]}; do
for binary in "${bin_targets_without_servant[@]}"; do
for binary in "${bin_targets_process_servant[@]}"; do
local binary_name=$(get_output_name $binary)
local binary_path=${YURT_LOCAL_BIN_DIR}/${SUPPORTED_OS}/${arch}/${binary_name}
if [ -f ${binary_path} ]; then
local docker_build_path=${DOCKER_BUILD_BASE_IDR}/${SUPPORTED_OS}/${arch}
local docker_file_path=${docker_build_path}/Dockerfile.${binary_name}-${arch}
mkdir -p ${docker_build_path}

local yurt_component_image="${REPO}/${binary_name}:${TAG}-${arch}"
local base_image="k8s.gcr.io/debian-iptables-${arch}:v11.0.2"
cat <<EOF > "${docker_file_path}"
local yurt_component_image
local base_image
if [[ ${binary} =~ yurtctl ]]
then
yurt_component_image=$REPO/yurtctl-servant:$TAG-$arch
case $arch in
amd64)
base_image="amd64/alpine:3.9"
;;
arm64)
base_image="arm64v8/alpine:3.9"
;;
arm)
base_image="arm32v7/alpine:3.9"
;;
*)
echo unknown arch $arch
exit 1
esac
cat << EOF > $docker_file_path
FROM ${base_image}
ADD ${binary_name} /usr/local/bin/yurtctl
EOF
else
yurt_component_image="${REPO}/${binary_name}:${TAG}-${arch}" # openyurt/${binary_name}:latest-${arch}
base_image="k8s.gcr.io/debian-iptables-${arch}:v11.0.2"
cat <<EOF > "${docker_file_path}"
FROM ${base_image}
COPY ${binary_name} /usr/local/bin/${binary_name}
ENTRYPOINT ["/usr/local/bin/${binary_name}"]
EOF
fi

ln "${binary_path}" "${docker_build_path}/${binary_name}"
docker build --no-cache -t "${yurt_component_image}" -f "${docker_file_path}" ${docker_build_path}
Expand All @@ -108,50 +133,14 @@ EOF
done
}

function build_yurtctl_servant_image() {
servant_script_path=$YURTCTL_SERVANT_DIR/setup_edgenode
for arch in ${target_arch[@]}; do
local docker_build_path=$DOCKER_BUILD_BASE_IDR/$SUPPORTED_OS/$arch
local docker_file_path=$docker_build_path/Dockerfile.yurtctl-servant-$arch
mkdir -p $docker_build_path

local yurtctl_servant_image=$REPO/yurtctl-servant:$TAG-$arch
local base_image
case $arch in
amd64)
base_image="amd64/alpine:3.9"
;;
arm64)
base_image="arm64v8/alpine:3.9"
;;
arm)
base_image="arm32v7/alpine:3.9"
;;
*)
echo unknown arch $arch
exit 1
esac
cat << EOF > $docker_file_path
FROM $base_image
EOF
ln $servant_script_path $docker_build_path/setup_edgenode
docker build --no-cache -t $yurtctl_servant_image -f $docker_file_path $docker_build_path
docker save $yurtctl_servant_image > $YURT_IMAGE_DIR/yurtctl-servant-$SUPPORTED_OS-$arch.tar
rm -rf $docker_build_path
done
}

build_images() {
# Always clean first
rm -Rf ${YURT_OUTPUT_DIR}
rm -Rf ${DOCKER_BUILD_BASE_IDR}
mkdir -p ${YURT_LOCAL_BIN_DIR}
mkdir -p ${YURT_IMAGE_DIR}
mkdir -p ${DOCKER_BUILD_BASE_IDR}

build_multi_arch_binaries
build_docker_image
if [[ ${bin_targets[@]} =~ yurtctl-servant ]]; then
build_yurtctl_servant_image
fi
}
}
8 changes: 5 additions & 3 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
// ProviderACK is used if the target kubernetes is run on ack
ProviderACK Provider = "ack"
ProviderKubeadm Provider = "kubeadm"
// ProviderKind is used if the target kubernetes is run on kind
ProviderKind Provider = "kind"
)

// ConvertOptions has the information that required by convert operation
Expand Down Expand Up @@ -204,9 +206,9 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error {

// Validate makes sure provided values for ConvertOptions are valid
func (co *ConvertOptions) Validate() error {
if co.Provider != ProviderMinikube &&
co.Provider != ProviderACK && co.Provider != ProviderKubeadm {
return fmt.Errorf("unknown provider: %s, valid providers are: minikube, ack",
if co.Provider != ProviderMinikube && co.Provider != ProviderACK &&
co.Provider != ProviderKubeadm && co.Provider != ProviderKind {
return fmt.Errorf("unknown provider: %s, valid providers are: minikube, ack, kubeadm, kind",
co.Provider)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/cmd/convert/edgenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (

const (
kubeletConfigRegularExpression = "\\-\\-kubeconfig=.*kubelet.conf"
apiserverAddrRegularExpression = "server: (http(s)?:\\/\\/)?[\\w][\\w]{0,62}(\\.[\\w][-\\w]{0,62})+(:[\\d]{1,5})?"
apiserverAddrRegularExpression = "server: (http(s)?:\\/\\/)?[\\w][-\\w]{0,62}(\\.[\\w][-\\w]{0,62})*(:[\\d]{1,5})?"
hubHealthzCheckFrequency = 10 * time.Second
failedRetry = 5
filemode = 0666
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurtctl/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ spec:
- /bin/sh
- -c
args:
- "nsenter -t 1 -m -u -n -i -- /bin/yurtctl convert edgenode --yurthub-image {{.yurthub_image}} --join-token {{.joinToken}}"
- "cp /usr/local/bin/yurtctl /tmp && nsenter -t 1 -m -u -n -i -- /var/tmp/yurtctl convert edgenode --yurthub-image {{.yurthub_image}} --join-token {{.joinToken}} && rm /tmp/yurtctl"
securityContext:
privileged: true
volumeMounts:
Expand Down Expand Up @@ -231,7 +231,7 @@ spec:
- /bin/sh
- -c
args:
- "nsenter -t 1 -m -u -n -i -- /bin/yurtctl revert edgenode"
- "cp /usr/local/bin/yurtctl /tmp && nsenter -t 1 -m -u -n -i -- /var/tmp/yurtctl revert edgenode && rm /tmp/yurtctl"
securityContext:
privileged: true
volumeMounts:
Expand Down
12 changes: 4 additions & 8 deletions pkg/yurtctl/util/edgenode/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ func GetNodeName() (string, error) {
}

//2. find --hostname-override in 10-kubeadm.conf
nodeName, err := GetSingleContentFromFile(KubeletSvcPath, KubeletHostname)
if err != nil {
return "", err
} else if nodeName != "" {
nodeName, _ := GetSingleContentFromFile(KubeletSvcPath, KubeletHostname)
if nodeName != "" {
nodeName = strings.Split(nodeName, "=")[1]
return nodeName, nil
}
Expand All @@ -128,10 +126,8 @@ func GetNodeName() (string, error) {
}
for _, ef := range environmentFiles {
ef = strings.Split(ef, "-")[1]
nodeName, err = GetSingleContentFromFile(ef, KubeletHostname)
if err != nil {
return "", err
} else if nodeName != "" {
nodeName, _ = GetSingleContentFromFile(ef, KubeletHostname)
if nodeName != "" {
nodeName = strings.Split(nodeName, "=")[1]
return nodeName, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurtctl/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (

var (
// PropagationPolicy defines the propagation policy used when deleting a resource
PropagationPolicy = metav1.DeletePropagationForeground
PropagationPolicy = metav1.DeletePropagationBackground
// WaitServantJobTimeout specifies the timeout value of waiting for the ServantJob to be succeeded
WaitServantJobTimeout = time.Minute * 2
// CheckServantJobPeriod defines the time interval between two successive ServantJob statu's inspection
Expand Down

0 comments on commit 10dff86

Please sign in to comment.