This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
ROLE: openshift-patch-resource - patch a k8s/openshift resource #386
Merged
oybed
merged 3 commits into
redhat-cop:master
from
pabrahamsson:openshift_patch_resource
Dec 2, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
openshift-patch-resource | ||
======================== | ||
|
||
Patch a Kubernetes/Openshift resource | ||
|
||
Requirements | ||
------------ | ||
|
||
This role requires the `kubernetes` python module and an active session to your Kubernetes/Openshift cluster. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
| Variable | Description | Required | Defaults | | ||
| :------- | :---------- | :------- | :------- | | ||
| api_version | The api_version of the resource | yes || | ||
| definition | The patch definition | yes || | ||
| kind | The kind of the resource | yes || | ||
| merge_type | A list of merge types ("strategic-merge, merge") | no | [strategic-merge](https://docs.ansible.com/ansible/latest/modules/k8s_module.html) | | ||
| name | The name of the resource | yes || | ||
| namespace | The namespace of the resource | no || | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
```yaml | ||
--- | ||
- hosts: localhost | ||
tasks: | ||
- name: Patch annotations on default project (strategic-merge strategy) | ||
include_role: | ||
name: openshift-patch-resource | ||
vars: | ||
api_version: v1 | ||
definition: | ||
metadata: | ||
labels: | ||
patch-role: patched | ||
kind: Namespace | ||
merge_type: strategic-merge | ||
name: default | ||
- name: Get annotated namespace | ||
k8s_info: | ||
kind: Namespace | ||
label_selectors: | ||
- patch-role=patched | ||
register: r_namespace_label | ||
- name: Assert namespace was labelled | ||
assert: | ||
that: | ||
- (r_namespace_label.resources | length) == 1 | ||
- "'patched' in r_namespace_label.resources[0].metadata.labels['patch-role']" | ||
fail_msg: "Expected one namespace with the label 'patch-role: patched'" | ||
success_msg: "There's one namespace with the label 'patch-role: patched'" | ||
- name: Remove patch-role label (merge strategy) | ||
include_role: | ||
name: openshift-patch-resource | ||
vars: | ||
api_version: v1 | ||
definition: | ||
metadata: | ||
labels: | ||
patch-role: null | ||
kind: Namespace | ||
merge_type: merge | ||
name: default | ||
- name: Get annotated namespace | ||
k8s_info: | ||
kind: Namespace | ||
label_selectors: | ||
- patch-role=patched | ||
register: r_namespace | ||
- name: Assert namespace label was removed | ||
assert: | ||
that: | ||
- (r_namespace.resources | length) == 0 | ||
fail_msg: "Expected zero namespace with the label 'patch-role: patched'" | ||
success_msg: "There's no namespace with the label 'patch-role: patched'" | ||
``` | ||
|
||
License | ||
------- | ||
|
||
Apache 2.0 | ||
|
||
Author Information | ||
------------------ | ||
|
||
Red Hat Community of Practice & staff of the Red Hat Open Innovation Labs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
# tasks file for openshift-patch-resource | ||
- name: Patch {{ api_version }} {{ kind }}/{{ name }} | ||
k8s: | ||
api_version: "{{ api_version }}" | ||
kind: "{{ kind }}" | ||
merge_type: "{{ merge_type| default(omit) }}" | ||
name: "{{ name }}" | ||
namespace: "{{ namespace | default(omit) }}" | ||
definition: "{{ definition | default(omit) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
localhost ansible_connection=local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../roles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
- hosts: localhost | ||
tasks: | ||
- name: Patch annotations on default project (strategic-merge strategy) | ||
include_role: | ||
name: openshift-patch-resource | ||
vars: | ||
api_version: v1 | ||
definition: | ||
metadata: | ||
labels: | ||
patch-role: patched | ||
kind: Namespace | ||
merge_type: strategic-merge | ||
name: default | ||
- name: Get annotated namespace | ||
k8s_info: | ||
kind: Namespace | ||
label_selectors: | ||
- patch-role=patched | ||
register: r_namespace_label | ||
- name: Assert namespace was labelled | ||
assert: | ||
that: | ||
- (r_namespace_label.resources | length) == 1 | ||
- "'patched' in r_namespace_label.resources[0].metadata.labels['patch-role']" | ||
fail_msg: "Expected one namespace with the label 'patch-role: patched'" | ||
success_msg: "There's one namespace with the label 'patch-role: patched'" | ||
- name: Remove patch-role label (merge strategy) | ||
include_role: | ||
name: openshift-patch-resource | ||
vars: | ||
api_version: v1 | ||
definition: | ||
metadata: | ||
labels: | ||
patch-role: null | ||
kind: Namespace | ||
merge_type: merge | ||
name: default | ||
- name: Get annotated namespace | ||
k8s_info: | ||
kind: Namespace | ||
label_selectors: | ||
- patch-role=patched | ||
register: r_namespace | ||
- name: Assert namespace label was removed | ||
assert: | ||
that: | ||
- (r_namespace.resources | length) == 0 | ||
fail_msg: "Expected zero namespace with the label 'patch-role: patched'" | ||
success_msg: "There's no namespace with the label 'patch-role: patched'" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we include some example vars here as well? ... or maybe just point to the tests to see some examples?