diff --git a/README.md b/README.md index f2d4cf0..15919ca 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,9 @@ git clone https://opendev.org/airship/hostconfig-operator.git cd hostconfig-operator ``` -2. To install kind, kubectl and operator-sdk utilities +2. To install docker, kind, kubectl and necessary utilities ``` -./tools/deployment/00_install_kind.sh -./tools/deployment/01_install_kubectl.sh +./tools/deployment/00_install_prerequsite.sh ``` 3. Create hostconfig kind cluster diff --git a/playbooks/airship-hostconfig-operator.yaml b/playbooks/airship-hostconfig-operator.yaml index 9f569bd..9acd42b 100644 --- a/playbooks/airship-hostconfig-operator.yaml +++ b/playbooks/airship-hostconfig-operator.yaml @@ -15,8 +15,7 @@ - name: "set default gate scripts" set_fact: gate_scripts_default: - - ./tools/deployment/00_install_kind.sh - - ./tools/deployment/01_install_kubectl.sh + - ./tools/deployment/00_install_prerequsite.sh - ./tools/deployment/10_create_hostconfig_cluster.sh - ./tools/deployment/20_configure_ssh_on_nodes.sh - ./tools/deployment/30_create_labels.sh diff --git a/tools/deployment/00_install_kind.sh b/tools/deployment/00_install_kind.sh deleted file mode 100755 index 76b2bb2..0000000 --- a/tools/deployment/00_install_kind.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# 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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This downloads kind, puts it in a temp directory, and prints the directory -set -e - -KIND_VERSION="v0.8.1" - -echo "Installing Kind Version $KIND_VERSION" -: ${KIND_URL:="https://kind.sigs.k8s.io/dl/$KIND_VERSION/kind-$(uname)-amd64"} -TMP=$(mktemp -d) -KIND="${TMP}/kind" - -wget -O ${KIND} ${KIND_URL} -chmod +x ${KIND} -sudo cp ${KIND} /usr/local/bin diff --git a/tools/deployment/00_install_prerequsite.sh b/tools/deployment/00_install_prerequsite.sh new file mode 100755 index 0000000..1133450 --- /dev/null +++ b/tools/deployment/00_install_prerequsite.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This downloads kind, puts it in a temp directory, and prints the directory +set -xe + +export KIND_VERSION=${KIND_VERSION:="v0.8.1"} +export KIND_URL=${KIND_URL:="https://kind.sigs.k8s.io/dl/$KIND_VERSION/kind-$(uname)-amd64"} +export KUBE_VERSION=${KUBE_VERSION:="v1.18.6"} +export KUBE_URL=${KUBE_URL:="https://storage.googleapis.com"} +export HCO_WS=${HCO_WS:-$PWD} +export TMP_DIR=${TMP_DIR:-"$(dirname $(mktemp -u))"} + +ANSIBLE_CFG=${ANSIBLE_CFG:-"${HOME}/.ansible.cfg"} +ANSIBLE_HOSTS=${ANSIBLE_HOSTS:-"${TMP_DIR}/ansible_hosts"} +PLAYBOOK_CONFIG=${PLAYBOOK_CONFIG:-"${TMP_DIR}/config.yaml"} + +echo "Installing Necessary OS Packages" +pkg_check() { + for pkg in $@; do + sudo dpkg -s $pkg &> /dev/null || sudo DEBIAN_FRONTEND=noninteractive apt -y install $pkg + done +} + +pkg_check curl wget python3-pip python3-setuptools ca-certificates make + +echo "Installing Kind Version $KIND_VERSION" +sudo wget -O /usr/local/bin/kind ${KIND_URL} +sudo chmod +x /usr/local/bin/kind + +# Install kubectl +echo "Installing Kubectl Version $KUBE_VERSION" +sudo wget -O /usr/local/bin/kubectl \ + "${KUBE_URL}"/kubernetes-release/release/"${KUBE_VERSION}"/bin/linux/amd64/kubectl + +sudo chmod +x /usr/local/bin/kubectl + +mkdir -p "$TMP_DIR" +envsubst <"${HCO_WS}/tools/deployment/config_template.yaml" > "$PLAYBOOK_CONFIG" + +PACKAGES="ansible netaddr" +if [[ -z "${http_proxy}" ]]; then + sudo pip3 install $PACKAGES +else + sudo pip3 --proxy "${http_proxy}" install $PACKAGES +fi + +echo "primary ansible_host=localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python3" > "$ANSIBLE_HOSTS" +printf "[defaults]\nroles_path = %s/roles\n" "$HCO_WS" > "$ANSIBLE_CFG" + +ansible-playbook -i "$ANSIBLE_HOSTS" \ + playbooks/airship-hostconfig-operator-deploy-docker.yaml \ + -e @"$PLAYBOOK_CONFIG" diff --git a/tools/deployment/clean.sh b/tools/deployment/clean.sh index b8e1034..46c1708 100755 --- a/tools/deployment/clean.sh +++ b/tools/deployment/clean.sh @@ -15,4 +15,4 @@ set -xe kind delete cluster --name hostconfig sudo docker rmi -f $(sudo docker images --all -q | xargs -I{} sudo bash -c 'if docker image inspect {} | grep -q kind; then echo {} ; fi') -rm -rf ssh +rm -rf ssh ~/.ansible.cfg diff --git a/tools/deployment/01_install_kubectl.sh b/tools/deployment/config_template.yaml old mode 100755 new mode 100644 similarity index 66% rename from tools/deployment/01_install_kubectl.sh rename to tools/deployment/config_template.yaml index ecb0139..2f63950 --- a/tools/deployment/01_install_kubectl.sh +++ b/tools/deployment/config_template.yaml @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - # 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 @@ -12,13 +10,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -xe - -: ${KUBE_VERSION:="v1.18.6"} - -# Install kubectl -URL="https://storage.googleapis.com" -sudo wget -O /usr/local/bin/kubectl \ - "${URL}"/kubernetes-release/release/"${KUBE_VERSION}"/bin/linux/amd64/kubectl - -sudo chmod +x /usr/local/bin/kubectl +--- +local_src_dir: "$HCO_WS" +ansible_user: root +proxy: + enabled: "$USE_PROXY" + http: "$HTTP_PROXY" + https: "$HTTPS_PROXY" + noproxy: "$NO_PROXY" diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 498f3ba..aef6280 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -13,7 +13,6 @@ - job: name: airship-hostconfig-operator-test nodeset: airship-hostconfig-single-node - pre-run: playbooks/airship-hostconfig-operator-deploy-docker.yaml timeout: 3600 run: playbooks/airship-hostconfig-operator.yaml post-run: @@ -21,8 +20,7 @@ attempts: 1 vars: gate_scripts: - - ./tools/deployment/00_install_kind.sh - - ./tools/deployment/01_install_kubectl.sh + - ./tools/deployment/00_install_prerequsite.sh - ./tools/deployment/10_create_hostconfig_cluster.sh - ./tools/deployment/20_configure_ssh_on_nodes.sh - ./tools/deployment/30_create_labels.sh