Uplift base image for hostconfig-operator
* uplift ansible-operator image from v0.17.0 to v1.13.1 * add cleanup for dnf cache * copy callback plugin to correct ansible path * update python version in inventory and filters * update inventory variables and annotations to align with ansible-operator greater than v1.0 Signed-off-by: Sreejith Punnapuzha <Sreejith.Punnapuzha@outlook.com> Change-Id: I0aa5b17fec91d589d1dce0e76f1de3ed07b002f8
This commit is contained in:
parent
6af4deb077
commit
9d263d74ee
11
Dockerfile
11
Dockerfile
|
@ -1,10 +1,10 @@
|
||||||
# Ansible Operator base image
|
# Ansible Operator base image
|
||||||
FROM quay.io/operator-framework/ansible-operator:v0.17.0
|
FROM quay.io/operator-framework/ansible-operator:v1.13.1
|
||||||
|
|
||||||
# Installing dependency libraries
|
# Installing dependency libraries
|
||||||
COPY airship-host-config/requirements.yml ${HOME}/requirements.yml
|
COPY airship-host-config/requirements.yml ${HOME}/requirements.yml
|
||||||
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
|
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
|
||||||
&& chmod -R ug+rwx ${HOME}/.ansible
|
&& chmod -R ug+rwx ${HOME}/.ansible
|
||||||
|
|
||||||
# Installing ssh clients - used to connect to kubernetes nodes
|
# Installing ssh clients - used to connect to kubernetes nodes
|
||||||
USER root
|
USER root
|
||||||
|
@ -15,8 +15,9 @@ RUN dnf install dbus libnghttp2 python3-librepo dbus-libs librepo dbus-daemon \
|
||||||
platform-python-pip python3-pip libcom_err gnupg2 vim-minimal libstdc++ \
|
platform-python-pip python3-pip libcom_err gnupg2 vim-minimal libstdc++ \
|
||||||
python3-libs systemd-libs libssh-config glib2 python3-pip-wheel libsolv \
|
python3-libs systemd-libs libssh-config glib2 python3-pip-wheel libsolv \
|
||||||
gdb-gdbserver sqlite-libs libgcrypt libgcc pcre2 glibc-common expat libxml2 \
|
gdb-gdbserver sqlite-libs libgcrypt libgcc pcre2 glibc-common expat libxml2 \
|
||||||
libcurl glibc-minimal-langpack libpcap openssh-clients sshpass -y
|
libcurl glibc-minimal-langpack libpcap openssh-clients sshpass -y \
|
||||||
USER ansible-operator
|
&& dnf clean all && rm -rf /var/cache/yum
|
||||||
|
USER ansible
|
||||||
|
|
||||||
# Configuration for ansible
|
# Configuration for ansible
|
||||||
COPY airship-host-config/build/ansible.cfg /etc/ansible/ansible.cfg
|
COPY airship-host-config/build/ansible.cfg /etc/ansible/ansible.cfg
|
||||||
|
@ -39,7 +40,7 @@ COPY airship-host-config/plugins/ ${HOME}/plugins/
|
||||||
# ansible-runner unable to pick custom callback plugins specified in any other directory other than /usr/local/lib/python3.6/site-packages/ansible/plugins/callback
|
# ansible-runner unable to pick custom callback plugins specified in any other directory other than /usr/local/lib/python3.6/site-packages/ansible/plugins/callback
|
||||||
# ansible-runner is overriding the ANSIBLE_CALLBACK_PLUGINS Environment variable
|
# ansible-runner is overriding the ANSIBLE_CALLBACK_PLUGINS Environment variable
|
||||||
# https://github.com/ansible/ansible-runner/blob/stable/1.3.x/ansible_runner/runner_config.py#L178
|
# https://github.com/ansible/ansible-runner/blob/stable/1.3.x/ansible_runner/runner_config.py#L178
|
||||||
COPY airship-host-config/plugins/callback/hostconfig_k8_cr_status.py /usr/local/lib/python3.6/site-packages/ansible/plugins/callback/
|
COPY airship-host-config/plugins/callback/hostconfig_k8_cr_status.py /usr/local/lib/python3.8/site-packages/ansible/plugins/callback/
|
||||||
|
|
||||||
# Copying scripts folder used by exec configuration
|
# Copying scripts folder used by exec configuration
|
||||||
COPY airship-host-config/scripts/ ${HOME}/scripts/
|
COPY airship-host-config/scripts/ ${HOME}/scripts/
|
||||||
|
|
|
@ -33,6 +33,9 @@ spec:
|
||||||
- name: airship-host-config
|
- name: airship-host-config
|
||||||
image: "AIRSHIP_HOSTCONFIG_IMAGE"
|
image: "AIRSHIP_HOSTCONFIG_IMAGE"
|
||||||
imagePullPolicy: "PULL_POLICY"
|
imagePullPolicy: "PULL_POLICY"
|
||||||
|
args:
|
||||||
|
- --leader-elect
|
||||||
|
- --leader-election-id=airship-host-config
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- mountPath: /tmp/ansible-operator/runner
|
- mountPath: /tmp/ansible-operator/runner
|
||||||
name: runner
|
name: runner
|
||||||
|
@ -45,8 +48,6 @@ spec:
|
||||||
valueFrom:
|
valueFrom:
|
||||||
fieldRef:
|
fieldRef:
|
||||||
fieldPath: metadata.name
|
fieldPath: metadata.name
|
||||||
- name: OPERATOR_NAME
|
|
||||||
value: "airship-host-config"
|
|
||||||
- name: ANSIBLE_FILTER_PLUGINS
|
- name: ANSIBLE_FILTER_PLUGINS
|
||||||
value: /opt/ansible/plugins/filter
|
value: /opt/ansible/plugins/filter
|
||||||
- name: ANSIBLE_FORKS
|
- name: ANSIBLE_FORKS
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3.8
|
||||||
|
|
||||||
# Python code to build Inventory dynamically based on the kubernetes nodes
|
# Python code to build Inventory dynamically based on the kubernetes nodes
|
||||||
# present in the cluster and labels and annotations associated
|
# present in the cluster and labels and annotations associated
|
||||||
|
|
|
@ -55,8 +55,8 @@ class CallbackModule(CallbackBase):
|
||||||
def v2_playbook_on_play_start(self, play):
|
def v2_playbook_on_play_start(self, play):
|
||||||
self.vm = play.get_variable_manager()
|
self.vm = play.get_variable_manager()
|
||||||
self.host_vars = self.vm.get_vars()['hostvars']
|
self.host_vars = self.vm.get_vars()['hostvars']
|
||||||
self.hostConfigName = self.host_vars['localhost']['meta']['name']
|
self.hostConfigName = self.host_vars['localhost']['ansible_operator_meta']['name']
|
||||||
self.namespace = self.host_vars['localhost']['meta']['namespace']
|
self.namespace = self.host_vars['localhost']['ansible_operator_meta']['namespace']
|
||||||
|
|
||||||
# This function is triggered when a certain task fails with
|
# This function is triggered when a certain task fails with
|
||||||
# unreachable state
|
# unreachable state
|
||||||
|
@ -119,7 +119,7 @@ class CallbackModule(CallbackBase):
|
||||||
if k8_hostname not in self.host_config_status.keys():
|
if k8_hostname not in self.host_config_status.keys():
|
||||||
self.host_config_status[k8_hostname] = dict()
|
self.host_config_status[k8_hostname] = dict()
|
||||||
if task_name in self.host_config_status[k8_hostname].keys():
|
if task_name in self.host_config_status[k8_hostname].keys():
|
||||||
status[task_name] = host_config_status[k8_hostname][task_name]
|
status[task_name] = self.host_config_status[k8_hostname][task_name]
|
||||||
status[task_name] = dict()
|
status[task_name] = dict()
|
||||||
check_keys = ["stdout", "stderr", "msg"]
|
check_keys = ["stdout", "stderr", "msg"]
|
||||||
for key in check_keys:
|
for key in check_keys:
|
||||||
|
@ -210,7 +210,7 @@ class CallbackModule(CallbackBase):
|
||||||
['_hostconfig_airshipit_org_hostconfig']\
|
['_hostconfig_airshipit_org_hostconfig']\
|
||||||
['metadata']['annotations']
|
['metadata']['annotations']
|
||||||
reconcile_status = dict()
|
reconcile_status = dict()
|
||||||
if "ansible.operator-sdk/reconcile-period" in annotations.keys():
|
if "ansible.sdk.operatorframework.io/reconcile-period" in annotations.keys():
|
||||||
iterations = 0
|
iterations = 0
|
||||||
pre_iter = None
|
pre_iter = None
|
||||||
if 'reconcileStatus' in cr_obj['status'].keys() and \
|
if 'reconcileStatus' in cr_obj['status'].keys() and \
|
||||||
|
@ -219,12 +219,12 @@ class CallbackModule(CallbackBase):
|
||||||
pre_iter = cr_obj['status']['reconcileStatus']\
|
pre_iter = cr_obj['status']['reconcileStatus']\
|
||||||
['completed_iterations']
|
['completed_iterations']
|
||||||
# Checks if the reconcile-interval or period is specified
|
# Checks if the reconcile-interval or period is specified
|
||||||
if "ansible.operator-sdk/reconcile-interval" in annotations.keys():
|
if "ansible.sdk.operatorframework.io/reconcile-interval" in annotations.keys():
|
||||||
# Calculates the iterations based on the reconcile-interval
|
# Calculates the iterations based on the reconcile-interval
|
||||||
# This executes for the very first iteration only
|
# This executes for the very first iteration only
|
||||||
if pre_iter is None:
|
if pre_iter is None:
|
||||||
interval = annotations["ansible.operator-sdk/reconcile-interval"]
|
interval = annotations["ansible.sdk.operatorframework.io/reconcile-interval"]
|
||||||
period = annotations["ansible.operator-sdk/reconcile-period"]
|
period = annotations["ansible.sdk.operatorframework.io/reconcile-period"]
|
||||||
iterations = self.get_iterations_from_interval(
|
iterations = self.get_iterations_from_interval(
|
||||||
interval, period)
|
interval, period)
|
||||||
reconcile_status['total_iterations'] = iterations
|
reconcile_status['total_iterations'] = iterations
|
||||||
|
@ -244,9 +244,9 @@ class CallbackModule(CallbackBase):
|
||||||
"format not specified" in iterations:
|
"format not specified" in iterations:
|
||||||
reconcile_status['msg'] = iterations
|
reconcile_status['msg'] = iterations
|
||||||
return reconcile_status
|
return reconcile_status
|
||||||
elif "ansible.operator-sdk/reconcile-iterations" \
|
elif "ansible.sdk.operatorframework.io/reconcile-iterations" \
|
||||||
in annotations.keys():
|
in annotations.keys():
|
||||||
iterations = annotations["ansible.operator-sdk/reconcile-iterations"]
|
iterations = annotations["ansible.sdk.operatorframework.io/reconcile-iterations"]
|
||||||
else:
|
else:
|
||||||
reconcile_status['msg'] = "Reconcile iterations or interval "+\
|
reconcile_status['msg'] = "Reconcile iterations or interval "+\
|
||||||
"not specified. Running simple reconcile."
|
"not specified. Running simple reconcile."
|
||||||
|
@ -271,7 +271,7 @@ class CallbackModule(CallbackBase):
|
||||||
reconcile_status['completed_iterations'] = current_iter
|
reconcile_status['completed_iterations'] = current_iter
|
||||||
if int(current_iter) == int(iterations)-1:
|
if int(current_iter) == int(iterations)-1:
|
||||||
cr_obj["metadata"]["annotations"]\
|
cr_obj["metadata"]["annotations"]\
|
||||||
["ansible.operator-sdk/reconcile-period"] = "0"
|
["ansible.sdk.operatorframework.io/reconcile-period"] = "0"
|
||||||
self.custom_api_instance.patch_namespaced_custom_object(
|
self.custom_api_instance.patch_namespaced_custom_object(
|
||||||
group="hostconfig.airshipit.org",
|
group="hostconfig.airshipit.org",
|
||||||
version="v1alpha1",
|
version="v1alpha1",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3.8
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3.8
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3.8
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3.8
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
|
@ -6,7 +6,7 @@ apiVersion: hostconfig.airshipit.org/v1alpha1
|
||||||
kind: HostConfig
|
kind: HostConfig
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
ansible.operator-sdk/reconcile-period: "30s"
|
ansible.sdk.operatorframework.io/reconcile-period: "30s"
|
||||||
name: example9
|
name: example9
|
||||||
spec:
|
spec:
|
||||||
host_groups:
|
host_groups:
|
||||||
|
|
|
@ -6,8 +6,8 @@ apiVersion: hostconfig.airshipit.org/v1alpha1
|
||||||
kind: HostConfig
|
kind: HostConfig
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
ansible.operator-sdk/reconcile-period: "30s"
|
ansible.sdk.operatorframework.io/reconcile-period: "30s"
|
||||||
ansible.operator-sdk/reconcile-interval: "2m40s"
|
ansible.sdk.operatorframework.io/reconcile-interval: "2m40s"
|
||||||
name: example11
|
name: example11
|
||||||
spec:
|
spec:
|
||||||
host_groups:
|
host_groups:
|
||||||
|
|
|
@ -6,8 +6,8 @@ apiVersion: hostconfig.airshipit.org/v1alpha1
|
||||||
kind: HostConfig
|
kind: HostConfig
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
ansible.operator-sdk/reconcile-period: "30s"
|
ansible.sdk.operatorframework.io/reconcile-period: "30s"
|
||||||
ansible.operator-sdk/reconcile-iterations: "3"
|
ansible.sdk.operatorframework.io/reconcile-iterations: "3"
|
||||||
name: example10
|
name: example10
|
||||||
spec:
|
spec:
|
||||||
host_groups:
|
host_groups:
|
||||||
|
|
Loading…
Reference in New Issue