Skip to content

Commit 40807f1

Browse files
authored
Add OCP-CNV patching demo (#140)
1 parent 6593693 commit 40807f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1896
-2
lines changed

ansible-navigator.yml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
Role Name
2+
=========
3+
4+
This Ansible role helps configure Operators on the Openshift Cluster to support VM migrations. Tasks include
5+
- Configure Catalog Sources to use mirroring repository for Operators
6+
- Create and configure Operators
7+
8+
9+
Requirements
10+
------------
11+
12+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
13+
14+
Role Variables
15+
--------------
16+
17+
The task `operators/catalog_sources.yml` needs following variables:
18+
19+
- **Variable Name**: `cluster_config_catalog_sources`
20+
- **Type**: List
21+
- **Description**: A list of custom CatalogSources configurations used as loop variables to generate Kubernetes manifest files from the template `catalog_source.j2` for CatalogSource. If the variable is not available, no manifest is created.
22+
- **Example**:
23+
```yaml
24+
cluster_config_catalog_sources:
25+
- name: redhat-marketplace2
26+
source_type: grpc
27+
display_name: Mirror to Red Hat Marketplace
28+
image_path: internal-registry.example.com/operator:v1
29+
priority: '-300'
30+
icon:
31+
base64data: ''
32+
mediatype: ''
33+
publisher: redhat
34+
address: ''
35+
grpc_pod_config: |
36+
nodeSelector:
37+
kubernetes.io/os: linux
38+
node-role.kubernetes.io/master: ''
39+
priorityClassName: system-cluster-critical
40+
securityContextConfig: restricted
41+
tolerations:
42+
- effect: NoSchedule
43+
key: node-role.kubernetes.io/master
44+
operator: Exists
45+
- effect: NoExecute
46+
key: node.kubernetes.io/unreachable
47+
operator: Exists
48+
tolerationSeconds: 120
49+
- effect: NoExecute
50+
key: node.kubernetes.io/not-ready
51+
operator: Exists
52+
tolerationSeconds: 120
53+
registry_poll_interval: 10m
54+
```
55+
56+
The task `operators/operator_config.yaml` needs following variables:
57+
58+
- **Variable Name**: `cluster_config_operators`
59+
- **Type**: List
60+
- **Description**: A list of operators to be installed on OCP cluster
61+
- **Variable Name**: `cluster_config_[OPERATOR_NAME]`
62+
- **Type**: Dict
63+
- **Description**: Configuration specific to each operator listed in `cluster_config_operators`. Includes settings for namespace, operator group, subscription, and any extra resources
64+
- **Example**: Assume the `cluster_config_operators` specifies these operators:
65+
```yaml
66+
cluster_config_operators:
67+
- cnv
68+
- oadp
69+
```
70+
then the corresponding `cluster_config_mtv` and `cluster_config_cnv` can be configured as following:
71+
```yaml
72+
cluster_config_cnv_namespace: openshift-cnv
73+
cluster_config_cnv:
74+
namespace:
75+
name: "{{ cluster_config_cnv_namespace }}"
76+
operator_group:
77+
name: kubevirt-hyperconverged-group
78+
target_namespaces:
79+
- "{{ cluster_config_cnv_namespace }}"
80+
subscription:
81+
name: kubevirt-hyperconverged
82+
starting_csv: kubevirt-hyperconverged-operator.v4.13.8
83+
extra_resources:
84+
- apiVersion: hco.kubevirt.io/v1beta1
85+
kind: HyperConverged
86+
metadata:
87+
name: kubevirt-hyperconverged
88+
namespace: "{{ cluster_config_cnv_namespace }}"
89+
spec:
90+
BareMetalPlatform: true
91+
92+
cluster_config_oadp_namespace: openshift-adp
93+
cluster_config_oadp:
94+
namespace:
95+
name: "{{ cluster_config_oadp_namespace }}"
96+
operator_group:
97+
name: redhat-oadp-operator-group
98+
target_namespaces:
99+
- "{{ cluster_config_oadp_namespace }}"
100+
subscription:
101+
name: redhat-oadp-operator-subscription
102+
spec_name: redhat-oadp-operator
103+
```
104+
Dependencies
105+
------------
106+
107+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
108+
109+
Example Playbook
110+
----------------
111+
112+
An example of configuring a CatalogSource resource:
113+
```
114+
- name: Configure Catalog Sources for Operators
115+
hosts: localhost
116+
gather_facts: false
117+
tasks:
118+
- ansible.builtin.include_role:
119+
name: cluster_config
120+
tasks_from: operators/catalog_sources
121+
```
122+
123+
License
124+
-------
125+
126+
BSD
127+
128+
Author Information
129+
------------------
130+
131+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
# defaults file for cluster_config
3+
cluster_config_operators:
4+
- cnv
5+
6+
cluster_config_cnv:
7+
checkplan: true
8+
namespace:
9+
name: &cluster_config_cnv_namespace openshift-cnv
10+
operator_group:
11+
name: kubevirt-hyperconverged-group
12+
target_namespaces:
13+
- *cluster_config_cnv_namespace
14+
subscription:
15+
name: kubevirt-hyperconverged
16+
extra_resources:
17+
- apiVersion: hco.kubevirt.io/v1beta1
18+
kind: HyperConverged
19+
metadata:
20+
name: kubevirt-hyperconverged
21+
namespace: *cluster_config_cnv_namespace
22+
spec:
23+
BareMetalPlatform: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for cluster_config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- name: Configure Operators
3+
ansible.builtin.import_tasks: operators/operator_config.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
- name: Retrieve Operator name
3+
ansible.builtin.set_fact:
4+
_operator: "{{ vars['cluster_config_' + _operator_name] }}"
5+
- name: Configure Operator {{ _operator_name }}
6+
redhat.openshift.k8s:
7+
state: present
8+
template:
9+
- operators/namespace.yml.j2
10+
- operators/operator_group.yml.j2
11+
- operators/subscription.yml.j2
12+
- name: Query for install plan
13+
kubernetes.core.k8s_info:
14+
api_version: operators.coreos.com/v1alpha1
15+
kind: InstallPlan
16+
namespace: "{{ _operator.namespace.name }}"
17+
register: r_install_plans
18+
retries: 30
19+
delay: 5
20+
until:
21+
- r_install_plans.resources | default([]) | length > 0
22+
- r_install_plans.resources[0].status is defined
23+
- r_install_plans.resources[0].status.phase == "Complete"
24+
when:
25+
- _operator.checkplan is defined
26+
- _operator.checkplan | bool
27+
28+
- name: Configure extra resources for Operator {{ _operator_name }}
29+
redhat.openshift.k8s:
30+
state: present
31+
definition: "{{ item }}"
32+
register: creation_result
33+
loop: "{{ _operator.extra_resources }}"
34+
retries: 30
35+
delay: 5
36+
until: creation_result is success
37+
when: _operator.extra_resources is defined
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Configure custom CatalogSource for Operators
3+
redhat.openshift.k8s:
4+
state: present
5+
template: operators/catalog_source.j2
6+
loop: "{{ cluster_config_catalog_sources }}"
7+
when: cluster_config_catalog_sources is defined
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
- name: Create node-health-check operator namespace
3+
redhat.openshift.k8s:
4+
name: openshift-workload-availability
5+
api_version: v1
6+
kind: Namespace
7+
state: present
8+
9+
- name: Create node-health-check operator group
10+
redhat.openshift.k8s:
11+
state: present
12+
definition:
13+
apiVersion: operators.coreos.com/v1
14+
kind: OperatorGroup
15+
metadata:
16+
generateName: openshift-workload-availability-
17+
annotations:
18+
olm.providedAPIs: >-
19+
NodeHealthCheck.v1alpha1.remediation.medik8s.io,SelfNodeRemediation.v1alpha1.self-node-remediation.medik8s.io,SelfNodeRemediationConfig.v1alpha1.self-node-remediation.medik8s.io,SelfNodeRemediationTemplate.v1alpha1.self-node-remediation.medik8s.io
20+
namespace: openshift-workload-availability
21+
spec:
22+
upgradeStrategy: Default
23+
24+
- name: Create node-health-check operator subscription
25+
redhat.openshift.k8s:
26+
state: present
27+
definition:
28+
apiVersion: operators.coreos.com/v1alpha1
29+
kind: Subscription
30+
metadata:
31+
labels:
32+
operators.coreos.com/node-healthcheck-operator.openshift-workload-availability: ''
33+
name: node-health-check-operator
34+
namespace: openshift-workload-availability
35+
spec:
36+
channel: stable
37+
installPlanApproval: Automatic
38+
name: node-healthcheck-operator
39+
source: redhat-operators
40+
sourceNamespace: openshift-marketplace
41+
42+
- name: Create Self Node Remediation subscription
43+
redhat.openshift.k8s:
44+
state: present
45+
definition:
46+
apiVersion: operators.coreos.com/v1alpha1
47+
kind: Subscription
48+
metadata:
49+
name: self-node-remediation-stable-redhat-operators-openshift-marketplace
50+
namespace: openshift-workload-availability
51+
labels:
52+
operators.coreos.com/self-node-remediation.openshift-workload-availability: ''
53+
spec:
54+
channel: stable
55+
installPlanApproval: Automatic
56+
name: self-node-remediation
57+
source: redhat-operators
58+
sourceNamespace: openshift-marketplace
59+
startingCSV: self-node-remediation.v0.8.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Configure Operators
3+
ansible.builtin.include_tasks: _operator_config_item.yml
4+
loop: "{{ cluster_config_operators }}"
5+
loop_control:
6+
loop_var: _operator_name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: CatalogSource
3+
metadata:
4+
name: {{ item.name }}
5+
namespace: openshift-marketplace
6+
spec:
7+
sourceType: {{ item.source_type | d('grpc',true) }}
8+
image: {{ item.image_path }}
9+
{% if item.display_name is defined -%}
10+
displayName: {{ item.display_name }}
11+
{% endif -%}
12+
{% if item.priority is defined -%}
13+
priority: {{ item.priority }}
14+
{% endif -%}
15+
{% if item.grpc_pod_config is defined -%}
16+
grpcPodConfig:
17+
{{ item.grpc_pod_config | indent(4) }}
18+
{% endif -%}
19+
{% if item.icon is defined -%}
20+
icon:
21+
base64data: '{{ item.icon.base64data or '' }}'
22+
mediatype: '{{ item.icon.mediatype or '' }}'
23+
{% endif -%}
24+
{% if item.publisher is defined -%}
25+
publisher: {{ item.publisher }}
26+
{% endif -%}
27+
{% if item.address is defined -%}
28+
address: {{ item.address }}
29+
{% endif -%}
30+
{% if item.registry_poll_interval is defined -%}
31+
updateStrategy:
32+
registryPoll:
33+
interval: {{ item.registry_poll_interval }}
34+
{% endif -%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: {{ _operator.namespace.name }}
5+
{% if _operator.namespace.labels is defined %}
6+
labels:
7+
{% for key, value in _operator.namespace.labels.items() -%}
8+
{{ key }}: "{{ value }}"
9+
{% endfor -%}
10+
{% endif -%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: operators.coreos.com/v1
2+
kind: OperatorGroup
3+
metadata:
4+
name: {{ _operator.operator_group.name }}
5+
namespace: {{ _operator.operator_group.namespace | d(_operator.namespace.name, true) }}
6+
spec:
7+
{% if _operator.operator_group.target_namespaces is defined -%}
8+
targetNamespaces:
9+
{% for item in _operator.operator_group.target_namespaces %}
10+
- {{ item }}
11+
{% endfor %}
12+
{% endif -%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: Subscription
3+
metadata:
4+
name: {{ _operator.subscription.name }}
5+
namespace: "{{ _operator.subscription.namespace | d(_operator.namespace.name, true) }}"
6+
spec:
7+
channel: {{ _operator.subscription.channel | d('stable', true) }}
8+
installPlanApproval: {{ _operator.subscription.install_plan_approval | d('Automatic', true) }}
9+
name: {{ _operator.subscription.spec_name | d(_operator.subscription.name, true) }}
10+
source: {{ _operator.subscription.source | d('redhat-operators', true) }}
11+
sourceNamespace: {{ _operator.subscription.source_namespace | d('openshift-marketplace', true) }}
12+
{% if _operator.subscription.starting_csv is defined %}
13+
startingCSV: {{ _operator.subscription.starting_csv }}
14+
{% endif -%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
localhost
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Include cluster_config role
3+
hosts: localhost
4+
remote_user: root
5+
roles:
6+
- cluster_config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# vars file for cluster_config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
build_report_linux_patch
2+
========
3+
4+
Installs Apache and creates a report based on facts from Linux patching
5+
6+
Requirements
7+
------------
8+
9+
Must run on Apache server
10+
11+
Role Variables / Configuration
12+
--------------
13+
14+
N/A
15+
16+
Dependencies
17+
------------
18+
19+
N/A
20+
21+
Example Playbook
22+
----------------
23+
24+
The role can be used to create an html report on any number of Linux hosts using any number of Linux servers about their patching results(yum and dnf)
25+
26+
27+
```
28+
---
29+
- hosts: all
30+
31+
tasks:
32+
- name: Run Windows Report
33+
import_role:
34+
name: shadowman.reports.build_report_linux_patch
35+
36+
```

0 commit comments

Comments
 (0)