diff --git a/Dockerfile b/Dockerfile index dafc76a..c67c6a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ # 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 COPY airship-host-config/requirements.yml ${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 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++ \ python3-libs systemd-libs libssh-config glib2 python3-pip-wheel libsolv \ gdb-gdbserver sqlite-libs libgcrypt libgcc pcre2 glibc-common expat libxml2 \ - libcurl glibc-minimal-langpack libpcap openssh-clients sshpass -y -USER ansible-operator + libcurl glibc-minimal-langpack libpcap openssh-clients sshpass -y \ + && dnf clean all && rm -rf /var/cache/yum +USER ansible # Configuration for ansible 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 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 -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 COPY airship-host-config/scripts/ ${HOME}/scripts/ diff --git a/airship-host-config/deploy/operator.yaml b/airship-host-config/deploy/operator.yaml index 7826464..009af12 100644 --- a/airship-host-config/deploy/operator.yaml +++ b/airship-host-config/deploy/operator.yaml @@ -33,6 +33,9 @@ spec: - name: airship-host-config image: "AIRSHIP_HOSTCONFIG_IMAGE" imagePullPolicy: "PULL_POLICY" + args: + - --leader-elect + - --leader-election-id=airship-host-config volumeMounts: - mountPath: /tmp/ansible-operator/runner name: runner @@ -45,8 +48,6 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name - - name: OPERATOR_NAME - value: "airship-host-config" - name: ANSIBLE_FILTER_PLUGINS value: /opt/ansible/plugins/filter - name: ANSIBLE_FORKS diff --git a/airship-host-config/inventory/dynamic_inventory.py b/airship-host-config/inventory/dynamic_inventory.py index aafb859..e36ad7f 100755 --- a/airship-host-config/inventory/dynamic_inventory.py +++ b/airship-host-config/inventory/dynamic_inventory.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python3.8 # Python code to build Inventory dynamically based on the kubernetes nodes # present in the cluster and labels and annotations associated diff --git a/airship-host-config/plugins/callback/hostconfig_k8_cr_status.py b/airship-host-config/plugins/callback/hostconfig_k8_cr_status.py index f8075d0..568328a 100644 --- a/airship-host-config/plugins/callback/hostconfig_k8_cr_status.py +++ b/airship-host-config/plugins/callback/hostconfig_k8_cr_status.py @@ -55,8 +55,8 @@ class CallbackModule(CallbackBase): def v2_playbook_on_play_start(self, play): self.vm = play.get_variable_manager() self.host_vars = self.vm.get_vars()['hostvars'] - self.hostConfigName = self.host_vars['localhost']['meta']['name'] - self.namespace = self.host_vars['localhost']['meta']['namespace'] + self.hostConfigName = self.host_vars['localhost']['ansible_operator_meta']['name'] + self.namespace = self.host_vars['localhost']['ansible_operator_meta']['namespace'] # This function is triggered when a certain task fails with # unreachable state @@ -119,7 +119,7 @@ class CallbackModule(CallbackBase): if k8_hostname not in self.host_config_status.keys(): self.host_config_status[k8_hostname] = dict() 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() check_keys = ["stdout", "stderr", "msg"] for key in check_keys: @@ -210,7 +210,7 @@ class CallbackModule(CallbackBase): ['_hostconfig_airshipit_org_hostconfig']\ ['metadata']['annotations'] reconcile_status = dict() - if "ansible.operator-sdk/reconcile-period" in annotations.keys(): + if "ansible.sdk.operatorframework.io/reconcile-period" in annotations.keys(): iterations = 0 pre_iter = None if 'reconcileStatus' in cr_obj['status'].keys() and \ @@ -219,12 +219,12 @@ class CallbackModule(CallbackBase): pre_iter = cr_obj['status']['reconcileStatus']\ ['completed_iterations'] # 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 # This executes for the very first iteration only if pre_iter is None: - interval = annotations["ansible.operator-sdk/reconcile-interval"] - period = annotations["ansible.operator-sdk/reconcile-period"] + interval = annotations["ansible.sdk.operatorframework.io/reconcile-interval"] + period = annotations["ansible.sdk.operatorframework.io/reconcile-period"] iterations = self.get_iterations_from_interval( interval, period) reconcile_status['total_iterations'] = iterations @@ -244,9 +244,9 @@ class CallbackModule(CallbackBase): "format not specified" in iterations: reconcile_status['msg'] = iterations return reconcile_status - elif "ansible.operator-sdk/reconcile-iterations" \ + elif "ansible.sdk.operatorframework.io/reconcile-iterations" \ in annotations.keys(): - iterations = annotations["ansible.operator-sdk/reconcile-iterations"] + iterations = annotations["ansible.sdk.operatorframework.io/reconcile-iterations"] else: reconcile_status['msg'] = "Reconcile iterations or interval "+\ "not specified. Running simple reconcile." @@ -271,7 +271,7 @@ class CallbackModule(CallbackBase): reconcile_status['completed_iterations'] = current_iter if int(current_iter) == int(iterations)-1: 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( group="hostconfig.airshipit.org", version="v1alpha1", diff --git a/airship-host-config/plugins/filter/hostconfig_host_groups.py b/airship-host-config/plugins/filter/hostconfig_host_groups.py index a69bc09..ab5e785 100644 --- a/airship-host-config/plugins/filter/hostconfig_host_groups.py +++ b/airship-host-config/plugins/filter/hostconfig_host_groups.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python3.8 from __future__ import (absolute_import, division, print_function) __metaclass__ = type diff --git a/airship-host-config/plugins/filter/hostconfig_host_groups_to_list.py b/airship-host-config/plugins/filter/hostconfig_host_groups_to_list.py index 8d7acea..0aac695 100644 --- a/airship-host-config/plugins/filter/hostconfig_host_groups_to_list.py +++ b/airship-host-config/plugins/filter/hostconfig_host_groups_to_list.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python3.8 from __future__ import (absolute_import, division, print_function) __metaclass__ = type diff --git a/airship-host-config/plugins/filter/hostconfig_hosts_parallel.py b/airship-host-config/plugins/filter/hostconfig_hosts_parallel.py index 7b3a9d3..c68e706 100644 --- a/airship-host-config/plugins/filter/hostconfig_hosts_parallel.py +++ b/airship-host-config/plugins/filter/hostconfig_hosts_parallel.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python3.8 from __future__ import (absolute_import, division, print_function) __metaclass__ = type diff --git a/airship-host-config/plugins/filter/hostconfig_sequential.py b/airship-host-config/plugins/filter/hostconfig_sequential.py index 2eac704..ae94d1f 100644 --- a/airship-host-config/plugins/filter/hostconfig_sequential.py +++ b/airship-host-config/plugins/filter/hostconfig_sequential.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python3.8 from __future__ import (absolute_import, division, print_function) __metaclass__ = type diff --git a/demo_examples/example_reconcile.yaml b/demo_examples/example_reconcile.yaml index 2862f46..5bebdcd 100644 --- a/demo_examples/example_reconcile.yaml +++ b/demo_examples/example_reconcile.yaml @@ -6,7 +6,7 @@ apiVersion: hostconfig.airshipit.org/v1alpha1 kind: HostConfig metadata: annotations: - ansible.operator-sdk/reconcile-period: "30s" + ansible.sdk.operatorframework.io/reconcile-period: "30s" name: example9 spec: host_groups: diff --git a/demo_examples/example_reconcile_interval.yaml b/demo_examples/example_reconcile_interval.yaml index ebc4d45..0e9668a 100644 --- a/demo_examples/example_reconcile_interval.yaml +++ b/demo_examples/example_reconcile_interval.yaml @@ -6,8 +6,8 @@ apiVersion: hostconfig.airshipit.org/v1alpha1 kind: HostConfig metadata: annotations: - ansible.operator-sdk/reconcile-period: "30s" - ansible.operator-sdk/reconcile-interval: "2m40s" + ansible.sdk.operatorframework.io/reconcile-period: "30s" + ansible.sdk.operatorframework.io/reconcile-interval: "2m40s" name: example11 spec: host_groups: diff --git a/demo_examples/example_reconcile_iterations.yaml b/demo_examples/example_reconcile_iterations.yaml index 74bf359..586950d 100644 --- a/demo_examples/example_reconcile_iterations.yaml +++ b/demo_examples/example_reconcile_iterations.yaml @@ -6,8 +6,8 @@ apiVersion: hostconfig.airshipit.org/v1alpha1 kind: HostConfig metadata: annotations: - ansible.operator-sdk/reconcile-period: "30s" - ansible.operator-sdk/reconcile-iterations: "3" + ansible.sdk.operatorframework.io/reconcile-period: "30s" + ansible.sdk.operatorframework.io/reconcile-iterations: "3" name: example10 spec: host_groups: