[CORD-3083] Prep for validation jobs on automation-tools repo
Change-Id: Ia61993c88f99497273599d359789f9d9b0040887
diff --git a/kubespray-installer/copy-ssh-keys.sh b/kubespray-installer/copy-ssh-keys.sh
index ff1918b..4683779 100755
--- a/kubespray-installer/copy-ssh-keys.sh
+++ b/kubespray-installer/copy-ssh-keys.sh
@@ -17,8 +17,9 @@
NODES=($@)
for NODE in "${NODES[@]}";
- do
- ssh-keygen -R ${NODE}
- ssh cord@${NODE} 'mkdir -p .ssh'
- cat ~/.ssh/id_rsa.pub | ssh cord@${NODE} 'cat >> .ssh/authorized_keys'
- done
+do
+ ssh-keygen -R "${NODE}"
+ ssh "cord@${NODE}" 'mkdir -p .ssh'
+ ssh "cord@${NODE}" 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
+done
+
diff --git a/kubespray-installer/k8s-requirements.yaml b/kubespray-installer/k8s-requirements.yaml
index a34b68f..c1649d5 100644
--- a/kubespray-installer/k8s-requirements.yaml
+++ b/kubespray-installer/k8s-requirements.yaml
@@ -12,7 +12,6 @@
# 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.
-#
- hosts: all
gather_facts: False
@@ -20,9 +19,13 @@
tasks:
- name: Update apt-get
raw: sudo apt-get update -qq
+ tags:
+ - skip_ansible_lint # raw command in prep for python install
- name: Install python 2.7
raw: sudo apt-get install -qq python2.7
+ tags:
+ - skip_ansible_lint # raw command to install python
- name: Install prerequisites for using PPA repos
apt:
@@ -47,7 +50,6 @@
- name: Make sure Ansible is newest version
apt:
name: "ansible"
- state: latest
update_cache: yes
cache_valid_time: 3600
@@ -66,4 +68,7 @@
state: absent
- name: Disable swap
- command: swapoff -a
\ No newline at end of file
+ command: "swapoff -a"
+ tags:
+ - skip_ansible_lint # there isn't a module for this, command is idempotent
+
diff --git a/kubespray-installer/setup.sh b/kubespray-installer/setup.sh
index 61902cd..6c89bfc 100755
--- a/kubespray-installer/setup.sh
+++ b/kubespray-installer/setup.sh
@@ -14,15 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-################################################
-# #
-# Installs Kubespray on remote target machines #
-# #
-################################################
-
#
# Installs Kubespray on remote target machines.
#
+
+set +e -u -o pipefail
+
install_kubespray () {
# Cleanup Old Kubespray Installations
echo -e "\nCleaning Up Old Kubespray Installation" && \
@@ -34,29 +31,29 @@
# Generate inventory and var files
echo -e "\nGenerating The Inventory File" && \
- rm -rf inventories/${DEPLOYMENT_NAME} && \
- cp -r kubespray/inventory inventories/${DEPLOYMENT_NAME} && \
- CONFIG_FILE=inventories/${DEPLOYMENT_NAME}/inventory.cfg python3 kubespray/contrib/inventory_builder/inventory.py ${NODES[@]} && \
+ rm -rf "inventories/${DEPLOYMENT_NAME}" && \
+ cp -r "kubespray/inventory inventories/${DEPLOYMENT_NAME}" && \
+ CONFIG_FILE="inventories/${DEPLOYMENT_NAME}/inventory.cfg" python3 kubespray/contrib/inventory_builder/inventory.py "${NODES[@]}" && \
# Edit inventory var files
- NODE_LIST=`echo ${NODES[@]}`
+ NODE_LIST=$(echo "${NODES[@]}")
ansible-playbook k8s-configs.yaml --extra-vars "deployment_name=${DEPLOYMENT_NAME} k8s_nodes='${NODE_LIST}'"
# Copy SSH keys
echo -e "\nCopying Public SSH Keys To Remote Machines" && \
- source copy-ssh-keys.sh ${NODES[@]} && \
+ source copy-ssh-keys.sh "${NODES[@]}" && \
# Prepare Target Machines
echo -e "\nInstalling Prerequisites On Remote Machines" && \
- ansible-playbook -i inventories/${DEPLOYMENT_NAME}/inventory.cfg k8s-requirements.yaml && \
+ ansible-playbook -i "inventories/${DEPLOYMENT_NAME}/inventory.cfg" k8s-requirements.yaml && \
# Install Kubespray
echo -e "\nInstalling Kubespray" && \
- ansible-playbook -i inventories/${DEPLOYMENT_NAME}/inventory.cfg kubespray/cluster.yml -b -v && \
+ ansible-playbook -i "inventories/${DEPLOYMENT_NAME}/inventory.cfg" kubespray/cluster.yml -b -v && \
# Export the Kubespray Config Location
echo -e "\nLoading Kubespray Configuration" && \
- cp kubespray/artifacts/admin.conf configs/${DEPLOYMENT_NAME}.conf
+ cp kubespray/artifacts/admin.conf "configs/${DEPLOYMENT_NAME}.conf"
}
#
@@ -71,7 +68,7 @@
#
helm_init () {
echo -e "\nInitializing Helm" && \
- source_kubeconfig $DEPLOYMENT_NAME && \
+ source_kubeconfig "$DEPLOYMENT_NAME" && \
helm init --upgrade
}
@@ -80,7 +77,7 @@
#
deploy_insecure_registry () {
echo -e "\nDeploying insecure registry" && \
- source_kubeconfig $DEPLOYMENT_NAME && \
+ source_kubeconfig "$DEPLOYMENT_NAME" && \
helm install stable/docker-registry --set service.nodePort=30500,service.type=NodePort -n docker-registry
}
@@ -89,7 +86,7 @@
# operations.
#
check_pod_name () {
- if [ -z $DEPLOYMENT_NAME ]
+ if [ -z "$DEPLOYMENT_NAME" ]
then
echo "Missing option: podname" >&2
echo " "
@@ -131,9 +128,9 @@
case $CLI_OPT in
-i | --install)
check_pod_name
- install_kubespray $DEPLOYMENT_NAME $NODES
- helm_init $DEPLOYMENT_NAME
- deploy_insecure_registry $DEPLOYMENT_NAME
+ install_kubespray "$DEPLOYMENT_NAME" "$NODES"
+ helm_init "$DEPLOYMENT_NAME"
+ deploy_insecure_registry "$DEPLOYMENT_NAME"
exit 0
;;
-h | --help)
@@ -142,7 +139,7 @@
;;
-s | --source)
check_pod_name
- source_kubeconfig $DEPLOYMENT_NAME
+ source_kubeconfig "$DEPLOYMENT_NAME"
return 0
;;
--) # End of all options
@@ -150,7 +147,7 @@
break
;;
*)
- echo Error: Unknown option: $CLI_OPT >&2
+ echo Error: Unknown option: "$CLI_OPT" >&2
echo " "
display_help
exit -1
diff --git a/scripts/ansiblelint.sh b/scripts/ansiblelint.sh
new file mode 100755
index 0000000..f97d186
--- /dev/null
+++ b/scripts/ansiblelint.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+# ansiblelint.sh - check all yaml files that they pass the ansible-lint tool
+
+set +e -u -o pipefail
+fail_ansible=0
+
+# verify that we have ansible-lint installed
+command -v ansible-lint >/dev/null 2>&1 || { echo "ansible-lint not found, please install it" >&2; exit 1; }
+
+# when not running under Jenkins, use current dir as workspace
+WORKSPACE=${WORKSPACE:-.}
+
+echo "=> Linting Ansible Code with $(ansible-lint --version)"
+
+while IFS= read -r -d '' yf
+do
+ echo "==> CHECKING: ${yf}"
+ ansible-lint -p "${yf}"
+ rc=$?
+ if [[ $rc != 0 ]]; then
+ echo "==> LINTING FAIL: ${yf}"
+ fail_ansible=1
+ fi
+done < <(find "${WORKSPACE}" \( -name "*.yml" -o -name "*.yaml" \) -print0)
+
+exit ${fail_ansible}
diff --git a/scripts/shcheck.sh b/scripts/shcheck.sh
new file mode 100755
index 0000000..2abe89c
--- /dev/null
+++ b/scripts/shcheck.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+# shcheck.sh - check shell scripts with shellcheck
+
+set +e -u -o pipefail
+fail_shellcheck=0
+
+# verify that we have shellcheck-lint installed
+command -v shellcheck >/dev/null 2>&1 || { echo "shellcheck not found, please install it" >&2; exit 1; }
+
+# when not running under Jenkins, use current dir as workspace
+WORKSPACE=${WORKSPACE:-.}
+
+echo "=> Linting shell script with $(shellcheck --version)"
+
+while IFS= read -r -d '' sf
+do
+ echo "==> CHECKING: ${sf}"
+ shellcheck "${sf}"
+ rc=$?
+ if [[ $rc != 0 ]]; then
+ echo "==> LINTING FAIL: ${sf}"
+ fail_shellcheck=1
+ fi
+done < <(find "${WORKSPACE}" \( -name "*.sh" -o -name "*.bash" \) -print0)
+
+exit ${fail_shellcheck}
+