-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Playbook for for developing and testing sample helm based oper…
…ator using operator-sdk Signed-off-by: SurajGudaji <[email protected]>
- Loading branch information
1 parent
edfe340
commit deaf79b
Showing
7 changed files
with
182 additions
and
0 deletions.
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,10 @@ | ||
--- | ||
|
||
op_api_role_enable: false | ||
build_operator_image: true | ||
deploy_operator: false | ||
OPERATOR_SDK_VERSION: "1.37.0" | ||
op_api_dir: "/tmp/operator-api" | ||
ocp_version: "418" | ||
quay_username: "" | ||
HELM_OP_IMAGE: "quay.io/{{quay_username}}/nginx-operator-helm:{{ ocp_version }}" |
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
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,8 @@ | ||
--- | ||
- name: Validate Operator development and installation | ||
hosts: bastion | ||
tasks: | ||
- name: Validate Operator development and installation | ||
include_role: | ||
name: ocp-operator-api | ||
|
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,59 @@ | ||
ocp-cluster-observability-operator | ||
========= | ||
|
||
This role is used to validate operator development using operator-sdk. | ||
|
||
Requirements | ||
------------ | ||
|
||
- OCP 4.x healthy cluster on PowerVS. | ||
|
||
|
||
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. | | ||
| build_operator_image | no | true | Set it to true to build the operator image | | ||
| deploy_operator | no | false | Set it to true to deploy the operators | | ||
| OPERATOR_SDK_VERSION | no | "1.37.0" | Version of operator-sdk to be installed. | | ||
| op_api_dir | no | "/tmp/operator-api" | Directory where the operator workspace are intialized. | | ||
| ocp_version | yes | | Openshift version on which this validation is run | | ||
| quay_username | yes | | quay account username where the operator images will be pushed | | ||
|
||
|
||
|
||
|
||
Dependencies | ||
------------ | ||
|
||
- Login to a quay.io account | ||
``` | ||
docker login -u='' -p='' quay.io | ||
``` | ||
|
||
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] |
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,11 @@ | ||
--- | ||
|
||
op_api_role_enable: false | ||
build_operator_image: true | ||
deploy_operator: false | ||
op_cleanup: false | ||
OPERATOR_SDK_VERSION: "1.37.0" | ||
op_api_dir: "/tmp/operator-api" | ||
ocp_version: "418" | ||
quay_username: "" | ||
HELM_OP_IMAGE: "quay.io/{{quay_username}}/nginx-operator-helm:{{ ocp_version }}" |
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,88 @@ | ||
--- | ||
|
||
- name: Check if cluster operators and nodes are healthy | ||
include_role: | ||
name: check-cluster-health | ||
|
||
- name: Download operator-sdk | ||
get_url: | ||
url: "https://github.com/operator-framework/operator-sdk/releases/download/v{{ OPERATOR_SDK_VERSION }}/operator-sdk_linux_ppc64le" | ||
dest: /usr/local/bin/operator-sdk | ||
mode: '0755' | ||
|
||
- name: Install required packages | ||
package: | ||
name: | ||
- docker | ||
state: present | ||
|
||
- name: Build and push operator images to quay.io | ||
block: | ||
- name: Create working directory for helm based nginx operator | ||
ansible.builtin.file: | ||
path: "{{ op_api_dir }}/helm-op" | ||
state: directory | ||
mode: '0755' | ||
|
||
- name: Intialize the helm based nginx operator project | ||
command: operator-sdk init --plugins=helm --domain=helm.com --group=helm --version=v1 --kind=Nginx | ||
args: | ||
chdir: "{{ op_api_dir }}/helm-op" | ||
|
||
- name: Build and push Nginx-helm operator image | ||
command: make docker-build docker-push IMG="{{ HELM_OP_IMAGE }}" | ||
args: | ||
chdir: "{{ op_api_dir }}/helm-op" | ||
when: build_operator_image | ||
|
||
- name: Deploy and Validate operator | ||
block: | ||
- name: Deploy helm based nginx operator | ||
command: make deploy IMG="{{ HELM_OP_IMAGE }}" | ||
args: | ||
chdir: "{{ op_api_dir }}/helm-op" | ||
|
||
- name: Verify helm based nginx operator | ||
shell: oc get pods -n helm-op-system --no-headers | grep -v "Running\|Completed" | wc -l | ||
register: helm_nginx_pods | ||
until: helm_nginx_pods.stdout|int == 0 and helm_nginx_pods.stderr == "" | ||
retries: 10 | ||
delay: 10 | ||
|
||
- name: Create a instance of Nginx resource | ||
command: oc create -f "{{ op_api_dir }}/helm-op/config/samples/helm_v1_nginx.yaml" | ||
args: | ||
chdir: "{{ op_api_dir }}/helm-op" | ||
|
||
- name: Verify if instance of nginx operator is created sucessfully | ||
shell: oc get pods --no-headers | grep -v "Running\|Completed" | grep nginx-sample |wc -l | ||
register: nginx_instance_pods | ||
until: nginx_instance_pods.stdout|int == 0 and nginx_instance_pods.stderr == "" | ||
retries: 10 | ||
delay: 10 | ||
when: deploy_operator | ||
|
||
- 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 nginx-sample --no-headers | wc -l | ||
register: nginx_instance | ||
until: nginx_instance.stdout|int == 0 and nginx_instance.stderr == "" | ||
retries: 10 | ||
delay: 10 | ||
|
||
- name: Operator cleanup | ||
command: make undeploy IMG="{{ HELM_OP_IMAGE }}" | ||
args: | ||
chdir: "{{ op_api_dir }}/helm-op" | ||
|
||
- name: Delete the workspace | ||
file: | ||
path: "{{ op_api_dir }}" | ||
state: "absent" | ||
when: op_cleanup |
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,3 @@ | ||
operator_api_env: | ||
PATH: "{{ ansible_env.PATH }}:/usr/local/bin/operator-sdk" | ||
KUBECONFIG: "{{ ansible_env.HOME }}/.kube/config" |