main.yaml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ---
  2. - fail:
  3. msg: This role required openshift_master_default_subdomain or openshift_master_metrics_url be set
  4. when: openshift.master.metrics_public_url | default(openshift_master_metrics_public_url | default(openshift.master.default_subdomain | default(openshift_master_default_subdomain | default(none)))) is none
  5. - name: Create temp directory for kubeconfig
  6. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  7. register: mktemp
  8. changed_when: False
  9. - set_fact:
  10. openshift_metrics_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  11. - name: Copy the admin client config(s)
  12. command: >
  13. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ openshift_metrics_kubeconfig }}
  14. changed_when: False
  15. - name: Set hosted metrics facts
  16. openshift_facts:
  17. role: hosted
  18. openshift_env: "{{ hostvars
  19. | oo_merge_hostvars(vars, inventory_hostname)
  20. | oo_openshift_env }}"
  21. openshift_env_structures:
  22. - 'openshift.hosted.metrics.*'
  23. - set_fact:
  24. # Prefer the master facts over bare variables if present, prefer
  25. # metrics_public_url over creating a default using default_subdomain
  26. metrics_hostname: "{{ openshift.hosted.metrics.public_url
  27. | default('hawkular-metrics.' ~ (openshift.master.default_subdomain
  28. | default(openshift_master_default_subdomain )))
  29. | oo_hostname_from_url }}"
  30. metrics_persistence: "{{ openshift.hosted.metrics.storage_kind | default(none) is not none }}"
  31. metrics_dynamic_vol: "{{ openshift.hosted.metrics.storage_kind | default(none) == 'dynamic' }}"
  32. metrics_template_dir: "/usr/share/openshift/examples/infrastructure-templates/{{ 'origin' if deployment_type == 'origin' else 'enterprise' }}"
  33. cassandra_nodes: "{{ ',CASSANDRA_NODES=' ~ openshift.hosted.metrics.cassandra_nodes if 'cassandra' in openshift.hosted.metrics else '' }}"
  34. cassandra_pv_size: "{{ ',CASSANDRA_PV_SIZE=' ~ openshift.hosted.metrics.storage_volume_size if openshift.hosted.metrics.storage_volume_size | default(none) is not none else '' }}"
  35. - name: Test if metrics-deployer service account exists
  36. command: >
  37. {{ openshift.common.client_binary }}
  38. --config={{ openshift_metrics_kubeconfig }}
  39. --namespace=openshift-infra
  40. get serviceaccount metrics-deployer -o json
  41. register: serviceaccount
  42. changed_when: false
  43. failed_when: false
  44. - name: Create metrics-deployer Service Account
  45. shell: >
  46. echo {{ metrics_deployer_sa | to_json | quote }} |
  47. {{ openshift.common.client_binary }}
  48. --config={{ openshift_metrics_kubeconfig }}
  49. --namespace openshift-infra
  50. create -f -
  51. when: serviceaccount.rc == 1
  52. - name: Test edit permissions
  53. command: >
  54. {{ openshift.common.client_binary }}
  55. --config={{ openshift_metrics_kubeconfig }}
  56. --namespace openshift-infra
  57. get rolebindings -o jsonpath='{.items[?(@.metadata.name == "edit")].userNames}'
  58. register: edit_rolebindings
  59. changed_when: false
  60. - name: Add edit permission to the openshift-infra project to metrics-deployer SA
  61. command: >
  62. {{ openshift.common.admin_binary }}
  63. --config={{ openshift_metrics_kubeconfig }}
  64. --namespace openshift-infra
  65. policy add-role-to-user edit
  66. system:serviceaccount:openshift-infra:metrics-deployer
  67. when: "'system:serviceaccount:openshift-infra:metrics-deployer' not in edit_rolebindings.stdout"
  68. - name: Test cluster-reader permissions
  69. command: >
  70. {{ openshift.common.client_binary }}
  71. --config={{ openshift_metrics_kubeconfig }}
  72. --namespace openshift-infra
  73. get clusterrolebindings -o jsonpath='{.items[?(@.metadata.name == "cluster-reader")].userNames}'
  74. register: cluster_reader_clusterrolebindings
  75. changed_when: false
  76. - name: Add cluster-reader permission to the openshift-infra project to heapster SA
  77. command: >
  78. {{ openshift.common.admin_binary }}
  79. --config={{ openshift_metrics_kubeconfig }}
  80. --namespace openshift-infra
  81. policy add-cluster-role-to-user cluster-reader
  82. system:serviceaccount:openshift-infra:heapster
  83. when: "'system:serviceaccount:openshift-infra:heapster' not in cluster_reader_clusterrolebindings.stdout"
  84. # TODO: extend this to allow user passed in certs or generating cert with
  85. # OpenShift CA
  86. - name: Create metrics-deployer secret
  87. command: >
  88. {{ openshift.common.client_binary }}
  89. --config={{ openshift_metrics_kubeconfig }}
  90. --namespace openshift-infra
  91. secrets new metrics-deployer nothing=/dev/null
  92. register: metrics_deployer_secret
  93. changed_when: metrics_deployer_secret.rc == 0
  94. failed_when: "metrics_deployer_secret.rc == 1 and 'already exists' not in metrics_deployer_secret.stderr"
  95. - debug: var=openshift.hosted.metrics.deployer_prefix
  96. - debug: var=openshift.hosted.metrics.deployer_version
  97. - name: Deploy Metrics
  98. shell: >
  99. {{ openshift.common.client_binary }} process -f
  100. {{ metrics_template_dir }}/metrics-deployer.yaml -v
  101. HAWKULAR_METRICS_HOSTNAME={{ metrics_hostname }},USE_PERSISTENT_STORAGE={{
  102. metrics_persistence | string | lower }},METRIC_DURATION={{ openshift.hosted.metrics.duration }},METRIC_RESOLUTION={{ openshift.hosted.metrics.resolution }},IMAGE_PREFIX={{ openshift.hosted.metrics.deployer_prefix }},IMAGE_VERSION={{ openshift.hosted.metrics.deployer_version }}
  103. | {{ openshift.common.client_binary }} --namespace openshift-infra
  104. --config={{ openshift_metrics_kubeconfig }}
  105. create -f -
  106. register: deploy_metrics
  107. failed_when: "'already exists' not in deploy_metrics.stderr and deploy_metrics.rc != 0"
  108. changed_when: deploy_metrics.rc == 0
  109. # TODO: re-enable this once the metrics deployer validation issue is fixed
  110. # when using dynamically provisioned volumes
  111. - name: "Wait for image pull and deployer pod"
  112. shell: >
  113. {{ openshift.common.client_binary }}
  114. --namespace openshift-infra
  115. --config={{ openshift_metrics_kubeconfig }}
  116. get pods | grep metrics-deployer.*Completed
  117. register: result
  118. until: result.rc == 0
  119. retries: 60
  120. delay: 10
  121. - name: Delete temp directory
  122. file:
  123. name: "{{ mktemp.stdout }}"
  124. state: absent
  125. changed_when: False