Skip to content

Commit

Permalink
Create Playbook for developing and testing sample helm, ansible and g…
Browse files Browse the repository at this point in the history
…o based operator using operator-sdk

Signed-off-by: SurajGudaji <[email protected]>
  • Loading branch information
SurajGudaji committed Jan 2, 2025
1 parent a4886eb commit b85bc7f
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,15 @@ db_volume_size: "10Gi"
fs_volume_size: "100Gi"
iso_url: ""
root_fs_url: ""

# ocp-operator-api vars
op_api_role_enable: false
helm_op: false
ansible_op: false
go_op: false
op_cleanup: false
OPERATOR_SDK_VERSION: "1.38.0"
op_api_dir: "/tmp/operator-api"
HELM_OP_IMAGE: "quay.io/{{quay_username}}/nginx-operator-helm:v1"
ANSIBLE_OP_IMAGE: "quay.io/{{quay_username}}/memcached-operator-ansible:v1"
GO_OP_IMAGE: "quay.io/{{quay_username}}/memcached-operator-go:v1"
12 changes: 12 additions & 0 deletions examples/ocp_operator_api-vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

op_api_role_enable: false
helm_op: false
ansible_op: false
go_op: false
op_cleanup: false
OPERATOR_SDK_VERSION: "1.38.0"
op_api_dir: "/tmp/operator-api"
HELM_OP_IMAGE: "quay.io/{{quay_username}}/nginx-operator-helm:v1"
ANSIBLE_OP_IMAGE: "quay.io/{{quay_username}}/memcached-operator-ansible:v1"
GO_OP_IMAGE: "quay.io/{{quay_username}}/memcached-operator-go:v1"
3 changes: 3 additions & 0 deletions playbooks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@
when: >
(hypershift_agent_install is defined and hypershift_agent_install) or
(hypershift_agent_destroy is defined and hypershift_agent_destroy)
- import_playbook: ocp-operator-api.yml
when: op_api_role_enable is defined and op_api_role_enable
7 changes: 7 additions & 0 deletions playbooks/ocp-operator-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Validate Operator development and installation
hosts: bastion
tasks:
- name: Validate Operator development and installation
include_role:
name: ocp-operator-api
59 changes: 59 additions & 0 deletions playbooks/roles/ocp-operator-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ocp-operator-api
=========

This role is used to validate operator development using operator-sdk.

Requirements
------------

- OCP 4.x healthy cluster on Power.


Role Variables
--------------

| Variable | Required | Default | Comments |
|--------------------------------------------|----------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| op_api_role_enable | no | false | Set it to true to run this playbook |
| op_cleanup | no | false | Set it to true to do operator cleanup. |
| helm_op | no | false | Set it to true to test helm based operator |
| ansible_op | no | false | Set it to true to test ansible based operator |
| go_op | no | false | Set it to true to test go based operator |
| OPERATOR_SDK_VERSION | no | "1.38.0" | Version of operator-sdk to be installed. |
| op_api_dir | no | "/tmp/operator-api" | Directory where the operator workspace are intialized. |
| quay_username | yes | | quay account username where the operator images will be pushed |
| quay_token | yes | | quay account token to push the operator images |




Dependencies
------------

- ansible-runner
- ansible-runner-http
- openshift

Example Playbook
----------------

```
---
- name: Validate Operator development and installation
hosts: bastion
tasks:
- name: Validate Operator development and installation
include_role:
name: ocp-operator-api
```


License
-------

See LICENCE.txt

Author Information
------------------

[email protected]
12 changes: 12 additions & 0 deletions playbooks/roles/ocp-operator-api/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

op_api_role_enable: false
helm_op: false
ansible_op: false
go_op: false
op_cleanup: false
operator_sdk_version: "1.38.0"
op_api_dir: "/tmp/operator-api"
helm_op_image: "quay.io/{{quay_username}}/nginx-operator-helm:v1"
ansible_op_image: "quay.io/{{quay_username}}/memcached-operator-ansible:v1"
go_op_image: "quay.io/{{quay_username}}/memcached-operator-go:v1"
24 changes: 24 additions & 0 deletions playbooks/roles/ocp-operator-api/files/memcached-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: start memcached
k8s:
definition:
kind: Deployment
apiVersion: apps/v1
metadata:
name: '{{ ansible_operator_meta.name }}-memcached'
namespace: '{{ ansible_operator_meta.namespace }}'
spec:
replicas: "{{size}}"
selector:
matchLabels:
app: memcached
template:
metadata:
labels:
app: memcached
spec:
containers:
- name: memcached
image: "docker.io/ppc64le/memcached"
ports:
- containerPort: 11211
60 changes: 60 additions & 0 deletions playbooks/roles/ocp-operator-api/tasks/cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---

- name: Cleanup
block:
- name: Delete Nginx instance
command: oc delete -f "{{ op_api_dir }}/helm-op/config/samples/helm_v1_nginx.yaml"
args:
chdir: "{{ op_api_dir }}/helm-op"

- name: Verify Nginx instance is deleted
shell: oc get Nginx --no-headers | wc -l
register: nginx_instance
until: nginx_instance.stdout|int == 0 and nginx_instance.stderr == "No resources found in default namespace."
retries: 10
delay: 10

- name: Nginx helm operator cleanup
command: make undeploy IMG="{{ HELM_OP_IMAGE }}"
args:
chdir: "{{ op_api_dir }}/helm-op"

- name: Delete Memcached instance
command: oc delete -f "{{ op_api_dir }}/ansible-op/config/samples/cache_v1_memcached.yaml"
args:
chdir: "{{ op_api_dir }}/go-op"

- name: Verify Memcached instance is deleted
shell: oc get Memcached --no-headers | wc -l
register: memcached_instance
until: memcached_instance.stdout|int == 0 and memcached_instance.stderr == "No resources found in default namespace."
retries: 10
delay: 10

- name: Memcached ansible operator cleanup
command: make undeploy IMG="{{ ANSIBLE_OP_IMAGE }}"
args:
chdir: "{{ op_api_dir }}/ansible-op"

- name: Delete MemcachedGo instance
command: oc delete -f "{{ op_api_dir }}/go-op/config/samples/cache1_v1_memcachedgo.yaml"
args:
chdir: "{{ op_api_dir }}/go-op"

- name: Verify Memcached instance is deleted
shell: oc get MemcachedGo --no-headers | wc -l
register: memcached_instance
until: memcached_instance.stdout|int == 0 and memcached_instance.stderr == "No resources found in default namespace."
retries: 10
delay: 10

- name: MemcachedGo operator cleanup
command: make undeploy IMG="{{ GO_OP_IMAGE }}"
args:
chdir: "{{ op_api_dir }}/go-op"

- name: Delete the workspace
file:
path: "{{ op_api_dir }}"
state: "absent"
when: op_cleanup
Loading

0 comments on commit b85bc7f

Please sign in to comment.