Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement and bug fix in ocp-descheduler role #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/ocp_descheduler_vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion playbooks/roles/ocp-descheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
4 changes: 2 additions & 2 deletions playbooks/roles/ocp-descheduler/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -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 == ""
AdityaHonkalas marked this conversation as resolved.
Show resolved Hide resolved
when:
- operator_namespace != ""
- operator_subscription != ""
- operator_group != ""
- namespace_output.stdout != ""
ignore_errors: true
70 changes: 42 additions & 28 deletions playbooks/roles/ocp-descheduler/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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/"
Expand Down Expand Up @@ -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\.\/\:\-]*\"'
Expand All @@ -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"
Expand Down