main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ---
  2. # Ensures all the operator artifacts are created and waits for CSV to succeed.
  3. #
  4. # The following variables must exist:
  5. #
  6. # desired_csv
  7. # op_nsp
  8. # op_cat
  9. # op_pkg
  10. # op_chn
  11. #
  12. # NOTE: Do NOT test by checking for presence of API resources - they do not always get cleaned up.
  13. #
  14. - name: Check if the CSV exists already
  15. k8s_info:
  16. kubeconfig: tmp/kubeconfig-ocp4
  17. validate_certs: no
  18. api_version: operators.coreos.com/v1alpha1
  19. kind: clusterserviceversion
  20. register: all_csv
  21. - name: Find the wanted CSV among all CSVs
  22. set_fact:
  23. found_csv: "{{ (all_csv | community.general.json_query(\"resources[?metadata.name == \" + desired_csv + \"]\")) }}"
  24. when:
  25. - all_csv.resources is defined
  26. - (all_csv.resources | length) > 0
  27. - name: Get details about the CSV if found
  28. set_fact:
  29. csv_ns: "{{ found_csv[0] | community.general.json_query('metadata.namespace') }}"
  30. csv_name: "{{ found_csv[0] | community.general.json_query('metadata.name') }}"
  31. when:
  32. - found_csv is defined
  33. - (found_csv | length) > 0
  34. - name: Make sure the namespace is there
  35. k8s:
  36. kubeconfig: tmp/kubeconfig-ocp4
  37. validate_certs: no
  38. api_version: v1
  39. kind: namespace
  40. name: "{{ op_nsp }}"
  41. # TODO: Finish this at some point.
  42. #- name: Make sure it has a properly configured OperatorGroup
  43. # k8s_info:
  44. # kubeconfig: tmp/kubeconfig-ocp4
  45. # validate_certs: no
  46. # api_version: operators.coreos.com/v1
  47. # kind: operatorgroup
  48. # namespace: "{{ op_nsp }}"
  49. # register: found_opgrp
  50. - name: Also make sure there is a subscription
  51. k8s:
  52. kubeconfig: tmp/kubeconfig-ocp4
  53. validate_certs: no
  54. api_version: operators.coreos.com/v1alpha1
  55. kind: subscription
  56. namespace: "{{ op_nsp }}"
  57. name: "{{ op_pkg }}"
  58. definition:
  59. spec:
  60. source: "{{ op_cat }}"
  61. sourceNamespace: openshift-marketplace
  62. name: "{{ op_pkg }}"
  63. channel: "{{ op_chn }}"
  64. installPlanApproval: Automatic
  65. # TODO: Finish this at some point.
  66. #- name: Wait for installPlan to show up
  67. # k8s_info:
  68. # kubeconfig: tmp/kubeconfig-ocp4
  69. # validate_certs: no
  70. # api_version: operators.coreos.com/v1alpha1
  71. # kind: installplan
  72. # namespace: "{{ op_nsp }}"
  73. # register: installplan
  74. # until:
  75. # - installplan.resources is defined
  76. # - (installplan.resources | length) > 0
  77. # - installplan.resources[0].spec.approved
  78. # retries: 12
  79. # delay: 10
  80. - name: Wait for CSV to show up and complete
  81. k8s_info:
  82. kubeconfig: tmp/kubeconfig-ocp4
  83. validate_certs: no
  84. api_version: operators.coreos.com/v1alpha1
  85. kind: clusterserviceversion
  86. namespace: "{{ op_nsp }}"
  87. name: "{{ desired_csv }}"
  88. register: new_csv
  89. until:
  90. - new_csv.resources is defined
  91. - (new_csv.resources | length) > 0
  92. - new_csv.resources[0].status is defined
  93. - new_csv.resources[0].status.phase == "Succeeded"
  94. retries: 30
  95. delay: 10
  96. # TODO: Finish this at some point.
  97. #- name: Finally, wait for the pod
  98. # k8s_info:
  99. # kubeconfig: tmp/kubeconfig-ocp4
  100. # validate_certs: no
  101. # api_version: v1
  102. # kind: pod
  103. # namespace: rhsso
  104. # label_selectors:
  105. # - name = rhsso-operator
  106. # register: sso_pod
  107. # until:
  108. # - sso_pod.resources is defined
  109. # - (sso_pod.resources | length) > 0
  110. # - sso_pod.resources[0].status is defined
  111. # - sso_pod.resources[0].status.phase == "Running"
  112. # retries: 30
  113. # delay: 10
  114. ...