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

View File

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

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:
- "master"
config:
shell:
- command: "date;hostname"
kubeadm:
- command: "alpha certs check-expiration"
exec:
- name: test.sh

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <name>`
* We have also added an anisble role to execute the

View File

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