Browse Source

adopt oc_scale for openshift_metrics role

Jeff Cantrill 8 years ago
parent
commit
1d93498a1d

+ 1 - 0
roles/openshift_metrics/meta/main.yaml

@@ -15,4 +15,5 @@ galaxy_info:
   categories:
   - openshift
 dependencies:
+- { role: lib_openshift }
 - { role: openshift_facts }

+ 0 - 30
roles/openshift_metrics/tasks/scale.yaml

@@ -1,30 +0,0 @@
----
-- command: >
-    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get {{object}}
-    -o jsonpath='{.spec.replicas}' -n {{openshift_metrics_project}}
-  register: replica_count
-  failed_when: "replica_count.rc == 1 and 'exists' not in replica_count.stderr"
-  when: not ansible_check_mode
-  changed_when: no
-
-- command: >
-    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig scale {{object}}
-    --replicas={{desired}} -n {{openshift_metrics_project}}
-  register: scale_result
-  failed_when: scale_result.rc == 1 and 'exists' not in scale_result.stderr
-  when:
-  - replica_count.stdout != (desired | string)
-  - not ansible_check_mode
-  changed_when: no
-
-- name: Waiting for {{object}} to scale to {{desired}}
-  command: >
-    {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
-    get {{object}} -n {{openshift_metrics_project|quote}} -o jsonpath='{.status.replicas}'
-  register: replica_counts
-  until: replica_counts.stdout.find("{{desired}}") != -1
-  retries: 30
-  delay: 10
-  when:
-  - replica_count.stdout != (desired | string)
-  - not ansible_check_mode

+ 18 - 9
roles/openshift_metrics/tasks/start_metrics.yaml

@@ -10,9 +10,12 @@
   changed_when: no
 
 - name: Start Hawkular Cassandra
-  include: scale.yaml
-  vars:
-    desired: 1
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: 1
   with_items: "{{metrics_cassandra_rc.stdout_lines}}"
   loop_control:
     loop_var: object
@@ -28,9 +31,12 @@
   changed_when: no
 
 - name: Start Hawkular Metrics
-  include: scale.yaml
-  vars:
-    desired: "{{openshift_metrics_hawkular_replicas}}"
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: "{{openshift_metrics_hawkular_replicas}}"
   with_items: "{{metrics_metrics_rc.stdout_lines}}"
   loop_control:
     loop_var: object
@@ -46,9 +52,12 @@
   changed_when: no
 
 - name: Start Heapster
-  include: scale.yaml
-  vars:
-    desired: 1
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: 1
   with_items: "{{metrics_heapster_rc.stdout_lines}}"
   loop_control:
     loop_var: object

+ 18 - 9
roles/openshift_metrics/tasks/stop_metrics.yaml

@@ -11,9 +11,12 @@
   check_mode: no
 
 - name: Stop Heapster
-  include: scale.yaml
-  vars:
-    desired: 0
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: 0
   with_items: "{{metrics_heapster_rc.stdout_lines}}"
   loop_control:
     loop_var: object
@@ -29,9 +32,12 @@
   changed_when: "'No resources found' not in metrics_hawkular_rc.stderr"
 
 - name: Stop Hawkular Metrics
-  include: scale.yaml
-  vars:
-    desired: 0
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: 0
   with_items: "{{metrics_hawkular_rc.stdout_lines}}"
   loop_control:
     loop_var: object
@@ -46,9 +52,12 @@
   changed_when: "'No resources found' not in metrics_cassandra_rc.stderr"
 
 - name: Stop Hawkular Cassandra
-  include: scale.yaml
-  vars:
-    desired: 0
+  oc_scale:
+    kind: rc
+    name: "{{object.split('/')[1]}}"
+    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
+    namespace: "{{openshift_metrics_project}}"
+    replicas: 0
   with_items: "{{metrics_cassandra_rc.stdout_lines}}"
   loop_control:
     loop_var: object