This is an automated email from the ASF dual-hosted git repository. liuxun pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push: new c0f8825 SUBMARINE-380. Optimize create kind cluster scripts c0f8825 is described below commit c0f88255436ffefca8e1fbf6a13f0f0843a32580 Author: Xun Liu <liu...@apache.org> AuthorDate: Fri Feb 14 22:17:57 2020 +0800 SUBMARINE-380. Optimize create kind cluster scripts ### What is this PR for? In the submarine-cloud script for creating a kind cluster, If the user does not have kind bin installed, after the automatic download, the user is required to manually set the kind to the PATH environment variable. We need to provide a kind script in the submarine project. This script proxy all kind bin commands. If the kind bin file is not installed locally, the kind script will automatically download the kind bin file. All kind bin operations are performed by this kind script, so that the user does not need to set the PATH environment variable. ### What type of PR is it? Improvement ### Todos * [[k8s-e2e] Create k8s e2e test module](https://issues.apache.org/jira/browse/SUBMARINE-385) ### What is the Jira issue? * https://issues.apache.org/jira/browse/SUBMARINE-380 ### How should this be tested? 1. execute `submarine-cloud/hack/kind-create-cluster.sh` 2. execute `submarine-cloud/hack/deploy-submarine.sh` 3. open `http://127.0.0.1` in chrome, you can see submarine workbench 4. execute `submarine-cloud/hack/deploy-submarine.sh -u`, uninstall submarine in kind 5. execute `kind delete cluster` * https://travis-ci.org/liuxunorg/submarine/builds/650709676 ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Xun Liu <liu...@apache.org> Closes #183 from liuxunorg/SUBMARINE-380 and squashes the following commits: 7725226 [Xun Liu] SUBMARINE-380. Optimize submarine-cloud to create kind cluster script --- submarine-cloud/hack/deploy-submarine.sh | 40 ++++++++++++---------- submarine-cloud/hack/kind | 27 +++++++++++++++ submarine-cloud/hack/kind-cluster-build.sh | 47 ++++++++++++++------------ submarine-cloud/hack/kubectl | 27 +++++++++++++++ submarine-cloud/hack/lib.sh | 54 ++++++++++++++++-------------- 5 files changed, 132 insertions(+), 63 deletions(-) diff --git a/submarine-cloud/hack/deploy-submarine.sh b/submarine-cloud/hack/deploy-submarine.sh index 52ece6d..410e8a2 100755 --- a/submarine-cloud/hack/deploy-submarine.sh +++ b/submarine-cloud/hack/deploy-submarine.sh @@ -23,8 +23,7 @@ SUBMARINE_HOME=${ROOT}/.. source $ROOT/hack/lib.sh -# Check requirements -hack::check_requirements +hack::ensure_kubectl # Install submarine in k8s cluster function install_submarine() { @@ -49,20 +48,27 @@ function install_submarine() { echo -n "Do you want to deploy submarine in k8s cluster now? [y/n]" read myselect if [[ "$myselect" == "y" || "$myselect" == "Y" ]]; then - if kubectl get configmap --namespace default | grep submarine-config >/dev/null ; then - kubectl delete configmap --namespace default submarine-config + if $KUBECTL_BIN get configmap --namespace default | grep submarine-config >/dev/null ; then + $KUBECTL_BIN delete configmap --namespace default submarine-config fi - kubectl create configmap --namespace default submarine-config --from-file=${ROOT}/hack/conf/submarine-site.xml --from-file=${ROOT}/hack/conf/log4j.properties + $KUBECTL_BIN create configmap --namespace default submarine-config --from-file=${ROOT}/hack/conf/submarine-site.xml --from-file=${ROOT}/hack/conf/log4j.properties - docker pull apache/submarine:operator-0.3.0-SNAPSHOT - kind load docker-image apache/submarine:operator-0.3.0-SNAPSHOT - kubectl apply -f $ROOT/manifests/submarine-operator/ + if ! docker inspect apache/submarine:operator-0.3.0-SNAPSHOT >/dev/null ; then + docker pull apache/submarine:operator-0.3.0-SNAPSHOT + fi + $KIND_BIN load docker-image apache/submarine:operator-0.3.0-SNAPSHOT + $KUBECTL_BIN apply -f $ROOT/manifests/submarine-operator/ + + if ! docker inspect apache/submarine:database-0.3.0-SNAPSHOT >/dev/null ; then + docker pull apache/submarine:database-0.3.0-SNAPSHOT + fi + $KIND_BIN load docker-image apache/submarine:database-0.3.0-SNAPSHOT - docker pull apache/submarine:database-0.3.0-SNAPSHOT - kind load docker-image apache/submarine:database-0.3.0-SNAPSHOT - docker pull apache/submarine:server-0.3.0-SNAPSHOT - kind load docker-image apache/submarine:server-0.3.0-SNAPSHOT - kubectl apply -f $ROOT/manifests/submarine-cluster/ + if ! docker inspect apache/submarine:server-0.3.0-SNAPSHOT >/dev/null ; then + docker pull apache/submarine:server-0.3.0-SNAPSHOT + fi + $KIND_BIN load docker-image apache/submarine:server-0.3.0-SNAPSHOT + $KUBECTL_BIN apply -f $ROOT/manifests/submarine-cluster/ cat <<EOF NOTE: You can open your browser and access the submarine workbench at http://127.0.0.1/ @@ -72,11 +78,11 @@ EOF # Uninstall submarine in k8s cluster function uninstall_submarine() { - if kubectl get configmap --namespace default | grep submarine-config >/dev/null ; then - kubectl delete configmap --namespace default submarine-config + if $KUBECTL_BIN get configmap --namespace default | grep submarine-config >/dev/null ; then + $KUBECTL_BIN delete configmap --namespace default submarine-config fi - kubectl delete -f $ROOT/manifests/submarine-operator/ - kubectl delete -f $ROOT/manifests/submarine-cluster/ + $KUBECTL_BIN delete -f $ROOT/manifests/submarine-operator/ + $KUBECTL_BIN delete -f $ROOT/manifests/submarine-cluster/ cat <<EOF NOTE: Submarine cluster has been deleted diff --git a/submarine-cloud/hack/kind b/submarine-cloud/hack/kind new file mode 100755 index 0000000..325d791 --- /dev/null +++ b/submarine-cloud/hack/kind @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -euo pipefail + +ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) + +source $ROOT/hack/lib.sh + +hack::ensure_kind + +$KIND_BIN "$@" diff --git a/submarine-cloud/hack/kind-cluster-build.sh b/submarine-cloud/hack/kind-cluster-build.sh index be0ceda..36242d7 100755 --- a/submarine-cloud/hack/kind-cluster-build.sh +++ b/submarine-cloud/hack/kind-cluster-build.sh @@ -22,6 +22,9 @@ cd $ROOT source $ROOT/hack/lib.sh +hack::ensure_kubectl +hack::ensure_kind + usage() { cat <<EOF This script use kind to create Kubernetes cluster, about kind please refer: https://kind.sigs.k8s.io/ @@ -31,7 +34,7 @@ Options: -h,--help prints the usage message -n,--name name of the Kubernetes cluster,default value: kind -c,--nodeNum the count of the cluster nodes,default value: 1 - -k,--k8sVersion version of the Kubernetes cluster,default value: v1.12.8 + -k,--k8sVersion version of the Kubernetes cluster,default value: v1.14.2 -v,--volumeNum the volumes number of each kubernetes node,default value: 1 Usage: $0 --name testCluster --nodeNum 4 --k8sVersion v1.12.9 @@ -77,7 +80,7 @@ done clusterName=${clusterName:-kind} nodeNum=${nodeNum:-1} -k8sVersion=${k8sVersion:-v1.12.8} +k8sVersion=${k8sVersion:-v1.14.2} volumeNum=${volumeNum:-1} echo "clusterName: ${clusterName}" @@ -85,9 +88,6 @@ echo "nodeNum: ${nodeNum}" echo "k8sVersion: ${k8sVersion}" echo "volumeNum: ${volumeNum}" -# Check requirements -hack::check_requirements - echo "############# start create cluster:[${clusterName}] #############" workDir=${HOME}/kind/${clusterName} mkdir -p ${workDir} @@ -144,12 +144,12 @@ EOF done echo "start to create k8s cluster" -kind create cluster --config ${configFile} --image kindest/node:${k8sVersion} --name=${clusterName} -export KUBECONFIG="${HOME}/.kube/kind-config-${clusterName}" +export KUBECONFIG=~/.kube/kind-config-${clusterName} +$KIND_BIN create cluster --config ${configFile} --image kindest/node:${k8sVersion} --name=${clusterName} echo "deploy docker registry in kind" registryNode=${clusterName}-control-plane -registryNodeIP=$(kubectl get nodes ${registryNode} -o template --template='{{range.status.addresses}}{{if eq .type "InternalIP"}}{{.address}}{{end}}{{end}}') +registryNodeIP=$($KUBECTL_BIN get nodes ${registryNode} -o template --template='{{range.status.addresses}}{{if eq .type "InternalIP"}}{{.address}}{{end}}{{end}}') registryFile=${workDir}/registry.yaml cat <<EOF >${registryFile} @@ -220,33 +220,38 @@ spec: - tcp-listen:5000,fork,reuseaddr - tcp-connect:${registryNodeIP}:5000 EOF -kubectl apply -f ${registryFile} +$KUBECTL_BIN apply -f ${registryFile} + +echo "load docker image registry:2 to kind" +if ! docker inspect registry:2 >/dev/null ; then + docker pull registry:2 +fi +$KIND_BIN load docker-image registry:2 # https://kind.sigs.k8s.io/docs/user/ingress/#ingress-nginx echo "setting up ingress on a kind cluster." # load ingress denpendence docker-image into kind -docker pull registry:2 -kind load docker-image registry:2 - -docker pull quay.io/kubernetes-ingress-controller/nginx-ingress-controller:master -kind load docker-image quay.io/kubernetes-ingress-controller/nginx-ingress-controller:master +if ! docker inspect quay.io/kubernetes-ingress-controller/nginx-ingress-controller:master >/dev/null ; then + docker pull quay.io/kubernetes-ingress-controller/nginx-ingress-controller:master +fi +$KIND_BIN load docker-image quay.io/kubernetes-ingress-controller/nginx-ingress-controller:master -kubectl apply -f $ROOT/hack/ingress/mandatory.yaml -kubectl apply -f $ROOT/hack/ingress/service-nodeport.yaml -kubectl patch deployments -n ingress-nginx nginx-ingress-controller -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx-ingress-controller","ports":[{"containerPort":80,"hostPort":80},{"containerPort":443,"hostPort":443}]}],"nodeSelector":{"ingress-ready":"true"},"tolerations":[{"key":"node-role.kubernetes.io/master","operator":"Equal","effect":"NoSchedule"}]}}}}' +$KUBECTL_BIN apply -f $ROOT/hack/ingress/mandatory.yaml +$KUBECTL_BIN apply -f $ROOT/hack/ingress/service-nodeport.yaml +$KUBECTL_BIN patch deployments -n ingress-nginx nginx-ingress-controller -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx-ingress-controller","ports":[{"containerPort":80,"hostPort":80},{"containerPort":443,"hostPort":443}]}],"nodeSelector":{"ingress-ready":"true"},"tolerations":[{"key":"node-role.kubernetes.io/master","operator":"Equal","effect":"NoSchedule"}]}}}}' echo "############# success create cluster:[${clusterName}] #############" echo "To start using your cluster, run:" -echo " export KUBECONFIG=\"${HOME}/.kube/kind-config-${clusterName}\"" -echo "" -cat <<EOF +echo " ./kubectl config use-context kind-${clusterName}" +echo " ./kubectl get pods -A" +echo <<EOF NOTE: In kind, nodes run docker network and cannot access host network. If you configured local HTTP proxy in your docker, images may cannot be pulled because http proxy is inaccessible. If you cannot remove http proxy settings, you can either whitelist image -domains in NO_PROXY environment or use 'docker pull <image> && kind load +domains in NO_PROXY environment or use 'docker pull <image> && $KIND_BIN load docker-image <image>' command to load images into nodes. EOF diff --git a/submarine-cloud/hack/kubectl b/submarine-cloud/hack/kubectl new file mode 100755 index 0000000..36a1a63 --- /dev/null +++ b/submarine-cloud/hack/kubectl @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -euo pipefail + +ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) + +source $ROOT/hack/lib.sh + +hack::ensure_kubectl + +$KUBECTL_BIN "$@" diff --git a/submarine-cloud/hack/lib.sh b/submarine-cloud/hack/lib.sh index 782fd1c..0d7d583 100755 --- a/submarine-cloud/hack/lib.sh +++ b/submarine-cloud/hack/lib.sh @@ -23,11 +23,13 @@ fi OS=$(go env GOOS) ARCH=$(go env GOARCH) -OUTPUT=${ROOT}/output +OUTPUT=${ROOT}/hack/output OUTPUT_BIN=${OUTPUT}/bin -KUBECTL_VERSION=1.12.10 + +KUBECTL_VERSION=1.14.2 KUBECTL_BIN=$OUTPUT_BIN/kubectl -KIND_VERSION=0.6.0 + +KIND_VERSION=0.7.0 KIND_BIN=$OUTPUT_BIN/kind test -d "$OUTPUT_BIN" || mkdir -p "$OUTPUT_BIN" @@ -44,6 +46,18 @@ function hack::ensure_kubectl() { if hack::verify_kubectl; then return 0 fi + + orig_kubectl_bin="$KUBECTL_BIN" + if command -v kubectl > /dev/null; then + KUBECTL_BIN="$(command -v kubectl)" + if hack::verify_kubectl; then + ln -sf "$KUBECTL_BIN" "$orig_kubectl_bin" + KUBECTL_BIN="$orig_kubectl_bin" + echo $KUBECTL_BIN + return 0 + fi + fi + echo "Installing kubectl v$KUBECTL_VERSION..." tmpfile=$(mktemp) trap "test -f $tmpfile && rm $tmpfile" RETURN @@ -64,6 +78,18 @@ function hack::ensure_kind() { if hack::verify_kind; then return 0 fi + + orig_kind_bin="$KIND_BIN" + if command -v kind > /dev/null; then + KIND_BIN="$(command -v kind)" + if hack::verify_kind; then + ln -sf "$KIND_BIN" "$orig_kind_bin" + KIND_BIN="$orig_kind_bin" + echo $KIND_BIN + return 0 + fi + fi + echo "Installing kind v$KIND_VERSION..." tmpfile=$(mktemp) trap "test -f $tmpfile && rm $tmpfile" RETURN @@ -76,25 +102,3 @@ function hack::ensure_kind() { function hack::version_ge() { [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$2" ] } - -function hack::check_requirements() { - # Check requirements - for requirement in kind docker kubectl - do - echo "############ check ${requirement} ##############" - if hash ${requirement} 2>/dev/null;then - echo "${requirement} have installed" - else - echo "this script needs ${requirement}, please install ${requirement} first." - if test ${requirement} = "kind"; then - hack::ensure_kind - echo "Please add $KIND_BIN to PATH variable or copy it to one of the locations $PATH" - fi - if test ${requirement} = "kubectl"; then - hack::ensure_kubectl - echo "Please add $KUBECTL_BIN to PATH variable or copy it to one of the locations $PATH" - fi - exit 1 - fi - done -} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org For additional commands, e-mail: dev-h...@submarine.apache.org