Skip to content

Commit 06d2629

Browse files
etsaueroybed
authored andcommitted
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
1 parent 74eee91 commit 06d2629

File tree

6 files changed

+165
-3
lines changed

6 files changed

+165
-3
lines changed

roles/openshift-applier/tasks/process-file.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
patch_path: "{{ params | check_file_location }}"
2121
- name: Pull data from file
2222
set_fact:
23-
patch_content: "{{ lookup('file', params) }}"
23+
patch_content: "{{ lookup('file', params) | from_yaml }}"
2424
when: patch_path.local_path
2525
- name: Pull data from url
2626
set_fact:
27-
patch_content: "{{ lookup('url', params, split_lines=False) }}"
27+
patch_content: "{{ lookup('url', params, split_lines=False) | from_yaml }}"
2828
when: not patch_path.local_path
2929
when: oc_action == 'patch'
3030

@@ -35,7 +35,7 @@
3535
-f {{ file_facts.oc_path }} \
3636
{{ (oc_action == 'delete') | ternary(' --ignore-not-found', '') }} \
3737
{% if oc_action == 'patch' %}
38-
-p "{{patch_content}}"
38+
-p '{{ patch_content | to_json }}'
3939
{% endif %}
4040
no_log: "{{ no_log }}"
4141
register: command_result

tests/files/imagestreams/python.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
apiVersion: image.openshift.io/v1
2+
kind: ImageStream
3+
metadata:
4+
annotations:
5+
openshift.io/display-name: Python
6+
openshift.io/image.dockerRepositoryCheck: 2019-02-14T06:49:49Z
7+
creationTimestamp: null
8+
generation: 2
9+
name: python
10+
spec:
11+
lookupPolicy:
12+
local: false
13+
tags:
14+
- annotations:
15+
description: Build and run Python 2.7 applications on RHEL 7. For more information
16+
about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/2.7/README.md.
17+
iconClass: icon-python
18+
openshift.io/display-name: Python 2.7
19+
openshift.io/provider-display-name: Red Hat, Inc.
20+
sampleRepo: https://github.com/openshift/django-ex.git
21+
supports: python:2.7,python
22+
tags: builder,python
23+
version: "2.7"
24+
from:
25+
kind: DockerImage
26+
name: docker-registry.default.svc:5000/openshift/python:2.7
27+
generation: 2
28+
importPolicy: {}
29+
name: "2.7"
30+
referencePolicy:
31+
type: Local
32+
- annotations:
33+
description: Build and run Python 3.3 applications on RHEL 7. For more information
34+
about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.3/README.md.
35+
iconClass: icon-python
36+
openshift.io/display-name: Python 3.3
37+
openshift.io/provider-display-name: Red Hat, Inc.
38+
sampleRepo: https://github.com/openshift/django-ex.git
39+
supports: python:3.3,python
40+
tags: hidden,builder,python
41+
version: "3.3"
42+
from:
43+
kind: DockerImage
44+
name: docker-registry.default.svc:5000/openshift/python:3.3
45+
generation: 2
46+
importPolicy: {}
47+
name: "3.3"
48+
referencePolicy:
49+
type: Local
50+
- annotations:
51+
description: Build and run Python 3.4 applications on RHEL 7. For more information
52+
about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.4/README.md.
53+
iconClass: icon-python
54+
openshift.io/display-name: Python 3.4
55+
openshift.io/provider-display-name: Red Hat, Inc.
56+
sampleRepo: https://github.com/openshift/django-ex.git
57+
supports: python:3.4,python
58+
tags: hidden,builder,python
59+
version: "3.4"
60+
from:
61+
kind: DockerImage
62+
name: docker-registry.default.svc:5000/openshift/python:3.4
63+
generation: 2
64+
importPolicy: {}
65+
name: "3.4"
66+
referencePolicy:
67+
type: Local
68+
- annotations:
69+
description: Build and run Python 3.5 applications on RHEL 7. For more information
70+
about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.5/README.md.
71+
iconClass: icon-python
72+
openshift.io/display-name: Python 3.5
73+
openshift.io/provider-display-name: Red Hat, Inc.
74+
sampleRepo: https://github.com/openshift/django-ex.git
75+
supports: python:3.5,python
76+
tags: builder,python
77+
version: "3.5"
78+
from:
79+
kind: DockerImage
80+
name: docker-registry.default.svc:5000/openshift/python:3.5
81+
generation: 2
82+
importPolicy: {}
83+
name: "3.5"
84+
referencePolicy:
85+
type: Local
86+
- annotations:
87+
description: Build and run Python 3.6 applications on RHEL 7. For more information
88+
about using this builder image, including OpenShift considerations, see https://github.com/sclorg/s2i-python-container/blob/master/3.6/README.md.
89+
iconClass: icon-python
90+
openshift.io/display-name: Python 3.6
91+
openshift.io/provider-display-name: Red Hat, Inc.
92+
sampleRepo: https://github.com/openshift/django-ex.git
93+
supports: python:3.6,python
94+
tags: builder,python
95+
version: "3.6"
96+
from:
97+
kind: DockerImage
98+
name: docker-registry.default.svc:5000/openshift/python:3.6
99+
generation: 2
100+
importPolicy: {}
101+
name: "3.6"
102+
referencePolicy:
103+
type: Local
104+
- annotations:
105+
description: |-
106+
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.
107+
108+
WARNING: By selecting this tag, your application will automatically update to use the latest version of Python available on OpenShift, including major versions updates.
109+
iconClass: icon-python
110+
openshift.io/display-name: Python (Latest)
111+
openshift.io/provider-display-name: Red Hat, Inc.
112+
sampleRepo: https://github.com/openshift/django-ex.git
113+
supports: python
114+
tags: builder,python
115+
from:
116+
kind: DockerImage
117+
name: docker-registry.default.svc:5000/openshift/python:latest
118+
generation: 1
119+
importPolicy: {}
120+
name: latest
121+
referencePolicy:
122+
type: Local

