diff --git a/README.md b/README.md index 48f72bb..84b6300 100644 --- a/README.md +++ b/README.md @@ -193,8 +193,11 @@ Config Roles: ulimit, sysctl: Array objects specifiying the configuration of ulimit and sysctl on the kubernetes nodes. -kubeadm, shell: Array objects specifiying the kubeadm and shell -commands that world be executed on the kubernetes nodes. +kubeadm: Array object specifiying the kubeadm commands that would +be executed on the kubernetes nodes. + +exec: Array object specifying list of scripts along with arguments +and environment variables that can be executed on the nodes. The demo_examples folder has some examples listed which can be used to initially to play with the above variables diff --git a/airship-host-config/inventory/dynamic_inventory.py b/airship-host-config/inventory/dynamic_inventory.py index 340ec1a..c906ee0 100755 --- a/airship-host-config/inventory/dynamic_inventory.py +++ b/airship-host-config/inventory/dynamic_inventory.py @@ -63,7 +63,6 @@ class KubeInventory(object): secret_value = self.api_instance.read_namespaced_secret( labels["secret"], namespace) except ApiException as e: - print("Exception when calling Secret: %s\n" % e) return False if "username" in secret_value.data.keys(): username = (base64.b64decode( @@ -127,7 +126,7 @@ class KubeInventory(object): "items" ] except ApiException as e: - print("Exception when calling CoreV1Api->list_node: %s\n" % e) + return False for node in nodes: addresses = node["status"]["addresses"] diff --git a/airship-host-config/roles/shell/tasks/main.yml b/airship-host-config/roles/shell/tasks/main.yml deleted file mode 100644 index b167c78..0000000 --- a/airship-host-config/roles/shell/tasks/main.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# To execute shell commands on the kubernetes nodes -# List of commands can be specified -- name: Execute shell command on nodes - shell: "{{ shell_item.command }}" - with_items: "{{ config.shell }}" - loop_control: - loop_var: shell_item - register: shell_output - -- name: shell output - debug: msg={{ shell_output }} - when: shell_output is defined diff --git a/airship-host-config/scripts/test.sh b/airship-host-config/scripts/test.sh new file mode 100644 index 0000000..bdaba39 --- /dev/null +++ b/airship-host-config/scripts/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +date;hostname;sleep 5 diff --git a/demo_examples/example_host_groups.yaml b/demo_examples/example_host_groups.yaml index 9b1d11a..0563abb 100644 --- a/demo_examples/example_host_groups.yaml +++ b/demo_examples/example_host_groups.yaml @@ -12,7 +12,5 @@ spec: values: - "master" config: - shell: - - command: "date;hostname" - kubeadm: - - command: "alpha certs check-expiration" + exec: + - name: test.sh diff --git a/demo_examples/example_match_host_groups.yaml b/demo_examples/example_match_host_groups.yaml index 1aa1ad9..c51e1a4 100644 --- a/demo_examples/example_match_host_groups.yaml +++ b/demo_examples/example_match_host_groups.yaml @@ -25,5 +25,5 @@ spec: sequential: false match_host_groups: true config: - shell: - - command: "date;hostname" + exec: + - name: test.sh diff --git a/demo_examples/example_max_percentage.yaml b/demo_examples/example_max_percentage.yaml index ce85aad..8fdcb0c 100644 --- a/demo_examples/example_max_percentage.yaml +++ b/demo_examples/example_max_percentage.yaml @@ -15,7 +15,7 @@ spec: stop_on_failure: false max_failure_percentage: 30 config: - shell: - - command: "date;hostname" + exec: + - name: test.sh kubeadm: - command: "alpha certs check-expiration" diff --git a/demo_examples/example_parallel.yaml b/demo_examples/example_parallel.yaml index e4550eb..75957c5 100644 --- a/demo_examples/example_parallel.yaml +++ b/demo_examples/example_parallel.yaml @@ -14,5 +14,5 @@ spec: - "worker" max_hosts_parallel: 2 config: - shell: - - command: "date;hostname;sleep 5" + exec: + - name: test.sh diff --git a/demo_examples/example_reconcile.yaml b/demo_examples/example_reconcile.yaml index 60e7859..2862f46 100644 --- a/demo_examples/example_reconcile.yaml +++ b/demo_examples/example_reconcile.yaml @@ -14,7 +14,7 @@ spec: values: - "master" config: - shell: - - command: "date;hostname" + exec: + - name: test.sh kubeadm: - command: "alpha certs check-expiration" diff --git a/demo_examples/example_reconcile_iterations.yaml b/demo_examples/example_reconcile_iterations.yaml index 5e4abf3..74bf359 100644 --- a/demo_examples/example_reconcile_iterations.yaml +++ b/demo_examples/example_reconcile_iterations.yaml @@ -15,7 +15,7 @@ spec: values: - "master" config: - shell: - - command: "date;hostname" + exec: + - name: test.sh kubeadm: - command: "alpha certs check-expiration" diff --git a/demo_examples/example_sequential.yaml b/demo_examples/example_sequential.yaml index 2580bc4..0f9ed55 100644 --- a/demo_examples/example_sequential.yaml +++ b/demo_examples/example_sequential.yaml @@ -14,5 +14,5 @@ spec: - "worker" sequential: true config: - shell: - - command: "date;hostname;sleep 5" + exec: + - name: test.sh diff --git a/demo_examples/example_sequential_match_host_groups.yaml b/demo_examples/example_sequential_match_host_groups.yaml index d28d690..c380a1b 100644 --- a/demo_examples/example_sequential_match_host_groups.yaml +++ b/demo_examples/example_sequential_match_host_groups.yaml @@ -28,5 +28,5 @@ spec: sequential: true match_host_groups: true config: - shell: - - command: "date;hostname;sleep 5" + exec: + - name: test.sh diff --git a/demo_examples/example_stop_on_failure.yaml b/demo_examples/example_stop_on_failure.yaml index 2f42602..1832bc4 100644 --- a/demo_examples/example_stop_on_failure.yaml +++ b/demo_examples/example_stop_on_failure.yaml @@ -14,7 +14,7 @@ spec: - "master" stop_on_failure: true config: - shell: - - command: "date;hostname" + exec: + - name: test.sh kubeadm: - command: "alpha certs check-expiration" diff --git a/docs/Overview.md b/docs/Overview.md index 77361f4..5948311 100644 --- a/docs/Overview.md +++ b/docs/Overview.md @@ -34,8 +34,9 @@ in the host-groups of the CR object * Reconcile on failed nodes, based on reconcile period - feature available from ansible-operator * Current support is available to perform `sysctl` and `ulimit` operations -on the kubernetes nodes. Also any shell command that needs to be executed -on the nodes. +on the kubernetes nodes. +* Any shell command that needs to be executed on the nodes can use the `exec` +config option. * Display the status of each Hostconfig CR object as part of the `kubectl describe hostconfig ` * We have also added an anisble role to execute the diff --git a/tools/deployment/50_test_hostconfig_cr.sh b/tools/deployment/50_test_hostconfig_cr.sh index c248bc0..d8a636c 100755 --- a/tools/deployment/50_test_hostconfig_cr.sh +++ b/tools/deployment/50_test_hostconfig_cr.sh @@ -44,7 +44,7 @@ check_status(){ hosts=( "${@:2:$1}" ); shift "$(( $1 + 1 ))" pre_host_date="" for j in "${!hosts[@]}"; do - kubectl_stdout=$(kubectl get hostconfig $hostconfig -o "jsonpath={.status.hostConfigStatus.${hosts[j]}.Execute\ shell\ command\ on\ nodes.results[0][0].Execute\ shell\ command\ on\ nodes.stdout}" | head -1) + kubectl_stdout=$(kubectl get hostconfig $hostconfig -o "jsonpath={.status.hostConfigStatus.${hosts[j]}.loop\ over\ each\ exec.results[0][2].exec\ script\ command.stdout}" | head -1) echo $kubectl_stdout host_date=$(date --date="$kubectl_stdout" +"%s") if [ ! -z "$pre_host_date" ]; then