From 06d2629cb1b5a4ffddcdc6efe27255117084cc08 Mon Sep 17 00:00:00 2001 From: Eric Sauer Date: Thu, 7 Mar 2019 16:47:15 -0500 Subject: [PATCH] Action: Patch needs to support yaml containing string values. (#111) * Adding a test showing a patch thats failing, so we can fix it * Fixing role to handle test scenario * Adding a json patch file to show that patches can be either yaml or json * Adding single file simple patch in json format --- .../openshift-applier/tasks/process-file.yml | 6 +- tests/files/imagestreams/python.yml | 122 ++++++++++++++++++ tests/files/patches/patch1.json | 7 + tests/files/patches/python-is-patch.json | 12 ++ tests/files/patches/python-is-patch.yml | 5 + .../patch/group_vars/seed-hosts.yml | 16 +++ 6 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 tests/files/imagestreams/python.yml create mode 100644 tests/files/patches/patch1.json create mode 100644 tests/files/patches/python-is-patch.json create mode 100644 tests/files/patches/python-is-patch.yml diff --git a/roles/openshift-applier/tasks/process-file.yml b/roles/openshift-applier/tasks/process-file.yml index 9d9c753..c1af341 100644 --- a/roles/openshift-applier/tasks/process-file.yml +++ b/roles/openshift-applier/tasks/process-file.yml @@ -20,11 +20,11 @@ patch_path: "{{ params | check_file_location }}" - name: Pull data from file set_fact: - patch_content: "{{ lookup('file', params) }}" + patch_content: "{{ lookup('file', params) | from_yaml }}" when: patch_path.local_path - name: Pull data from url set_fact: - patch_content: "{{ lookup('url', params, split_lines=False) }}" + patch_content: "{{ lookup('url', params, split_lines=False) | from_yaml }}" when: not patch_path.local_path when: oc_action == 'patch' @@ -35,7 +35,7 @@ -f {{ file_facts.oc_path }} \ {{ (oc_action == 'delete') | ternary(' --ignore-not-found', '') }} \ {% if oc_action == 'patch' %} - -p "{{patch_content}}" + -p '{{ patch_content | to_json }}' {% endif %} no_log: "{{ no_log }}" register: command_result diff --git a/tests/files/imagestreams/python.yml b/tests/files/imagestreams/python.yml new file mode 100644 index 0000000..602999a --- /dev/null +++ b/tests/files/imagestreams/python.yml @@ -0,0 +1,122 @@ +apiVersion: image.openshift.io/v1 +kind: ImageStream +metadata: + annotations: + openshift.io/display-name: Python + openshift.io/image.dockerRepositoryCheck: 2019-02-14T06:49:49Z + creationTimestamp: null + generation: 2 + name: python +spec: + lookupPolicy: + local: false + tags: + - annotations: + description: Build and run Python 2.7 applications on RHEL 7. For more information + about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/2.7/README.md. + iconClass: icon-python + openshift.io/display-name: Python 2.7 + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python:2.7,python + tags: builder,python + version: "2.7" + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:2.7 + generation: 2 + importPolicy: {} + name: "2.7" + referencePolicy: + type: Local + - annotations: + description: Build and run Python 3.3 applications on RHEL 7. For more information + about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.3/README.md. + iconClass: icon-python + openshift.io/display-name: Python 3.3 + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python:3.3,python + tags: hidden,builder,python + version: "3.3" + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:3.3 + generation: 2 + importPolicy: {} + name: "3.3" + referencePolicy: + type: Local + - annotations: + description: Build and run Python 3.4 applications on RHEL 7. For more information + about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.4/README.md. + iconClass: icon-python + openshift.io/display-name: Python 3.4 + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python:3.4,python + tags: hidden,builder,python + version: "3.4" + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:3.4 + generation: 2 + importPolicy: {} + name: "3.4" + referencePolicy: + type: Local + - annotations: + description: Build and run Python 3.5 applications on RHEL 7. For more information + about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.5/README.md. + iconClass: icon-python + openshift.io/display-name: Python 3.5 + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python:3.5,python + tags: builder,python + version: "3.5" + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:3.5 + generation: 2 + importPolicy: {} + name: "3.5" + referencePolicy: + type: Local + - annotations: + description: Build and run Python 3.6 applications on RHEL 7. For more information + about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.6/README.md. + iconClass: icon-python + openshift.io/display-name: Python 3.6 + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python:3.6,python + tags: builder,python + version: "3.6" + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:3.6 + generation: 2 + importPolicy: {} + name: "3.6" + referencePolicy: + type: Local + - annotations: + description: |- + Build and run Python applications on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.6/README.md. + + WARNING: By selecting this tag, your application will automatically update to use the latest version of Python available on OpenShift, including major versions updates. + iconClass: icon-python + openshift.io/display-name: Python (Latest) + openshift.io/provider-display-name: Red Hat, Inc. + sampleRepo: https://github.com/openshift/django-ex.git + supports: python + tags: builder,python + from: + kind: DockerImage + name: docker-registry.default.svc:5000/openshift/python:latest + generation: 1 + importPolicy: {} + name: latest + referencePolicy: + type: Local diff --git a/tests/files/patches/patch1.json b/tests/files/patches/patch1.json new file mode 100644 index 0000000..5dfa485 --- /dev/null +++ b/tests/files/patches/patch1.json @@ -0,0 +1,7 @@ +{ + "metadata": { + "labels": { + "test": "label" + } + } +} diff --git a/tests/files/patches/python-is-patch.json b/tests/files/patches/python-is-patch.json new file mode 100644 index 0000000..f13eeea --- /dev/null +++ b/tests/files/patches/python-is-patch.json @@ -0,0 +1,12 @@ +{ + "spec": { + "tags": [ + { + "name": "2.7", + "importPolicy": { + "scheduled": true + } + } + ] + } +} diff --git a/tests/files/patches/python-is-patch.yml b/tests/files/patches/python-is-patch.yml new file mode 100644 index 0000000..09d4925 --- /dev/null +++ b/tests/files/patches/python-is-patch.yml @@ -0,0 +1,5 @@ +spec: + tags: + - name: "2.7" + importPolicy: + scheduled: true diff --git a/tests/inventories/patch/group_vars/seed-hosts.yml b/tests/inventories/patch/group_vars/seed-hosts.yml index 5f43f89..564d6b2 100644 --- a/tests/inventories/patch/group_vars/seed-hosts.yml +++ b/tests/inventories/patch/group_vars/seed-hosts.yml @@ -12,6 +12,10 @@ openshift_cluster_content: - name: patch resource from url file: "{{ inventory_dir }}/../../files/multi-files-dir/files/route1.yml" params: "https://raw.githubusercontent.com/redhat-cop/openshift-applier/master/tests/files/patches/patch1.yml" + - name: patch resource from json + file: "{{ inventory_dir }}/../../files/multi-files-dir/files/route1.yml" + params: "{{ inventory_dir }}/../../files/patches/patch1.json" + action: patch - object: multi patch test content: - name: initialize resource @@ -20,3 +24,15 @@ openshift_cluster_content: file: "{{ inventory_dir }}/../../files/multi-files-dir/files/" params: "{{ inventory_dir }}/../../files/patches/patch1.yml" action: patch +- object: patch containing strings + content: + - name: initialize resource + file: "{{ inventory_dir }}/../../files/imagestreams/python.yml" + - name: patch resource + file: "{{ inventory_dir }}/../../files/imagestreams/python.yml" + params: "{{ inventory_dir }}/../../files/patches/python-is-patch.yml" + action: patch + - name: patch resource from json + file: "{{ inventory_dir }}/../../files/imagestreams/python.yml" + params: "{{ inventory_dir }}/../../files/patches/python-is-patch.json" + action: patch