Skip to content

Commit 25f210a

Browse files
Merge pull request #115 from prajwal-gawande492/srv-con-fun1
Automation to validate service controller function on IPI cluster
2 parents e50ffec + 5febd25 commit 25f210a

File tree

10 files changed

+273
-0
lines changed

10 files changed

+273
-0
lines changed

examples/all.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,6 @@ update_channel: ""
556556
odf_catalogsource_image: "" #Example - quay.io/rhceph-dev/ocs-registry:4.16.3
557557
test_pod_image: "quay.io/powercloud/nginx-unprivileged:latest"
558558

559+
## ocp-service-controller-function vars
560+
ocp-service: false
561+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## ocp-service-controller-function vars
2+
ocp-service: true
3+
4+

group_vars/all.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ global_secret_update: false
4141
## ocp-etcd-encryption-decryption vars
4242
ocp_etcd: false
4343

44+
## ocp-service-controller-function required vars
45+
ocp_service: false
46+
4447
## ocp-cluster-log-forwarding required vars
4548
ocp_cluster_logging: false
4649
cluster_log_forwarder: false
@@ -155,6 +158,7 @@ initiator_name: # eg. iqn.2021-04.com.redhat:initiator2
155158
iqn: # eg. iqn.2021-04.redhat.com:iscsitarget2
156159
target_IP: ""
157160

161+
158162
# hypershift required vars for installation/destroy
159163
mgmt_cluster_kubeconfig: "{{ ansible_env.HOME }}/.kube/config"
160164
hosted_cluster_name: "rdr-hypershift-cluster"

