diff --git a/examples/all.yaml b/examples/all.yaml index 54a80126d..09e42de1a 100644 --- a/examples/all.yaml +++ b/examples/all.yaml @@ -28,7 +28,7 @@ ipa_user_last_name: "Star" # IPA user last name to display descheduler_role_enable: false descheduler_operator_deploy: false descheduler_catalogsource_image: "quay.io/openshift-release-dev/ocp-release-nightly:iib-int-index-art-operators-4.12" -descheduler_catalogsource_name: "kube-descheduler-operator-catalog" +descheduler_catalogsource_name: "my-operator-catalog" descheduler_namespace: "openshift-descheduler" descheduler_channel: "4.12" descheduler_e2e_tests_run: false diff --git a/examples/ocp_descheduler_vars.yaml b/examples/ocp_descheduler_vars.yaml index 814f2017e..4b6e5abc0 100644 --- a/examples/ocp_descheduler_vars.yaml +++ b/examples/ocp_descheduler_vars.yaml @@ -6,10 +6,10 @@ descheduler_role_enable: false descheduler_operator_deploy: false descheduler_catalogsource_image: "quay.io/openshift-release-dev/ocp-release-nightly:iib-int-index-art-operators-4.12" descheduler_catalogsource_name: "my-operator-catalog" -descheduler_namespace: "openshift-kube-descheduler-operator" +descheduler_namespace: "openshift-descheduler" descheduler_channel: "4.12" descheduler_e2e_tests_run: false -descheduler_workdir: "/tmp/descheduler" +descheduler_workdir: "/tmp/descheduler" descheduler_e2e_repo: "https://github.com/openshift/openshift-tests-private" descheduler_e2e_github_branch: "master" descheduler_go_tarball: "https://go.dev/dl/go1.18.4.linux-ppc64le.tar.gz" diff --git a/playbooks/roles/ocp-descheduler/README.md b/playbooks/roles/ocp-descheduler/README.md index a4ce2150a..477eae118 100644 --- a/playbooks/roles/ocp-descheduler/README.md +++ b/playbooks/roles/ocp-descheduler/README.md @@ -24,7 +24,7 @@ Role Variables | descheduler_role_enable | no | false | Set the flag `true` to run this playbook. | | descheduler_operator_deploy | no | false | Set the flag `true` to deploy descheduler operator. | | descheduler_catalogsource_image | no | `quay.io/openshift-release-dev/ocp-release-nightly:iib-int-index-art-operators-4.12` | Descheduler operator image index for catalog source, the default has been given for operator version 4.12 ART. | -| descheduler_catalogsource_name | no | kube-descheduler-operator-catalog | Custom catalog source name, if not defined default will be used. | +| descheduler_catalogsource_name | no | my-operator-catalog | Custom catalog source name, if not defined default will be used. | | descheduler_namespace | no | openshift-descheduler | Custom namespace name to create a new namespace, if not defined the default wil be used. | | descheduler_channel | no | 4.12 | Channel version for the descheduler operator. | | descheduler_e2e_tests_run | no | false | Set the flag `true` for running descheduler e2e tests. | diff --git a/playbooks/roles/ocp-descheduler/defaults/main.yaml b/playbooks/roles/ocp-descheduler/defaults/main.yaml index 8a290db97..755e78d63 100644 --- a/playbooks/roles/ocp-descheduler/defaults/main.yaml +++ b/playbooks/roles/ocp-descheduler/defaults/main.yaml @@ -6,10 +6,10 @@ descheduler_role_enable: false descheduler_operator_deploy: false descheduler_catalogsource_image: "quay.io/openshift-release-dev/ocp-release-nightly:iib-int-index-art-operators-4.12" descheduler_catalogsource_name: "my-operator-catalog" -descheduler_namespace: "openshift-kube-descheduler-operator" +descheduler_namespace: "openshift-descheduler" descheduler_channel: "4.12" descheduler_e2e_tests_run: false -descheduler_workdir: "/tmp/descheduler" +descheduler_workdir: "/tmp/descheduler" descheduler_e2e_repo: "https://github.com/openshift/openshift-tests-private" descheduler_e2e_github_branch: "master" descheduler_go_tarball: "https://go.dev/dl/go1.18.4.linux-ppc64le.tar.gz" diff --git a/playbooks/roles/ocp-descheduler/tasks/descheduler-operator-cleanup.yaml b/playbooks/roles/ocp-descheduler/tasks/descheduler-operator-cleanup.yaml new file mode 100644 index 000000000..52d28d256 --- /dev/null +++ b/playbooks/roles/ocp-descheduler/tasks/descheduler-operator-cleanup.yaml @@ -0,0 +1,66 @@ +--- + +## Descheduler operator cleanup + +- name: Check the given namespace is correct + shell: "oc get namespaces | grep {{ operator_namespace }}" + register: namespace_output + ignore_errors: true + +- name: Operator resource cleanup block + block: + - name: Get the Subscriptions in the {{ operator_namespace }} + shell: oc get subscription {{ operator_subscription }} -n {{ operator_namespace }} + register: subscription_output + + - name: Get the ClusterServiceVersion for operator + shell: oc get subscription {{ operator_subscription }} -n {{ operator_namespace }} -o json | jq '.status.currentCSV' + register: operator_csv + when: subscription_output.stdout != "" + + - name: Get the OperatorGroups in {{ operator_namespace }} + shell: oc get operatorgroup {{ operator_group }} -n {{ operator_namespace }} + register: operatorgroup_output + + - name: Delete operator Subscription + kubernetes.core.k8s: + api_version: operators.coreos.com/v1alpha1 + kind: Subscription + name: "{{ operator_subscription }}" + namespace: "{{ operator_namespace }}" + state: absent + when: subscription_output.stdout != "" + + - name: Delete Cluster Service Version + shell: oc delete csv {{ operator_csv.stdout }} -n {{ operator_namespace }} + when: operator_csv.stdout != "" or operator_csv.stdout != None + + - name: Delete OperatorGroup + kubernetes.core.k8s: + api_version: operators.coreos.com/v1 + kind: OperatorGroup + name: "{{ operator_group }}" + namespace: "{{ operator_namespace }}" + state: absent + when: operatorgroup_output.stdout != "" + + - name: Verify the operator cleanup + shell: oc get csv -n {{ operator_namespace }} + register: cleanup_verification_output + + - name: Delete the namespace + kubernetes.core.k8s: + api_version: v1 + kind: Namespace + name: "{{ operator_namespace }}" + state: absent + + - debug: + msg: "Resources cleaned up suceessfully !" + when: cleanup_verification_output.stdout == "" + when: + - operator_namespace != "" + - operator_subscription != "" + - operator_group != "" + - namespace_output.stdout != "" + ignore_errors: true diff --git a/playbooks/roles/ocp-descheduler/tasks/main.yaml b/playbooks/roles/ocp-descheduler/tasks/main.yaml index ee23d903e..b576d4979 100644 --- a/playbooks/roles/ocp-descheduler/tasks/main.yaml +++ b/playbooks/roles/ocp-descheduler/tasks/main.yaml @@ -7,14 +7,6 @@ descheduler_github_access_token: "{{ lookup('ansible.builtin.env', 'GITHUB_ACCESS_TOKEN') }}" descheduler_e2e_dir: "{{ [descheduler_workdir, descheduler_e2e_repo.split('/')[-1]] | join('/') }}" -- fail: - msg: "Please set descheduler_e2e_repo variable with the e2e repo URL." - when: descheduler_e2e_repo == "" or descheduler_e2e_repo == None - -- fail: - msg: "Please set the environment variables GITHUB_USERNAME and GITHUB_ACCESS_TOKEN on your host." - when: descheduler_github_username == "" or descheduler_github_access_token == "" - # Cluster health check - name: Invoke the role check-cluster-health to check cluster status include_role: @@ -23,6 +15,13 @@ # Descheduler operator deployment block - name: Descheduler operator deployment block: + - name: Include operator cleanup task module + include_tasks: "{{ role_path }}/tasks/descheduler-operator-cleanup.yaml" + vars: + operator_namespace: "{{ descheduler_namespace }}" + operator_subscription: "openshift-descheduler-subscription" + operator_group: "openshift-descheduler-operatorgroup" + - name: Setup a catalogsource for installing descheduler operator block: - name: Include the global pull-secret update role to extract podman-secret @@ -36,7 +35,6 @@ custom_catalogsource_name: "{{ descheduler_catalogsource_name }}" custom_catalogsource_display_name: "Descheduler Operator" custom_catalogsource_image: "{{ descheduler_catalogsource_image }}" - when: descheduler_catalogsource_image != '' or descheduler_catalogsource_image == None - name: Create a target namespace kubernetes.core.k8s: @@ -78,28 +76,44 @@ name: cluster-kube-descheduler-operator source: "{{ descheduler_catalogsource_name }}" sourceNamespace: openshift-marketplace - when: descheduler_operator_deploy -- name: Verify the operator installation - block: - - name: Check if the cluster service version has status as Succeeded - shell: "oc get csv --all-namespaces --no-headers | grep clusterkubedescheduleroperator | awk '{ if (($2 ~ /clusterkubedescheduleroperator/) && $NF == \"Succeeded\") print $2 }'| wc -l" - register: descheduler_operators_csv - until: descheduler_operators_csv.stdout|int != 0 - retries: 15 - delay: 60 - - - name: Check if pods are running - shell: "oc get pods --all-namespaces --no-headers | grep descheduler | awk '{ if ($4 == \"Running\") print $2 }' | wc -l" - register: descheduler_pods - until: descheduler_pods.stdout|int != 0 - retries: 15 - delay: 60 + - name: Verify the operator installation + block: + - name: Check if the cluster service version has status as Succeeded + shell: "oc get csv --all-namespaces --no-headers | grep clusterkubedescheduleroperator | awk '{ if (($2 ~ /clusterkubedescheduleroperator/) && $NF == \"Succeeded\") print $2 }'| wc -l" + register: descheduler_operators_csv + until: descheduler_operators_csv.stdout|int != 0 + retries: 15 + delay: 60 + + - name: Check if pods are running + shell: "oc get pods --all-namespaces --no-headers | grep descheduler | awk '{ if ($4 == \"Running\") print $2 }' | wc -l" + register: descheduler_pods + until: descheduler_pods.stdout|int != 0 + retries: 15 + delay: 60 + + when: descheduler_operator_deploy # Descheduler e2e run block - name: Running e2e test suite in openshift-tests-private for descheduler block: - - name: Create a directory for clonning the repo + - fail: + msg: "Please set descheduler_e2e_repo variable with the e2e repo URL." + when: descheduler_e2e_repo == "" or descheduler_e2e_repo == None + + - fail: + msg: "Please set the environment variables GITHUB_USERNAME and GITHUB_ACCESS_TOKEN on your host." + when: descheduler_github_username == "" or descheduler_github_access_token == "" + + - name: Invoke operator cleanup task + include_tasks: "{{ role_path}}/tasks/descheduler-operator-cleanup.yaml" + vars: + operator_namespace: "{{ descheduler_namespace }}" + operator_subscription: "openshift-descheduler-subscription" + operator_group: "openshift-descheduler-operatorgroup" + + - name: Create a directory for cloning the repo file: state: directory path: "{{ descheduler_workdir }}/e2e-test-result/" @@ -136,7 +150,7 @@ regexp: 'opsrcName\:\s*\"[a-zA-Z0-9\-]*\"' replace: "opsrcName: \"{{ descheduler_catalogsource_name }}\"" - - name: Replace the descheduler operator image build with the custom one in the kube_descheduler_operator test module + - name: Replace the operator image build with the user defined image in the test module ansible.builtin.replace: path: "{{ descheduler_e2e_dir }}/test/extended/workloads/kube_descheduler_operator.go" regexp: 'imageInfo\:\s*\"[a-z0-9\.\/\:\-]*\"' @@ -147,7 +161,7 @@ chdir: "{{ descheduler_e2e_dir }}" target: build - - name: Run the kube_descheduler_operator.go module for descheduler e2e tests + - name: Run the e2e test module shell: "./bin/extended-platform-tests run all --dry-run| grep 'descheduler operator\\|Descheduler-Descheduler\\|Descheduler-Validate'| ./bin/extended-platform-tests run --junit-dir=./ -f - -o ../e2e-test-result/descheduler-e2e-test-summary.txt"