Browse Source

role to (re)deploy operators

Grega Bremec 3 days ago
parent
commit
44b7735c49
1 changed files with 140 additions and 0 deletions
  1. 140 0
      playbooks/roles/deploy-operator/tasks/main.yml

+ 140 - 0
playbooks/roles/deploy-operator/tasks/main.yml

@@ -0,0 +1,140 @@
+---
+# Ensures all the operator artifacts are created and waits for CSV to succeed.
+#
+# The following variables must exist:
+#
+#  added_operators:   (list)
+#    - catalog:       the catalog of the manifest
+#      package:       the name of the packagemanifest
+#      channel:       which channel to install from
+#      namespace:     target namespace for subscription
+#      desired_csv:   for verification - wait for this CSV to appear
+#      og_namespaces: (list) operatorgroup namespaces
+#
+# This role must then be applied as:
+#
+#   - include_role:
+#       name: deploy-operators
+#     loop: "{{ added_operators }}"
+#     loop_control:
+#       loop_var: role
+#
+# What this means is that each item of added_operators is expected to be
+# placed in the "role" variable prior to iterating over this role.
+#
+# NOTE: Do NOT test by checking for presence of API resources - they do not always get cleaned up.
+#
+#
+#
+# TODO: Maybe someday fix the JSONPath expression below. And figure out why check for a CSV.
+#- name: Check if the CSV exists already
+#  k8s_info:
+#    kubeconfig: tmp/kubeconfig-ocp4
+#    validate_certs: no
+#    api_version: operators.coreos.com/v1alpha1
+#    kind: clusterserviceversion
+#  register: all_csv
+#
+#- name: Find the wanted CSV among all CSVs
+#  set_fact:
+#    found_csv: "{{ (all_csv | community.general.json_query(\"resources[?metadata.name == \" + role.desired_csv + \"]\")) }}"
+#  when:
+#    - all_csv.resources is defined
+#    - (all_csv.resources | length) > 0
+#
+#- name: Get details about the CSV if found
+#  set_fact:
+#    csv_ns: "{{ found_csv[0] | community.general.json_query('metadata.namespace') }}"
+#    csv_name: "{{ found_csv[0] | community.general.json_query('metadata.name') }}"
+#  when:
+#    - found_csv is defined
+#    - (found_csv | length) > 0
+
+- name: Make sure the namespace is there
+  k8s:
+    kubeconfig: tmp/kubeconfig-ocp4
+    validate_certs: no
+    api_version: v1
+    kind: namespace
+    name: "{{ role.namespace }}"
+
+# TODO: Finish this at some point.
+# TODO: Just apply from role.og_namespaces - finding an OG or just applying a default name.
+#- name: Make sure the namespace has a properly configured OperatorGroup
+#  k8s_info:
+#    kubeconfig: tmp/kubeconfig-ocp4
+#    validate_certs: no
+#    api_version: operators.coreos.com/v1
+#    kind: operatorgroup
+#    namespace: "{{ op_nsp }}"
+#  register: found_opgrp
+
+- name: Also make sure there is a subscription
+  k8s:
+    kubeconfig: tmp/kubeconfig-ocp4
+    validate_certs: no
+    api_version: operators.coreos.com/v1alpha1
+    kind: subscription
+    namespace: "{{ role.namespace }}"
+    name: "{{ role.package }}"
+    definition:
+      spec:
+        source: "{{ role.catalog }}"
+        sourceNamespace: openshift-marketplace
+        name: "{{ role.package }}"
+        channel: "{{ role.channel }}"
+        startingCSV: "{{ role.desired_csv }}"
+        installPlanApproval: Automatic
+
+# TODO: Finish this at some point.
+#- name: Wait for installPlan to show up
+#  k8s_info:
+#    kubeconfig: tmp/kubeconfig-ocp4
+#    validate_certs: no
+#    api_version: operators.coreos.com/v1alpha1
+#    kind: installplan
+#    namespace: "{{ op_nsp }}"
+#  register: installplan
+#  until:
+#    - installplan.resources is defined
+#    - (installplan.resources | length) > 0
+#    - installplan.resources[0].spec.approved
+#  retries: 12
+#  delay: 10
+
+- name: Wait for CSV to show up and complete
+  k8s_info:
+    kubeconfig: tmp/kubeconfig-ocp4
+    validate_certs: no
+    api_version: operators.coreos.com/v1alpha1
+    kind: clusterserviceversion
+    namespace: "{{ role.namespace }}"
+    name: "{{ role.desired_csv }}"
+  register: new_csv
+  until:
+    - new_csv.resources is defined
+    - (new_csv.resources | length) > 0
+    - new_csv.resources[0].status is defined
+    - new_csv.resources[0].status.phase == "Succeeded"
+  retries: 30
+  delay: 10
+
+# TODO: Finish this at some point.
+#- name: Finally, wait for the pod
+#  k8s_info:
+#    kubeconfig: tmp/kubeconfig-ocp4
+#    validate_certs: no
+#    api_version: v1
+#    kind: pod
+#    namespace: rhsso
+#    label_selectors:
+#      - name = rhsso-operator
+#  register: sso_pod
+#  until:
+#    - sso_pod.resources is defined
+#    - (sso_pod.resources | length) > 0
+#    - sso_pod.resources[0].status is defined
+#    - sso_pod.resources[0].status.phase == "Running"
+#  retries: 30
+#  delay: 10
+...