playbooks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
3+
- import_playbook: ocp-service-controller-function.yml
4+
when: ocp-service is defined and ocp-service
5+
26
- import_playbook: ocp-scale.yml
37
when: scale_test_enabled
48

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- name: Run the Service Controller function
2+
hosts: localhost
3+
roles:
4+
- ocp-service-controller-function
5+
6+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
OCP Service Controller Function on IPI (Installer Provision Infrastructure) cluster
2+
=========
3+
This ansible playbook can be used for validating the Service controller functions (services of type loadbalancer) on IPI cluster.
4+
5+
It deploys the sample-app and service loadbalancer to check the functionality on IPI cluster.
6+
7+
8+
Requirements
9+
------------
10+
11+
- OCP IPI 4.x healthy cluster
12+
- The cluster is in a known good state, without any errors.
13+
14+
15+
16+
Role Variables
17+
--------------
18+
19+
| Variable | Required | Default | Comments |
20+
|-----------------------------|----------|--------------------------------------------|-----------------------------------------------------|
21+
| ocp_service| no | false | Flag to be set to true to run this playbook |
22+
23+
Dependencies
24+
------------
25+
26+
- None
27+
28+
Example Playbook
29+
----------------
30+
```
31+
- name: Run the Service Controller function
32+
hosts: localhost
33+
roles:
34+
- ocp-service-controller-function
35+
```
36+
37+
License
38+
-------
39+
40+
See LICENCE.txt
41+
42+
Author Information
43+
------------------
44+
45+
46+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test_namespace: "test-privileged"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: go-web-app
5+
namespace: test-privileged
6+
spec:
7+
replicas: 2
8+
selector:
9+
matchLabels:
10+
name: go-web-app
11+
template:
12+
metadata:
13+
labels:
14+
name: go-web-app
15+
spec:
16+
containers:
17+
- name: application
18+
image: karthikkn27/go-web-app-on-scratch
19+
imagePullPolicy: IfNotPresent
20+
ports:
21+
- containerPort: 7777
22+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: test-svc
5+
namespace: test-privileged
6+
spec:
7+
type: LoadBalancer
8+
ports:
9+
- name: http
10+
port: 80
11+
targetPort: 7777
12+
selector:
13+
name: go-web-app
14+
externalTrafficPolicy: Cluster
15+
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
3+
- name: Check if cluster operators and nodes are healthy
4+
include_role:
5+
name: check-cluster-health
6+
7+
- name: Delete the service if already exist
8+
kubernetes.core.k8s:
9+
state: absent
10+
api_version: v1
11+
kind: Service
12+
namespace: test-privileged
13+
name: test-svc
14+
ignore_errors: true
15+
16+
- name: Delete the sample-app if already exist
17+
kubernetes.core.k8s:
18+
state: absent
19+
api_version: apps/v1
20+
kind: Deployment
21+
namespace: test-privileged
22+
name: go-web-app
23+
ignore_errors: true
24+
25+
- name: Create namespace and labels to deploy sample-web-app
26+
kubernetes.core.k8s:
27+
name: "{{ test_namespace }}"
28+
api_version: v1
29+
kind: Namespace
30+
state: present
31+
32+
- name: Add label to the "{{ test_namespace }}" namespace
33+
kubernetes.core.k8s:
34+
state: patched
35+
kind: Namespace
36+
name: "{{ test_namespace }}"
37+
definition:
38+
metadata:
39+
labels:
40+
security.openshift.io/scc.podSecurityLabelSync: "false"
41+
pod-security.kubernetes.io/enforce: privileged
42+
pod-security.kubernetes.io/audit: privileged
43+
pod-security.kubernetes.io/warn: privileged
44+
45+
- name: Run sample-web-app file
46+
kubernetes.core.k8s:
47+
state: present
48+
src: "{{ role_path }}/files/sample-web-app.yaml"
49+
50+
- name: Wait for sample-app to come up
51+
wait_for:
52+
timeout: 120
53+
delay: 2
54+
55+
- name: Check for the pods
56+
shell: oc get pods -n "{{ test_namespace }}"
57+
register: check_pod
58+
59+
- name: Check if the pods are in Running state
60+
shell: oc get pods -n "{{ test_namespace }}" -o jsonpath='{.items[0].status.phase}'
61+
register: pods_status
62+
until: pods_status.stdout == "Running"
63+
retries: 15
64+
delay: 60
65+
66+
- debug:
67+
msg: "{{ check_pod.stdout_lines }}"
68+
69+
- name: Run the service file
70+
kubernetes.core.k8s:
71+
state: present
72+
src: "{{ role_path }}/files/test-svc.yaml"
73+
register: create_service
74+
when: pods_status.stdout == "Running"
75+
76+
- name: Wait for service to come up
77+
wait_for:
78+
timeout: 120
79+
delay: 2
80+
81+
- name: Check the service
82+
shell: oc get service -A | grep test-svc
83+
register: check_service
84+
85+
- debug:
86+
msg: "{{ check_service.stdout_lines }}"
87+
88+
- name: Get the pod
89+
shell: oc get pods -n "{{ test_namespace }}" -o=jsonpath='{.items[0].metadata.name}'
90+
register: first_pod
91+
92+
- name: Check the logs of the service
93+
shell: oc logs "{{ first_pod.stdout }}" -n "{{ test_namespace }}"
94+
register: service_logs
95+
96+
- debug:
97+
msg: "{{ service_logs.stdout_lines }}"
98+
99+
- name: Get the externalIP of the service
100+
shell: oc get service -n "{{ test_namespace }}" -o=jsonpath='{.items[0].status.loadBalancer.ingress[0].hostname}'
101+
register: lb_externalip
102+
103+
- name: Wait for loadbalancer to comes up
104+
wait_for:
105+
delay: 5
106+
107+
- name: Check the application is accessible through an external IP
108+
shell: curl http://{{ lb_externalip.stdout }}
109+
register: curl_ip
110+
when: lb_externalip.stdout != ''
111+
112+
- debug:
113+
msg: "{{ curl_ip.stdout_lines }}"
114+
115+
- name: Verify the logs from the external ip
116+
shell: echo "Successfully validate the service controller function"
117+
when: curl_ip.stdout == "My Go App"
118+
register: success_msg
119+
120+
- debug:
121+
msg: "{{ success_msg.stdout_lines }}"
122+
123+
- name: Clean up the service
124+
kubernetes.core.k8s:
125+
state: absent
126+
api_version: v1
127+
kind: Service
128+
namespace: "{{ test_namespace }}"
129+
name: test-svc
130+
ignore_errors: true
131+
132+
- name: Check if the service has been deleted
133+
shell: oc get service -A --no-headers | grep test-svc | wc -l
134+
register: func_srv
135+
until: func_srv.stdout|int == 0
136+
retries: 15
137+
delay: 60
138+
139+
- name: Clean up the sample-app resources
140+
kubernetes.core.k8s:
141+
api_version: apps/v1
142+
namespace: "{{ test_namespace }}"
143+
kind: Deployment
144+
state: absent
145+
name: go-web-app
146+
ignore_errors: true
147+
148+
- name: Check if all the pods has been deleted
149+
shell: oc get pods -n "{{ test_namespace }}" --no-headers | wc -l
150+
register: del_pod
151+
until: del_pod.stdout|int == 0
152+
retries: 15
153+
delay: 60
154+
155+
- name: Delete namespace created for sample-web-app
156+
kubernetes.core.k8s:
157+
name: "{{ test_namespace }}"
158+
api_version: v1
159+
kind: Namespace
160+
state: absent
161+
162+
- name: Check if the namespace gets deleted
163+
shell: oc get namespace --no-headers | grep "{{ test_namespace }}" | wc -l
164+
register: srv_namespace
165+
until: srv_namespace.stdout|int == 0
166+
retries: 15
167+
delay: 30

0 commit comments

Comments
 (0)