Przeglądaj źródła

fixes 1419839. Install only heapster for openshift_metrics when heapster standalone flag is set

Jeff Cantrill 8 lat temu
rodzic
commit
ea13eed3bf

+ 0 - 15
roles/openshift_metrics/tasks/generate_certificates.yaml

@@ -1,18 +1,4 @@
 ---
-- name: create certificate output directory
-  file:
-    path: "{{ openshift_metrics_certs_dir }}"
-    state: directory
-    mode: 0700
-
-- name: list existing secrets
-  command: >
-    {{ openshift.common.client_binary }} -n {{ openshift_metrics_project }}
-    --config={{ mktemp.stdout }}/admin.kubeconfig
-    get secrets -o name
-  register: metrics_secrets
-  changed_when: false
-
 - name: generate ca certificate chain
   shell: >
     {{ openshift.common.admin_binary }} ca create-signer-cert
@@ -22,5 +8,4 @@
     --serial='{{ openshift_metrics_certs_dir }}/ca.serial.txt'
     --name="metrics-signer@$(date +%s)"
   when: not '{{ openshift_metrics_certs_dir }}/ca.key' | exists
-- include: generate_heapster_certificates.yaml
 - include: generate_hawkular_certificates.yaml

+ 0 - 18
roles/openshift_metrics/tasks/generate_rolebindings.yaml

@@ -13,21 +13,3 @@
     - kind: ServiceAccount
       name: hawkular
   changed_when: no
-
-- name: generate cluster-reader role binding for the heapster service account
-  template:
-    src: rolebinding.j2
-    dest: "{{ mktemp.stdout }}/templates/heapster-rolebinding.yaml"
-  vars:
-    cluster: True
-    obj_name: heapster-cluster-reader
-    labels:
-      metrics-infra: heapster
-    roleRef:
-      kind: ClusterRole
-      name: cluster-reader
-    subjects:
-    - kind: ServiceAccount
-      name: heapster
-      namespace: "{{ openshift_metrics_project }}"
-  changed_when: no

+ 0 - 12
roles/openshift_metrics/tasks/generate_serviceaccounts.yaml

@@ -13,15 +13,3 @@
   - name: cassandra
     secret: hawkular-cassandra-secrets
   changed_when: no
-
-- name: Generating serviceaccount for heapster
-  template: src=serviceaccount.j2 dest={{mktemp.stdout}}/templates/metrics-{{obj_name}}-sa.yaml
-  vars:
-    obj_name: heapster
-    labels:
-      metrics-infra: support
-    secrets:
-    - heapster-secrets
-    - hawkular-metrics-certificate
-    - hawkular-metrics-account
-  changed_when: no

+ 0 - 13
roles/openshift_metrics/tasks/generate_services.yaml

@@ -1,17 +1,4 @@
 ---
-- name: Generate service for heapster
-  template: src=service.j2 dest={{mktemp.stdout}}/templates/metrics-{{obj_name}}-svc.yaml
-  vars:
-    obj_name: heapster
-    ports:
-    - {port: 80, targetPort: http-endpoint}
-    selector:
-      name: "{{obj_name}}"
-    labels:
-      metrics-infra: "{{obj_name}}"
-      name: "{{obj_name}}"
-  changed_when: no
-
 - name: Generate service for hawkular-metrics
   template: src=service.j2 dest={{mktemp.stdout}}/templates/metrics-{{obj_name}}-svc.yaml
   vars:

+ 52 - 0
roles/openshift_metrics/tasks/install_heapster.yaml

@@ -13,3 +13,55 @@
     replica_count: "{{heapster_replica_count.stdout | default(0)}}"
     node_selector: "{{openshift_metrics_heapster_nodeselector | default('') }}"
   changed_when: no
+
+- set_fact:
+    heapster_sa_secrets: ["heapster-secrets"]
+
+- set_fact:
+    heapster_sa_secrets: "{{ heapster_sa_secrets + [item] }}"
+  with_items:
+    - hawkular-metrics-certificate
+    - hawkular-metrics-account
+  when: "not {{ openshift_metrics_heapster_standalone | bool }}"
+
+- name: Generating serviceaccount for heapster
+  template: src=serviceaccount.j2 dest={{mktemp.stdout}}/templates/metrics-{{obj_name}}-sa.yaml
+  vars:
+    obj_name: heapster
+    labels:
+      metrics-infra: support
+    secrets: "{{ heapster_sa_secrets }}"
+  changed_when: no
+
+- name: Generate service for heapster
+  template: src=service.j2 dest={{mktemp.stdout}}/templates/metrics-{{obj_name}}-svc.yaml
+  vars:
+    obj_name: heapster
+    ports:
+      - {port: 80, targetPort: http-endpoint}
+    selector:
+      name: "{{obj_name}}"
+    labels:
+      metrics-infra: "{{obj_name}}"
+      name: "{{obj_name}}"
+  changed_when: no
+
+- name: generate cluster-reader role binding for the heapster service account
+  template:
+    src: rolebinding.j2
+    dest: "{{ mktemp.stdout }}/templates/heapster-rolebinding.yaml"
+  vars:
+    cluster: True
+    obj_name: heapster-cluster-reader
+    labels:
+      metrics-infra: heapster
+    roleRef:
+      kind: ClusterRole
+      name: cluster-reader
+    subjects:
+      - kind: ServiceAccount
+        name: heapster
+        namespace: "{{ openshift_metrics_project }}"
+  changed_when: no
+
+- include: generate_heapster_certificates.yaml

