From b2eef5d9d737a64b3853e00bdc7810dc57398f77 Mon Sep 17 00:00:00 2001 From: Pavan Sadhana Date: Tue, 5 Nov 2024 11:11:44 +0530 Subject: [PATCH 1/3] code changes for automation of cmo Signed-off-by: Pavan Sadhana --- examples/all.yaml | 13 +- examples/ocp_cost_management_vars.yaml | 16 ++ playbooks/ocp-cost-management.yml | 7 + playbooks/roles/ocp-cost-management/README.md | 103 +++++++++++++ .../ocp-cost-management/defaults/main.yml | 15 ++ .../ocp-cost-management/files/run-e2e.sh | 16 ++ .../ocp-cost-management/tasks/cmo-cleanup.yml | 141 ++++++++++++++++++ .../ocp-cost-management/tasks/cmo-setup.yml | 59 ++++++++ .../ocp-cost-management/tasks/cmo-test.yml | 111 ++++++++++++++ .../roles/ocp-cost-management/tasks/main.yml | 126 ++++++++++++++++ .../roles/ocp-cost-management/vars/main.yml | 7 + 11 files changed, 613 insertions(+), 1 deletion(-) create mode 100644 examples/ocp_cost_management_vars.yaml create mode 100644 playbooks/ocp-cost-management.yml create mode 100644 playbooks/roles/ocp-cost-management/README.md create mode 100644 playbooks/roles/ocp-cost-management/defaults/main.yml create mode 100644 playbooks/roles/ocp-cost-management/files/run-e2e.sh create mode 100644 playbooks/roles/ocp-cost-management/tasks/cmo-cleanup.yml create mode 100644 playbooks/roles/ocp-cost-management/tasks/cmo-setup.yml create mode 100644 playbooks/roles/ocp-cost-management/tasks/cmo-test.yml create mode 100644 playbooks/roles/ocp-cost-management/tasks/main.yml create mode 100644 playbooks/roles/ocp-cost-management/vars/main.yml diff --git a/examples/all.yaml b/examples/all.yaml index eb23935e..faddf78f 100644 --- a/examples/all.yaml +++ b/examples/all.yaml @@ -382,4 +382,15 @@ coo_namespace: "openshift-observability-operator" coo_catalogsource_name: "coo-catalog" coo_catalogsource_image: "brew.registry.redhat.io/rh-osbs/iib:760399" coo_channel: "development" - \ No newline at end of file + +# ocp-cost_management vars +cost_management_enabled: false +cost_management_directory: "/tmp/compliance" +cost_management_catalogsource_image: "" # "brew.registry.redhat.io/rh-osbs/iib:327237" +cost_management_upgrade_channel: "stable" +cost_management_e2e: false +cost_management_e2e_github_repo: "" +cost_management_e2e_github_branch: "" +cost_management_github_username: "" +cost_management_github_token: "" +cost_management_cleanup: true \ No newline at end of file diff --git a/examples/ocp_cost_management_vars.yaml b/examples/ocp_cost_management_vars.yaml new file mode 100644 index 00000000..3676f641 --- /dev/null +++ b/examples/ocp_cost_management_vars.yaml @@ -0,0 +1,16 @@ +--- +# ocp-cmo vars +cost_management_enabled: false +cost_management_directory: "/tmp/compliance" +cost_management_catalogsource_image: "" # "brew.registry.redhat.io/rh-osbs/iib:327237" +cost_management_upgrade_channel: "stable" +cost_management_e2e: false +cost_management_e2e_github_repo: "" +cost_management_e2e_github_branch: "" +cost_management_github_username: "" +cost_management_github_token: "" +cost_management_cleanup: true +cost_management_setup: false +cost_management_test: false +openshift_console_password: "" + diff --git a/playbooks/ocp-cost-management.yml b/playbooks/ocp-cost-management.yml new file mode 100644 index 00000000..cbdb6547 --- /dev/null +++ b/playbooks/ocp-cost-management.yml @@ -0,0 +1,7 @@ +--- +- name: Installation of the Compliance Operator and run e2e + hosts: bastion + tasks: + - name: Deploy Cost Management Operator + include_role: + name: ocp-cost-management diff --git a/playbooks/roles/ocp-cost-management/README.md b/playbooks/roles/ocp-cost-management/README.md new file mode 100644 index 00000000..bcfef3b7 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/README.md @@ -0,0 +1,103 @@ +ocp-cost-management-operator +========= + +This role is used to deploy Cost Management Operator. + +Requirements +------------ + +- OCP 4.x healthy cluster on PowerVS. +- Need to connect to Sgnvpn and Redhat VPN on your machine. + +Role Variables +-------------- + +| Variable | Required | Default | Comments | +|--------------------------------------------|----------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------| +| cost_management_enabled | yes | false | | +| cost_management_directory | yes | /tmp/compliance | cost management temporary directory | +| cost_management_catalogsource_image | yes | "" | index image build id | +| cost_management_upgrade_channel | no | stable | channel | +| cost_management_e2e | yes | false | | +| cost_management_e2e_github_repo | yes |"" | | +| cost_management_e2e_github_branch | yes |master | | | +| cost_management_github_username | yes |"" | | +| cost_management_github_token | yes |"" | | +| cost_management_cleanup | yes | true | to run cleanup playbook | +| cost_management_setup | yes | false | to run cost management setup | +| cost_management_test | yes | false | to run cost management test | +| openshift_console_password | yes | "" | oc login command password | + + +Dependencies +------------ + +- None + + +Example Playbook +---------------- + +``` + --- +- name: Installation of the cost management operator and run e2e + hosts: bastion + roles: + - ocp-cost-management +``` + +Execution process +----------------- + + there are 4 playbooks available on tasks folder + - main.yml + - cmo-setup.yml + - cmo-test.yml + - cmo-cleanup.yml + +**var filepath:** +examples/ocp_cost_management_vars.yaml + +**main.yml** +This is the main yaml file which is used to install,verify and validate cost managemenent operator. + +**cmo-setup.yml** +This file is responsible for install iqe cost management plugin and dependencies on your machine, +inorder to execute this we have to enable the cost_management_setup in var file. +`cost_management_setup: true` + +**cmo-test.yml** +After plugin installation is successful,we have to execute this file to run tests. +inorder to execute this we have to enable the cost_management_test in var file. +`cost_management_test: true` +Also we have to pass the kubeadmin password to this variable `openshift_console_password` in var file. + +**cmo-cleanup.yml** +This file is use to cleanup all resources involved with this operator. +inorder to execute this we have to enable the cost_management_cleanup in var file. +`cost_management_cleanup: true` + +Run Playbook +------------ + +To set up variables for specific playbook make use of the sample file at examples/. Modify the values as per your cluster. For more information refer to examples. + +``` +cp examples/ocp_cost_management_vars.yaml +``` +Once you have configured the vars & inventory file, run the specific playbook using: + +``` +ansible-playbook -i inventory -e @ocp_cost_management_vars.yaml playbooks/main.yml +``` + + +License +------- + +See LICENCE.txt + +Author Information +------------------ + +Pavan.Sadhana3@ibm.com diff --git a/playbooks/roles/ocp-cost-management/defaults/main.yml b/playbooks/roles/ocp-cost-management/defaults/main.yml new file mode 100644 index 00000000..12b6f592 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/defaults/main.yml @@ -0,0 +1,15 @@ +--- +# defaults file for playbooks/roles/ocp-cost-management +cost_management_enabled: false +cost_management_directory: "/tmp/costmanagement" +cost_management_catalogsource_image: "" # "brew.registry.redhat.io/rh-osbs/iib:327237" +cost_management_upgrade_channel: "stable" +cost_management_e2e: false +cost_management_e2e_github_repo: "" +cost_management_e2e_github_branch: "master" +cost_management_github_username: "" +cost_management_github_token: "" +cost_management_cleanup: true +cost_management_setup: false +cost_management_test: false +openshift_console_password: "" diff --git a/playbooks/roles/ocp-cost-management/files/run-e2e.sh b/playbooks/roles/ocp-cost-management/files/run-e2e.sh new file mode 100644 index 00000000..c8d4145c --- /dev/null +++ b/playbooks/roles/ocp-cost-management/files/run-e2e.sh @@ -0,0 +1,16 @@ +re_run_count=0 +max_re_runs=1 +echo -e "\ne2e summary:" > $COST_MANAGEMENT_WORKDIR/e2e-summary.txt +cat "${COST_MANAGEMENT_WORKDIR}/e2e-output.txt" | tail -n 1 >> $COST_MANAGEMENT_WORKDIR/e2e-summary.txt +sed -e 's/\"/\\"/g;s/.*/\"&\"/' "${COST_MANAGEMENT_WORKDIR}/e2e-output.txt" | awk '/Failing tests:/,EOF' | tail -n +3 | head -n -2 > $COST_MANAGEMENT_WORKDIR/failed_tests.txt +while [ $re_run_count -lt $max_re_runs ] && [ "0" -ne "$(wc -l < "${COST_MANAGEMENT_WORKDIR}/failed_tests.txt")" ] +do + re_run_count=$(( $re_run_count + 1 )) + ./bin/extended-platform-tests run -f $COST_MANAGEMENT_WORKDIR/failed_tests.txt -o $COST_MANAGEMENT_WORKDIR/e2e-re-run-output-${re_run_count}.txt + sed -e 's/\"/\\"/g;s/.*/\"&\"/' "${COST_MANAGEMENT_WORKDIR}/e2e-re-run-output-${re_run_count}.txt" | awk '/Failing tests:/,EOF' | tail -n +3 | head -n -2 > $COST_MANAGEMENT_WORKDIR/failed_tests.txt +done +if [ $re_run_count -ne 0 ]; then + echo -e "\n\ne2e summary after re-running:" >> $COST_MANAGEMENT_WORKDIR/e2e-summary.txt + cat $COST_MANAGEMENT_WORKDIR/failed_tests.txt >> $COST_MANAGEMENT_WORKDIR/e2e-summary.txt + cat "${COST_MANAGEMENT_WORKDIR}/e2e-re-run-output-${re_run_count}.txt" | tail -n 2 >> $COST_MANAGEMENT_WORKDIR/e2e-summary.txt +fi diff --git a/playbooks/roles/ocp-cost-management/tasks/cmo-cleanup.yml b/playbooks/roles/ocp-cost-management/tasks/cmo-cleanup.yml new file mode 100644 index 00000000..645aa582 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/tasks/cmo-cleanup.yml @@ -0,0 +1,141 @@ +--- +# this file is used for cleaning up the compliance operator resources + +- name: Check if ScanSettingBinding exists + shell: oc get ScanSettingBinding -n costmanagement-metrics-operator --no-headers | awk '{print $1}' + register: scan_setting_binding + +- name: Delete the ScanSettingBinding if exists + kubernetes.core.k8s: + api_version: compliance.openshift.io/v1alpha1 + state: absent + kind: ScanSettingBinding + name: "{{ item }}" + namespace: costmanagement-metrics-operator + loop: "{{ scan_setting_binding.stdout_lines }}" + when: scan_setting_binding.stdout_lines|length > 0 + +- name: Check if ScanSetting exists + shell: oc get ScanSetting -n costmanagement-metrics-operator --no-headers | awk '{print $1}' + register: scan_setting + +- name: Delete the ScanSetting if exists + kubernetes.core.k8s: + api_version: compliance.openshift.io/v1alpha1 + state: absent + kind: ScanSetting + name: "{{ item }}" + namespace: costmanagement-metrics-operator + loop: "{{ scan_setting.stdout_lines }}" + when: scan_setting.stdout_lines|length > 0 + +- name: Check if ComplianceSuite exists + shell: oc get ComplianceSuite -n costmanagement-metrics-operator --no-headers | awk '{print $1}' + register: compliance_suite + +- name: Delete the ComplianceSuite if exists + kubernetes.core.k8s: + api_version: compliance.openshift.io/v1alpha1 + state: absent + kind: ComplianceSuite + name: "{{ item }}" + namespace: costmanagement-metrics-operator + loop: "{{ compliance_suite.stdout_lines }}" + when: compliance_suite.stdout_lines|length > 0 + +- name: Get the name of cluster service version for Compliance Operator + shell: oc get csv -n costmanagement-metrics-operator --no-headers | awk '{ if ($1 ~ /^compliance-operator/) print $1 }' + register: compliance_csv + +- name: Delete the profile bundle if exists + kubernetes.core.k8s: + api_version: compliance.openshift.io/v1alpha1 + state: absent + kind: ProfileBundle + name: "{{ item }}" + namespace: costmanagement-metrics-operator + loop: + - "ocp4" + - "rhcos4" + when: compliance_csv.stdout|length > 0 + +- name: Get the subscription name + shell: oc get subscription -n costmanagement-metrics-operator --no-headers | awk '{print $1}' + register: compliance_subscription + +- name: Delete the subscription if exists + kubernetes.core.k8s: + api_version: operators.coreos.com/v1alpha1 + state: absent + kind: Subscription + name: "{{ compliance_subscription.stdout }}" + namespace: costmanagement-metrics-operator + when: compliance_subscription.stdout|length > 0 + +- name: Get the operator group name + shell: oc get operatorgroup -n costmanagement-metrics-operator --no-headers | awk '{print $1}' + register: compliance_operator_group + +- name: Delete the operator group if exists + kubernetes.core.k8s: + api_version: operators.coreos.com/v1 + state: absent + kind: OperatorGroup + name: "{{ compliance_operator_group.stdout }}" + namespace: costmanagement-metrics-operator + when: compliance_operator_group.stdout|length > 0 + +- name: Delete the cluster service version if exists + kubernetes.core.k8s: + api_version: operators.coreos.com/v1alpha1 + state: absent + kind: ClusterServiceVersion + name: "{{ compliance_csv.stdout }}" + namespace: costmanagement-metrics-operator + when: compliance_csv.stdout|length > 0 + +- name: Check if all the pods has been deleted + shell: oc get pods -n costmanagement-metrics-operator --no-headers + register: compliance_pods + until: compliance_pods.stdout|int == 0 + retries: 15 + delay: 60 + +- name: Get custom resource definitions + shell: oc get crd | awk '{print $1}'| grep compliance + register: compliance_crds + ignore_errors: true + +- name: Delete the custom resource definition if exists + shell: oc delete crd {{ item }} + loop: "{{ compliance_crds.stdout_lines }}" + when: compliance_crds.stdout_lines|length > 0 + +- name: Check if all the custom resource definitions has been deleted + shell: oc get crd | awk '{print $1}'| grep compliance + register: compliance_crds + failed_when: compliance_crds.stdout_lines|length != 0 + +- name: Delete the Cost Management Operator if exists + kubernetes.core.k8s: + state: absent + kind: Operator + name: cost-management-operator.costmanagement-metrics-operator + +- name: Delete the namespace if exists + kubernetes.core.k8s: + state: absent + kind: Namespace + name: costmanagement-metrics-operator + +- name: Check if the namespace gets deleted + shell: oc get namespace --no-headers | grep compliance | wc -l + register: compliance_namespace + until: compliance_namespace.stdout|int == 0 + retries: 15 + delay: 30 + +- name: Delete the workplace + file: + state: absent + path: "{{ cost_management_directory }}" diff --git a/playbooks/roles/ocp-cost-management/tasks/cmo-setup.yml b/playbooks/roles/ocp-cost-management/tasks/cmo-setup.yml new file mode 100644 index 00000000..ca71f8c0 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/tasks/cmo-setup.yml @@ -0,0 +1,59 @@ +--- +- name: Setup and Test Cost Management Metrics Operator + tasks: + - name: Create workspace directory + file: + path: "~/iqe-workspace-dev" + state: directory + + - name: Clone IQE Core repository + git: + repo: "git@gitlab.cee.redhat.com:insights-qe/iqe-core.git" + dest: "~/iqe-workspace-dev/iqe-core" + + - name: Create Python virtual environment + command: python3 -m venv .iqe-venv + args: + chdir: "~/iqe-workspace-dev/iqe-core" + + - name: Activate virtual environment and install dependencies + shell: | + source .iqe-venv/bin/activate + pip install -U pip setuptools wheel + args: + chdir: "~/iqe-workspace-dev/iqe-core" + + - name: Set PIP global index URL + shell: | + pip config set global.index-url https://repository.engineering.redhat.com/nexus/repository/insights-qe/simple --site + pip config set global.index https://repository.engineering.redhat.com/nexus/repository/insights-qe-search/pypi --site + args: + chdir: "~/iqe-workspace-dev/iqe-core" + + - name: Install IQE core with constraints + shell: | + source .iqe-venv/bin/activate + pip install -e . -c iqe/data/all_external_constraints.linux.python3.11.txt + args: + chdir: "~/iqe-workspace-dev/iqe-core" + + - name: Create plugin directory + file: + path: "~/iqe-workspace-dev/iqe-cost-management-plugin" + state: directory + + - name: Check if IQE Cost Management Plugin is already cloned + stat: + path: ~/iqe-workspace-dev/iqe-cost-management-plugin/.git + register: git_repo + + - name: Clone IQE Cost Management Plugin with SSL verification disabled + shell: git -c http.sslVerify=false clone https://gitlab.cee.redhat.com/insights-qe/iqe-cost-management-plugin ~/iqe-workspace-dev/iqe-cost-management-plugin + when: not git_repo.stat.exists + + - name: Install IQE Cost Management Plugin + shell: | + source .iqe-venv/bin/activate + iqe plugin install --editable . + args: + chdir: "~/iqe-workspace-dev/iqe-cost-management-plugin" diff --git a/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml b/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml new file mode 100644 index 00000000..ba7a8c08 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml @@ -0,0 +1,111 @@ +--- +- name: Setup and Test Cost Management Operator in OpenShift + gather_facts: no + tasks: + - name: Log in to OpenShift + ansible.builtin.shell: > + oc login -u kubeadmin -p {{ openshift_console_password }} + environment: + KUBECONFIG: "/root/openstack-upi/auth/kubeconfig" + become: yes + + - name: Patch OperatorHub to disable default sources + ansible.builtin.command: + cmd: > + oc patch operatorhub.config.openshift.io/cluster + -p='{"spec":{"disableAllDefaultSources":true}}' + --type=merge + become: yes + + - name: Apply ImageContentSourcePolicy + ansible.builtin.k8s: + state: present + definition: + apiVersion: operator.openshift.io/v1alpha1 + kind: ImageContentSourcePolicy + metadata: + name: brew-registry + spec: + repositoryDigestMirrors: + - mirrors: + - brew.registry.redhat.io + source: registry.redhat.io + - mirrors: + - brew.registry.redhat.io + source: registry.stage.redhat.io + - mirrors: + - brew.registry.redhat.io + source: registry-proxy.engineering.redhat.com + + - name: Create custom CatalogSource for Cost Management + ansible.builtin.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: CatalogSource + metadata: + name: my-operator-catalog + namespace: openshift-marketplace + spec: + sourceType: grpc + publisher: grpc + displayName: my-operator-catalog + image: brew.registry.redhat.io/rh-osbs/iib:{{ cost_management_catalogsource_image}} + + - name: Modify install_cost_operator method in cluster.py + ansible.builtin.replace: + path: "~/iqe-workspace-dev2/iqe-cost-management-plugin/operator_api/cluster.py" + regexp: '("source": "redhat-operators",)' + replace: '"source": "my-operator-catalog",' + + - name: Run IQE basic test for Cost Management + ansible.builtin.shell: > + iqe tests plugin cost_management -k "test_basic.py" -m cost_operator + args: + chdir: "~/iqe-workspace-dev2/iqe-cost-management-plugin/iqe_cost_management/tests/operator" + environment: + ENV_FOR_DYNACONF: prod + register: iqe_test_output + + - name: Show basic test results + ansible.builtin.debug: + msg: "{{ iqe_test_output.stdout }}" + + - name: Run IQE default config test + ansible.builtin.shell: > + iqe tests plugin cost_management -k "test_default_config.py" -m cost_operator + args: + chdir: "~/iqe-workspace-dev2/iqe-cost-management-plugin/iqe_cost_management/tests/operator" + environment: + ENV_FOR_DYNACONF: prod + register: iqe_test_default_config_output + + - name: Show default config test results + ansible.builtin.debug: + msg: "{{ iqe_test_default_config_output.stdout }}" + + - name: Run IQE interop test + ansible.builtin.shell: > + iqe tests plugin cost_management -k "test_interop.py" -m cost_interop + args: + chdir: "~/iqe-workspace-dev2/iqe-cost-management-plugin/iqe_cost_management/tests/operator" + environment: + ENV_FOR_DYNACONF: prod + register: iqe_test_interop_output + + - name: Show interop test results + ansible.builtin.debug: + msg: "{{ iqe_test_interop_output.stdout }}" + + - name: Run IQE operator test + ansible.builtin.shell: > + iqe tests plugin cost_management -k "test_operator.py" -m manual + args: + chdir: "~/iqe-workspace-dev2/iqe-cost-management-plugin/iqe_cost_management/tests/operator" + environment: + ENV_FOR_DYNACONF: prod + register: iqe_test_operator_output + + - name: Show operator test results + ansible.builtin.debug: + msg: "{{ iqe_test_operator_output.stdout }}" diff --git a/playbooks/roles/ocp-cost-management/tasks/main.yml b/playbooks/roles/ocp-cost-management/tasks/main.yml new file mode 100644 index 00000000..cf6f0bc8 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/tasks/main.yml @@ -0,0 +1,126 @@ +--- +# tasks file for playbooks/roles/ocp-cost-management + +- name: Check if cluster operators and nodes are healthy + include_role: + name: check-cluster-health + +- name: Clean up + include_tasks: "{{ role_path }}/tasks/cmo-cleanup.yml" + when: cost_management_cleanup + +- name: cost management operator setup + include_tasks: "{{ role_path }}/tasks/cmo-setup.yml" + when: cost_management_setup + +- name: cost management operator test + include_tasks: "{{ role_path }}/tasks/cmo-test.yml" + when: cost_management_test + +- name: Create working directory + file: + state: "directory" + path: "{{ cost_management_directory }}" + +- name: Setup custom catalog source + block: + - name: Include the global-secret-update role + include_role: + name: global-secret-update + + - name: Set fact variable for CatalogSource name + set_fact: + cost_management_catalogsource: "qe-app-registry" + + - name: Include role to create ImageContentSourcePolicy and CatalogSource + include_role: + name: set-custom-catalogsource + vars: + custom_catalogsource_name: "{{ cost_management_catalogsource }}" + custom_catalogsource_display_name: "Cost Management Operator" + custom_catalogsource_image: "{{ cost_management_catalogsource_image }}" + when: cost_management_catalogsource_image != '' and cost_management_catalogsource_image != None + +- name: Search for the StorageClass + kubernetes.core.k8s_info: + kind: StorageClass + register: storage_class + +- name: Check for default StorageClass annotations + set_fact: + default_storage_class: "{{ storage_class.resources[0].metadata.annotations }}" + when: + - storage_class.resources|length != 0 and storage_class.resources[0].metadata.annotations is defined + - "'storageclass.kubernetes.io/is-default-class' in storage_class.resources[0].metadata.annotations" + +- name: Fail if default StorageClass does not exist + fail: + msg: 'Default StorageClass does not exist' + when: > + (default_storage_class is undefined) or + (default_storage_class is defined and not default_storage_class["storageclass.kubernetes.io/is-default-class"]|bool) + +- name: Deploy Cost Management Operator + block: + - name: Create namespace for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + labels: + pod-security.kubernetes.io/audit: privileged + pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/warn: privileged + security.openshift.io/scc.podSecurityLabelSync: "false" + name: costmanagement-metrics-operator + spec: + targetNamespaces: + - costmanagement-metrics-operator + + - name: Create operator group for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1 + kind: OperatorGroup + metadata: + name: costmanagement-metrics-operator + namespace: costmanagement-metrics-operator + spec: + targetNamespaces: + - costmanagement-metrics-operator + + - name: Create subscription for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + name: cost-management-operator + namespace: costmanagement-metrics-operator + spec: + channel: "{{ cost_management_upgrade_channel }}" + installPlanApproval: Automatic + name: costmanagement-metrics-operator + source: "{{ cost_management_catalogsource }}" + sourceNamespace: openshift-marketplace + + - name: Verification of operator installation + block: + - name: Check if the cluster service version has succeeded + shell: oc get csv -n costmanagement-metrics-operator --no-headers | awk '{ if (($1 ~ /^costmanagement-metrics-operator/) && $NF=="Succeeded") print $1 }'| wc -l + register: cost_management_operators_csv + until: cost_management_operators_csv.stdout|int == 1 + retries: 15 + delay: 120 + + - name: Check if pods are running + shell: oc get pods -n costmanagement-metrics-operator --no-headers | grep "Running" | wc -l + register: cost_management_pods + until: cost_management_pods.stdout|int == 1 + retries: 15 + delay: 60 + diff --git a/playbooks/roles/ocp-cost-management/vars/main.yml b/playbooks/roles/ocp-cost-management/vars/main.yml new file mode 100644 index 00000000..d0187d32 --- /dev/null +++ b/playbooks/roles/ocp-cost-management/vars/main.yml @@ -0,0 +1,7 @@ +--- +# vars file for playbooks/roles/ocp-cmo + +cost_management_e2e_env: + PATH: "/usr/local/go/bin:{{ ansible_env.PATH }}" + KUBECONFIG: "{{ ansible_env.HOME }}/.kube/config" + COST_MANAGEMENT_WORKDIR: "{{ cost_management_directory }}" From ff6622f97210b54cdce747a4de2990e4bed27944 Mon Sep 17 00:00:00 2001 From: Pavan Sadhana Date: Mon, 4 Nov 2024 13:37:45 +0530 Subject: [PATCH 2/3] modified code on cmo-test and main file --- .../ocp-cost-management/tasks/cmo-test.yml | 41 +----- .../roles/ocp-cost-management/tasks/main.yml | 123 +++++++++--------- 2 files changed, 66 insertions(+), 98 deletions(-) diff --git a/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml b/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml index ba7a8c08..889a219b 100644 --- a/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml +++ b/playbooks/roles/ocp-cost-management/tasks/cmo-test.yml @@ -17,40 +17,13 @@ --type=merge become: yes - - name: Apply ImageContentSourcePolicy - ansible.builtin.k8s: - state: present - definition: - apiVersion: operator.openshift.io/v1alpha1 - kind: ImageContentSourcePolicy - metadata: - name: brew-registry - spec: - repositoryDigestMirrors: - - mirrors: - - brew.registry.redhat.io - source: registry.redhat.io - - mirrors: - - brew.registry.redhat.io - source: registry.stage.redhat.io - - mirrors: - - brew.registry.redhat.io - source: registry-proxy.engineering.redhat.com - - - name: Create custom CatalogSource for Cost Management - ansible.builtin.k8s: - state: present - definition: - apiVersion: operators.coreos.com/v1alpha1 - kind: CatalogSource - metadata: - name: my-operator-catalog - namespace: openshift-marketplace - spec: - sourceType: grpc - publisher: grpc - displayName: my-operator-catalog - image: brew.registry.redhat.io/rh-osbs/iib:{{ cost_management_catalogsource_image}} + - name: Set up custom ImageContentSourcePolicy and CatalogSource + include_role: + name: set-custom-catalogsource + vars: + custom_catalogsource_name: "my-operator-catalog" + custom_catalogsource_display_name: "my-operator-catalog" + custom_catalogsource_image: "brew.registry.redhat.io/rh-osbs/iib:{{ cost_management_catalogsource_image }}" - name: Modify install_cost_operator method in cluster.py ansible.builtin.replace: diff --git a/playbooks/roles/ocp-cost-management/tasks/main.yml b/playbooks/roles/ocp-cost-management/tasks/main.yml index cf6f0bc8..1a61e2f8 100644 --- a/playbooks/roles/ocp-cost-management/tasks/main.yml +++ b/playbooks/roles/ocp-cost-management/tasks/main.yml @@ -60,67 +60,62 @@ (default_storage_class is undefined) or (default_storage_class is defined and not default_storage_class["storageclass.kubernetes.io/is-default-class"]|bool) -- name: Deploy Cost Management Operator - block: - - name: Create namespace for Cost Management Operator - kubernetes.core.k8s: - state: present - definition: - apiVersion: v1 - kind: Namespace - metadata: - labels: - pod-security.kubernetes.io/audit: privileged - pod-security.kubernetes.io/enforce: privileged - pod-security.kubernetes.io/warn: privileged - security.openshift.io/scc.podSecurityLabelSync: "false" - name: costmanagement-metrics-operator - spec: - targetNamespaces: - - costmanagement-metrics-operator - - - name: Create operator group for Cost Management Operator - kubernetes.core.k8s: - state: present - definition: - apiVersion: operators.coreos.com/v1 - kind: OperatorGroup - metadata: - name: costmanagement-metrics-operator - namespace: costmanagement-metrics-operator - spec: - targetNamespaces: - - costmanagement-metrics-operator - - - name: Create subscription for Cost Management Operator - kubernetes.core.k8s: - state: present - definition: - apiVersion: operators.coreos.com/v1alpha1 - kind: Subscription - metadata: - name: cost-management-operator - namespace: costmanagement-metrics-operator - spec: - channel: "{{ cost_management_upgrade_channel }}" - installPlanApproval: Automatic - name: costmanagement-metrics-operator - source: "{{ cost_management_catalogsource }}" - sourceNamespace: openshift-marketplace - - - name: Verification of operator installation - block: - - name: Check if the cluster service version has succeeded - shell: oc get csv -n costmanagement-metrics-operator --no-headers | awk '{ if (($1 ~ /^costmanagement-metrics-operator/) && $NF=="Succeeded") print $1 }'| wc -l - register: cost_management_operators_csv - until: cost_management_operators_csv.stdout|int == 1 - retries: 15 - delay: 120 - - - name: Check if pods are running - shell: oc get pods -n costmanagement-metrics-operator --no-headers | grep "Running" | wc -l - register: cost_management_pods - until: cost_management_pods.stdout|int == 1 - retries: 15 - delay: 60 - +- name: Create namespace for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + labels: + pod-security.kubernetes.io/audit: privileged + pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/warn: privileged + security.openshift.io/scc.podSecurityLabelSync: "false" + name: costmanagement-metrics-operator + spec: + targetNamespaces: + - costmanagement-metrics-operator + +- name: Create operator group for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1 + kind: OperatorGroup + metadata: + name: costmanagement-metrics-operator + namespace: costmanagement-metrics-operator + spec: + targetNamespaces: + - costmanagement-metrics-operator + +- name: Create subscription for Cost Management Operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + name: cost-management-operator + namespace: costmanagement-metrics-operator + spec: + channel: "{{ cost_management_upgrade_channel }}" + installPlanApproval: Automatic + name: costmanagement-metrics-operator + source: "{{ cost_management_catalogsource }}" + sourceNamespace: openshift-marketplace + +- name: Check if the cluster service version has succeeded + shell: oc get csv -n costmanagement-metrics-operator --no-headers | awk '{ if (($1 ~ /^costmanagement-metrics-operator/) && $NF=="Succeeded") print $1 }' | wc -l + register: cost_management_operators_csv + until: cost_management_operators_csv.stdout | int == 1 + retries: 15 + delay: 120 + +- name: Check if pods are running + shell: oc get pods -n costmanagement-metrics-operator --no-headers | grep "Running" | wc -l + register: cost_management_pods + until: cost_management_pods.stdout | int == 1 + retries: 15 + delay: 60 \ No newline at end of file From 728134436b20a50bae1e3b872c103bbf5c0465d5 Mon Sep 17 00:00:00 2001 From: Pavan Sadhana Date: Tue, 12 Nov 2024 09:03:26 +0530 Subject: [PATCH 3/3] added new line --- playbooks/roles/ocp-cost-management/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/roles/ocp-cost-management/tasks/main.yml b/playbooks/roles/ocp-cost-management/tasks/main.yml index 1a61e2f8..dea352a4 100644 --- a/playbooks/roles/ocp-cost-management/tasks/main.yml +++ b/playbooks/roles/ocp-cost-management/tasks/main.yml @@ -118,4 +118,4 @@ register: cost_management_pods until: cost_management_pods.stdout | int == 1 retries: 15 - delay: 60 \ No newline at end of file + delay: 60