tests/files/patches/patch1.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"metadata": {
3+
"labels": {
4+
"test": "label"
5+
}
6+
}
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"spec": {
3+
"tags": [
4+
{
5+
"name": "2.7",
6+
"importPolicy": {
7+
"scheduled": true
8+
}
9+
}
10+
]
11+
}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spec:
2+
tags:
3+
- name: "2.7"
4+
importPolicy:
5+
scheduled: true

tests/inventories/patch/group_vars/seed-hosts.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ openshift_cluster_content:
1212
- name: patch resource from url
1313
file: "{{ inventory_dir }}/../../files/multi-files-dir/files/route1.yml"
1414
params: "https://raw.githubusercontent.com/redhat-cop/openshift-applier/master/tests/files/patches/patch1.yml"
15+
- name: patch resource from json
16+
file: "{{ inventory_dir }}/../../files/multi-files-dir/files/route1.yml"
17+
params: "{{ inventory_dir }}/../../files/patches/patch1.json"
18+
action: patch
1519
- object: multi patch test
1620
content:
1721
- name: initialize resource
@@ -20,3 +24,15 @@ openshift_cluster_content:
2024
file: "{{ inventory_dir }}/../../files/multi-files-dir/files/"
2125
params: "{{ inventory_dir }}/../../files/patches/patch1.yml"
2226
action: patch
27+
- object: patch containing strings
28+
content:
29+
- name: initialize resource
30+
file: "{{ inventory_dir }}/../../files/imagestreams/python.yml"
31+
- name: patch resource
32+
file: "{{ inventory_dir }}/../../files/imagestreams/python.yml"
33+
params: "{{ inventory_dir }}/../../files/patches/python-is-patch.yml"
34+
action: patch
35+
- name: patch resource from json
36+
file: "{{ inventory_dir }}/../../files/imagestreams/python.yml"
37+
params: "{{ inventory_dir }}/../../files/patches/python-is-patch.json"
38+
action: patch

0 commit comments

Comments
 (0)