+ 6 - 10
roles/openshift_metrics/tasks/install_metrics.yaml

@@ -1,14 +1,5 @@
 ---
-- name: Check that hawkular_metrics_hostname is set
-  fail: msg='the openshift_metrics_hawkular_hostname variable is required'
-  when: openshift_metrics_hawkular_hostname is not defined
-
-- name: Check the value of openshift_metrics_cassandra_storage_type
-  fail:
-    msg: >
-      openshift_metrics_cassandra_storage_type ({{ openshift_metrics_cassandra_storage_type }})
-      is invalid, must be one of: emptydir, pv, dynamic
-  when: openshift_metrics_cassandra_storage_type not in openshift_metrics_cassandra_storage_types
+- include: pre_install.yaml
 
 - name: Install Metrics
   include: "{{ role_path }}/tasks/install_{{ include_file }}.yaml"
@@ -19,6 +10,11 @@
     - cassandra
   loop_control:
     loop_var: include_file
+  when: "not {{ openshift_metrics_heapster_standalone | bool }}"
+
+- name: Install Heapster Standalone
+  include: install_heapster.yaml
+  when: "{{ openshift_metrics_heapster_standalone | bool }}"
 
 - find: paths={{ mktemp.stdout }}/templates patterns=*.yaml
   register: object_def_files

+ 27 - 0
roles/openshift_metrics/tasks/pre_install.yaml

@@ -0,0 +1,27 @@
+---
+- name: Check that hawkular_metrics_hostname is set
+  fail: msg='the openshift_metrics_hawkular_hostname variable is required'
+  when: openshift_metrics_hawkular_hostname is not defined
+
+- name: Check the value of openshift_metrics_cassandra_storage_type
+  fail:
+    msg: >
+      openshift_metrics_cassandra_storage_type ({{ openshift_metrics_cassandra_storage_type }})
+      is invalid, must be one of: emptydir, pv, dynamic
+  when:
+  - openshift_metrics_cassandra_storage_type not in openshift_metrics_cassandra_storage_types
+  - "not {{ openshift_metrics_heapster_standalone | bool }}"
+
+- name: create certificate output directory
+  file:
+    path: "{{ openshift_metrics_certs_dir }}"
+    state: directory
+    mode: 0700
+
+- name: list existing secrets
+  command: >
+    {{ openshift.common.client_binary }} -n {{ openshift_metrics_project }}
+    --config={{ mktemp.stdout }}/admin.kubeconfig
+    get secrets -o name
+  register: metrics_secrets
+  changed_when: false

+ 3 - 0
roles/openshift_metrics/tasks/start_metrics.yaml

@@ -19,6 +19,8 @@
   with_items: "{{metrics_cassandra_rc.stdout_lines}}"
   loop_control:
     loop_var: object
+  when: metrics_cassandra_rc is defined
+  changed_when: "{{metrics_cassandra_rc | length > 0 }}"
 
 - command: >
     {{openshift.common.client_binary}}
@@ -40,6 +42,7 @@
   with_items: "{{metrics_metrics_rc.stdout_lines}}"
   loop_control:
     loop_var: object
+  changed_when: "{{metrics_metrics_rc | length > 0 }}"
 
 - command: >
     {{openshift.common.client_binary}}

+ 2 - 0
roles/openshift_metrics/tasks/stop_metrics.yaml

@@ -41,6 +41,7 @@
   with_items: "{{metrics_hawkular_rc.stdout_lines}}"
   loop_control:
     loop_var: object
+  changed_when: "{{metrics_hawkular_rc | length > 0 }}"
 
 - command: >
     {{openshift.common.client_binary}} --config={{mktemp.stdout}}/admin.kubeconfig
@@ -62,3 +63,4 @@
   loop_control:
     loop_var: object
   when: metrics_cassandra_rc is defined
+  changed_when: "{{metrics_cassandra_rc | length > 0 }}"