Deprecate shell config support

The current PS deprecates shell config support. Replaces the shell
support with exec support.

Closes: #11
Change-Id: I7a92cee9ddb14e3638c61f2452c269313e839b7d
This commit is contained in:
Sirisha Gopigiri 2021-03-08 14:04:06 +05:30
parent eba0d8a39c
commit b9df67fb08
15 changed files with 30 additions and 40 deletions

View File

@ -193,8 +193,11 @@ Config Roles:
ulimit, sysctl: Array objects specifiying the configuration of ulimit, sysctl: Array objects specifiying the configuration of
ulimit and sysctl on the kubernetes nodes. ulimit and sysctl on the kubernetes nodes.
kubeadm, shell: Array objects specifiying the kubeadm and shell kubeadm: Array object specifiying the kubeadm commands that would
commands that world be executed on the kubernetes nodes. 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 The demo_examples folder has some examples listed which can be
used to initially to play with the above variables used to initially to play with the above variables

View File

@ -63,7 +63,6 @@ class KubeInventory(object):
secret_value = self.api_instance.read_namespaced_secret( secret_value = self.api_instance.read_namespaced_secret(
labels["secret"], namespace) labels["secret"], namespace)
except ApiException as e: except ApiException as e:
print("Exception when calling Secret: %s\n" % e)
return False return False
if "username" in secret_value.data.keys(): if "username" in secret_value.data.keys():
username = (base64.b64decode( username = (base64.b64decode(
@ -127,7 +126,7 @@ class KubeInventory(object):
"items" "items"
] ]
except ApiException as e: except ApiException as e:
print("Exception when calling CoreV1Api->list_node: %s\n" % e) return False
for node in nodes: for node in nodes:
addresses = node["status"]["addresses"] addresses = node["status"]["addresses"]

View File

@ -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

View File

@ -0,0 +1,2 @@
#!/bin/bash
date;hostname;sleep 5

View File

@ -12,7 +12,5 @@ spec:
values: values:
- "master" - "master"
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh
kubeadm:
- command: "alpha certs check-expiration"

View File

@ -25,5 +25,5 @@ spec:
sequential: false sequential: false
match_host_groups: true match_host_groups: true
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh

View File

@ -15,7 +15,7 @@ spec:
stop_on_failure: false stop_on_failure: false
max_failure_percentage: 30 max_failure_percentage: 30
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh
kubeadm: kubeadm:
- command: "alpha certs check-expiration" - command: "alpha certs check-expiration"

View File

@ -14,5 +14,5 @@ spec:
- "worker" - "worker"
max_hosts_parallel: 2 max_hosts_parallel: 2
config: config:
shell: exec:
- command: "date;hostname;sleep 5" - name: test.sh

View File

@ -14,7 +14,7 @@ spec:
values: values:
- "master" - "master"
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh
kubeadm: kubeadm:
- command: "alpha certs check-expiration" - command: "alpha certs check-expiration"

View File

@ -15,7 +15,7 @@ spec:
values: values:
- "master" - "master"
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh
kubeadm: kubeadm:
- command: "alpha certs check-expiration" - command: "alpha certs check-expiration"

View File

@ -14,5 +14,5 @@ spec:
- "worker" - "worker"
sequential: true sequential: true
config: config:
shell: exec:
- command: "date;hostname;sleep 5" - name: test.sh

View File

@ -28,5 +28,5 @@ spec:
sequential: true sequential: true
match_host_groups: true match_host_groups: true
config: config:
shell: exec:
- command: "date;hostname;sleep 5" - name: test.sh

View File

@ -14,7 +14,7 @@ spec:
- "master" - "master"
stop_on_failure: true stop_on_failure: true
config: config:
shell: exec:
- command: "date;hostname" - name: test.sh
kubeadm: kubeadm:
- command: "alpha certs check-expiration" - command: "alpha certs check-expiration"

View File

@ -34,8 +34,9 @@ in the host-groups of the CR object
* Reconcile on failed nodes, based on reconcile period - feature available * Reconcile on failed nodes, based on reconcile period - feature available
from ansible-operator from ansible-operator
* Current support is available to perform `sysctl` and `ulimit` operations * 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 kubernetes nodes.
on the 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 * Display the status of each Hostconfig CR object as part of the
`kubectl describe hostconfig <name>` `kubectl describe hostconfig <name>`
* We have also added an anisble role to execute the * We have also added an anisble role to execute the

View File

@ -44,7 +44,7 @@ check_status(){
hosts=( "${@:2:$1}" ); shift "$(( $1 + 1 ))" hosts=( "${@:2:$1}" ); shift "$(( $1 + 1 ))"
pre_host_date="" pre_host_date=""
for j in "${!hosts[@]}"; do 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 echo $kubectl_stdout
host_date=$(date --date="$kubectl_stdout" +"%s") host_date=$(date --date="$kubectl_stdout" +"%s")
if [ ! -z "$pre_host_date" ]; then if [ ! -z "$pre_host_date" ]; then