Skip to content

Commit

Permalink
Upgrade Ansible Images (operator-framework#1947)
Browse files Browse the repository at this point in the history
Upgrade Ansible based images (python and its lib as ansible and molecule)

* Download and install the inotify-tools which is no longer available in the ubi8//epel-release-latest-8
* use pip3 in all places
* changes in the ci/trevis in order to work with python3
* ajust pip and python to work in ubi7
* increase the timeout to check the reconcile ( 2m for reconciliation to run )
* upgrade ansible and its deps versions
* upgrade to use molecule 2.22
* apply to make generated inventory define implicit localhost operator-framework#1828
* add ansible_python_interpreter=/usr/bin/python3 in host inventory
* solve ansible [WARNING]: The value 8443 (type int)
* improve test names in order to be able to identify them
* add interpreter in the py file (plugin filter)
* add host var for all hosts in the molecule inventory
* add yum update to address request made in the pr operator-framework#1979
* using ansible as ~=2.8
  • Loading branch information
camilamacedo86 authored Sep 27, 2019
1 parent 996f14a commit ebac354
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 46 deletions.
19 changes: 18 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ sudo: required
# go modules require xenial for mercurial TLS 1.2 support
dist: xenial

# Python 3.6 is the default Python when language: python.
# But when not language: python, Python 3 can not be used by default.
# There is pip (/usr/bin/pip), but not pip3.
# Because of it the global env is required.
env:
global:
- PATH=/opt/python/3.6.7/bin:$PATH

# Install python3 and utilities dependencies
addons:
apt:
packages:
- "python3"
- "python3-pip"

cache:
directories:
- $HOME/.cache/go-build
Expand Down Expand Up @@ -97,7 +112,9 @@ jobs:
# Build and test ansible
- <<: *test
name: Ansible on OpenShift
before_script: sudo pip install ansible
before_script:
- pip3 install --upgrade setuptools pip
- pip install --user ansible
script: make test/ci-ansible

# Build and test helm
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
```
- [`pkg/test.FrameworkClient`](https://github.com/operator-framework/operator-sdk/blob/master/pkg/test/client.go#L33) methods `List()` and `Delete()` have new signatures corresponding to the homonymous methods of `sigs.k8s.io/controller-runtime/pkg/client.Client`. ([#1876](https://github.com/operator-framework/operator-sdk/pull/1876))
- CRD file names were previously of the form `<group>_<version>_<kind>_crd.yaml`. Now that CRD manifest `spec.version` is deprecated in favor of `spec.versions`, i.e. multiple versions can be specified in one CRD, CRD file names have the form `<full group>_<resource>_crd.yaml`. `<full group>` is the full group name of your CRD while `<group>` is the last subdomain of `<full group>`, ex. `foo.bar.com` vs `foo`. `<resource>` is the plural lower-case CRD Kind found at `spec.names.plural`. ([#1876](https://github.com/operator-framework/operator-sdk/pull/1876))
- Upgrade Python version from `2.7` to `3.6`, Ansible version from `2.8.0` to `~=2.8` and ansible-runner from `1.2` to `1.3.4` in the Ansible based images. ([#1947](https://github.com/operator-framework/operator-sdk/pull/1947))

### Deprecated

Expand Down
16 changes: 10 additions & 6 deletions ci/dockerfiles/ansible-e2e-hybrid.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ ENV OPERATOR=/usr/local/bin/ansible-operator \
# yum clean all && rm -rf /var/yum/cache/* first
RUN yum clean all && rm -rf /var/cache/yum/* \
&& (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
&& yum install -y python-devel gcc inotify-tools \
&& easy_install pip \
&& pip install -U --no-cache-dir setuptools pip \
&& yum -y update \
&& yum install -y python36-devel python36-pip gcc \
# Install inotify-tools. Note: rpm -i will install the rpm in the registry for allow yum install it.
&& curl -O https://rpmfind.net/linux/fedora/linux/releases/30/Everything/x86_64/os/Packages/i/inotify-tools-3.14-16.fc30.x86_64.rpm \
&& rpm -i inotify-tools-3.14-16.fc30.x86_64.rpm \
&& yum install inotify-tools \
&& pip3 install --upgrade setuptools pip \
&& pip install --no-cache-dir --ignore-installed ipaddress \
ansible-runner==1.2 \
ansible-runner==1.3.4 \
ansible-runner-http==1.0.0 \
openshift==0.8.9 \
ansible==2.8 \
&& yum remove -y gcc python-devel \
ansible~=2.8 \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum

Expand Down
17 changes: 11 additions & 6 deletions ci/dockerfiles/ansible.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ ENV OPERATOR=/usr/local/bin/ansible-operator \
USER_NAME=ansible-operator\
HOME=/opt/ansible

# Install python dependencies
# Ensure fresh metadata rather than cached metadata in the base by running
# yum clean all && rm -rf /var/yum/cache/* first
RUN yum clean all && rm -rf /var/cache/yum/* \
&& (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
&& yum install -y python-devel gcc inotify-tools \
&& easy_install pip \
&& pip install -U --no-cache-dir setuptools pip \
&& yum -y update \
&& yum install -y python36-devel python36-pip gcc \
# Install inotify-tools. Note: rpm -i will install the rpm in the registry for allow yum install it.
&& curl -O https://rpmfind.net/linux/fedora/linux/releases/30/Everything/x86_64/os/Packages/i/inotify-tools-3.14-16.fc30.x86_64.rpm \
&& rpm -i inotify-tools-3.14-16.fc30.x86_64.rpm \
&& yum install inotify-tools \
&& pip3 install --upgrade setuptools pip \
&& pip install --no-cache-dir --ignore-installed ipaddress \
ansible-runner==1.2 \
ansible-runner==1.3.4 \
ansible-runner-http==1.0.0 \
openshift==0.8.9 \
ansible==2.8 \
&& yum remove -y gcc python-devel \
ansible~=2.8 \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum

Expand Down
2 changes: 1 addition & 1 deletion doc/ansible/dev/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $ sudo dnf install ansible
In addition to Ansible, a user must install the [OpenShift Restclient
Python][openshift_restclient_python] package. This can be installed from pip:
```bash
$ pip install openshift
$ pip3 install openshift
```

### Testing the k8s Ansible modules locally
Expand Down
6 changes: 3 additions & 3 deletions hack/tests/e2e-ansible-molecule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ set -eux
ROOTDIR="$(pwd)"
GOTMP="$(mktemp -d)"
trap_add 'rm -rf $GOTMP' EXIT
pip install --user pyasn1==0.4.5 pyasn1-modules==0.2.5 idna==2.7 ipaddress==1.0.22
pip install --user molecule==2.20.2
pip install --user docker openshift jmespath
pip3 install --user pyasn1==0.4.7 pyasn1-modules==0.2.6 idna==2.8 ipaddress==1.0.22
pip3 install --user molecule==2.22
pip3 install --user docker openshift jmespath

deploy_prereqs() {
kubectl create -f "$OPERATORDIR/deploy/service_account.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ USER 0
# Ensure fresh metadata rather than cached metadata in the base by running
# yum clean all && rm -rf /var/yum/cache/* first
RUN yum clean all && rm -rf /var/cache/yum/* \
&& yum install -y python-devel gcc libffi-devel
RUN pip install molecule==2.20.1
&& yum -y update \
&& yum install -y python36-devel python36-pip gcc libffi-devel
RUN pip3 install --user molecule==2.22
ARG NAMESPACEDMAN
ADD $NAMESPACEDMAN /namespaced.yaml
Expand Down
18 changes: 11 additions & 7 deletions internal/pkg/scaffold/ansible/dockerfilehybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ ENV OPERATOR=/usr/local/bin/ansible-operator \
# Ensure fresh metadata rather than cached metadata in the base by running
# yum clean all && rm -rf /var/yum/cache/* first
RUN yum clean all && rm -rf /var/cache/yum/* \
&& yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& yum install -y python-devel gcc inotify-tools \
&& easy_install pip \
&& pip install -U --no-cache-dir setuptools pip \
&& (yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true) \
&& yum -y update \
&& yum install -y python36-devel python36-pip gcc \
# Install inotify-tools. Note: rpm -i will install the rpm in the registry for allow yum install it.
&& curl -O https://rpmfind.net/linux/fedora/linux/releases/30/Everything/x86_64/os/Packages/i/inotify-tools-3.14-16.fc30.x86_64.rpm \
&& rpm -i inotify-tools-3.14-16.fc30.x86_64.rpm \
&& yum install inotify-tools \
&& pip3 install --upgrade setuptools pip \
&& pip install --no-cache-dir --ignore-installed ipaddress \
ansible-runner==1.2 \
ansible-runner==1.3.4 \
ansible-runner-http==1.0.0 \
openshift==0.8.9 \
ansible==2.8 \
&& yum remove -y gcc python-devel \
ansible~=2.8 \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/scaffold/ansible/k8s_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k *K8sStatus) GetInput() (input.Input, error) {
return k.Input, nil
}

const k8sStatusTmpl = `#!/usr/bin/python
const k8sStatusTmpl = `#!/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
Expand Down Expand Up @@ -163,7 +163,7 @@ options:
type: bool
requirements:
- "python >= 2.7"
- "python >= 3.7"
- "openshift >= 0.8.1"
- "PyYAML >= 3.11"
'''
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/scaffold/ansible/molecule_default_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const moleculeDefaultPrepareAnsibleTmpl = `---
- name: Change the kubeconfig port to the proper value
replace:
regexp: 8443
regexp: '8443'
replace: "{{ lookup('env', 'KIND_PORT') }}"
path: '{{ kubeconfig }}'
delegate_to: localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const moleculeTestClusterPlaybookAnsibleTmpl = `---
debug:
msg: "{{ lookup('k8s', group='[[.Resource.FullGroup]]', api_version='[[.Resource.Version]]', kind='[[.Resource.Kind]]', namespace=namespace, resource_name=custom_resource.metadata.name) }}"
- name: Wait 60s for reconciliation to run
- name: Wait 2m for reconciliation to run
k8s_facts:
api_version: '[[.Resource.Version]]'
kind: '[[.Resource.Kind]]'
Expand All @@ -68,7 +68,7 @@ const moleculeTestClusterPlaybookAnsibleTmpl = `---
register: reconcile_cr
until:
- "'Successful' in (reconcile_cr | json_query('resources[].status.conditions[].reason'))"
delay: 6
delay: 12
retries: 10
- import_playbook: '{{ playbook_dir }}/../default/asserts.yml'
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/scaffold/ansible/molecule_test_local_playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const moleculeTestLocalPlaybookAnsibleTmpl = `---
namespace: '{{ namespace }}'
definition: '{{ custom_resource }}'
- name: Wait 60s for reconciliation to run
- name: Wait 2m for reconciliation to run
k8s_facts:
api_version: '{{ custom_resource.apiVersion }}'
kind: '{{ custom_resource.kind }}'
Expand All @@ -110,7 +110,7 @@ const moleculeTestLocalPlaybookAnsibleTmpl = `---
register: cr
until:
- "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))"
delay: 6
delay: 12
retries: 10
rescue:
- name: debug cr
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/scaffold/ansible/travis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const travisAnsibleTmpl = `sudo: required
services: docker
language: python
install:
- pip install docker molecule openshift
- pip3 install docker molecule openshift
script:
- molecule test -s test-local
`
4 changes: 3 additions & 1 deletion pkg/ansible/runner/internal/inputdir/inputdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func (i *InputDir) Write() error {
venv := os.Getenv("VIRTUAL_ENV")
hosts := "localhost ansible_connection=local"
if venv != "" {
hosts = fmt.Sprintf("%s ansible_python_interpreter=%s", hosts, filepath.Join(venv, "bin/python"))
hosts = fmt.Sprintf("%s ansible_python_interpreter=%s", hosts, filepath.Join(venv, "bin", "python3"))
} else {
hosts = fmt.Sprintf("%s ansible_python_interpreter=%s", hosts, "{{ansible_playbook_python}}")
}
err = i.addFile("inventory/hosts", []byte(hosts))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions test/ansible-inventory/inventory/hosts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[test]
127.0.0.1 ansible_connection=local

[all:vars]
ansible_python_interpreter=/usr/bin/python3
2 changes: 1 addition & 1 deletion test/ansible-inventory/molecule/test-local/asserts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ansible_python_interpreter: '{{ ansible_playbook_python }}'
cm: '{{ lookup("k8s", api_version="v1", kind="ConfigMap", namespace=namespace, resource_name="inventory-cm") }}'
tasks:
- name: Assert sentinel ConfigMap has been created
- name: Assert sentinel ConfigMap has been created for Molecule Test
assert:
that: cm.data.sentinel == 'test'
- name: output cm
Expand Down
8 changes: 4 additions & 4 deletions test/ansible-inventory/molecule/test-local/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Build Operator in Kubernetes docker container
- name: Build Operator in Kubernetes docker container for Molecule Test
hosts: k8s
vars:
image_name: inventory.apps.fabianism.us/inventory:testing
Expand All @@ -16,7 +16,7 @@
register: build_cmd
changed_when: not prev_hash.stdout or (prev_hash.stdout and prev_hash.stdout not in ''.join(build_cmd.stdout_lines[-2:]))

- name: Converge
- name: Converge for Molecule Test
hosts: localhost
connection: local
vars:
Expand Down Expand Up @@ -59,7 +59,7 @@
namespace: '{{ namespace }}'
definition: "{{ custom_resource }}"

- name: Wait 30s for reconciliation to run
- name: Wait 2m for reconciliation to run
k8s_facts:
api_version: '{{ custom_resource.apiVersion }}'
kind: '{{ custom_resource.kind }}'
Expand All @@ -68,7 +68,7 @@
register: cr
until:
- "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))"
delay: 3
delay: 12
retries: 10

- import_playbook: asserts.yml
10 changes: 5 additions & 5 deletions test/ansible-inventory/molecule/test-local/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Prepare
- name: Prepare for Molecule Test
hosts: k8s
gather_facts: no
vars:
Expand All @@ -19,7 +19,7 @@

- name: Change the kubeconfig port to the proper value
replace:
regexp: 8443
regexp: '8443'
replace: "{{ lookup('env', 'KIND_PORT') }}"
path: '{{ kubeconfig }}'
delegate_to: localhost
Expand All @@ -34,7 +34,7 @@
retries: 60
delay: 5

- name: Prepare operator resources
- name: Prepare operator resources for Molecule Test
hosts: localhost
connection: local
vars:
Expand Down Expand Up @@ -66,14 +66,14 @@
- name: Copy the image to the kind container
command: docker cp /tmp/dev-operator.tar kind-test-local:/dev-operator.tar

- name: Make dev operator image available
- name: Make dev operator image available for Molecule Test
hosts: k8s
gather_facts: no
tasks:
- name: Make dev operator available
command: docker load -i /dev-operator.tar

- name: Clean up
- name: Clean up for Molecule Test
hosts: localhost
connection: local
gather_facts: no
Expand Down
2 changes: 2 additions & 0 deletions test/ansible-inventory/plugins/filter/test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python3

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

Expand Down
2 changes: 1 addition & 1 deletion test/ansible-inventory/roles/inventory/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
namespace: '{{ meta.namespace }}'
data:
sentinel: '{{ sentinel }}'
groups: '{{ groups | to_nice_yaml }}'
groups: '{{ groups | to_nice_yaml }}'

0 comments on commit ebac354

Please sign in to comment.