diff --git a/Makefile b/Makefile index 6724bd04c..7b46d74b2 100644 --- a/Makefile +++ b/Makefile @@ -361,6 +361,10 @@ endif .PHONY: init-e2e-env init-e2e-env: install-kuttl-plugin install-stern-plugin kustomize ## Download necessary tools to run the integration tests +.PHONY: cleanup-e2e-env +cleanup-e2e-env: ## remove leftover e2e resouces due to test failure. + scripts/cleanup-e2e-env.sh + .PHONY: run-int-tests run-int-tests: init-e2e-env vdb-gen setup-e2e-communal ## Run the integration tests ifeq ($(DEPLOY_WITH), $(filter $(DEPLOY_WITH), olm)) @@ -696,6 +700,10 @@ deploy-prometheus-adapter: ## Setup prometheus adapter for VerticaAutoscaler undeploy-prometheus-adapter: ## Remove prometheus adapter helm uninstall $(PROMETHEUS_ADAPTER_NAME) -n $(PROMETHEUS_ADAPTER_NAMESPACE) +.PHONY: cleanup-prometheus-leftover +cleanup-prometheus-leftover: ## remove leftover Prometheus resouces due to e2e test failure. + scripts/cleanup-prometheus.sh PROMETHEUS_NAMESPACE + .PHONY: undeploy-operator undeploy-operator: ## Undeploy operator that was previously deployed scripts/undeploy.sh $(if $(filter false,$(ignore-not-found)),,-i) diff --git a/scripts/cleanup-e2e-env.sh b/scripts/cleanup-e2e-env.sh new file mode 100755 index 000000000..34cbfa05f --- /dev/null +++ b/scripts/cleanup-e2e-env.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# (c) Copyright [2021-2024] Open Text. +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A script that will clean up left over resources for local env due to failure of kuttl run. + +set -o errexit +set -o pipefail + +# Fetch leftover kuttl resources and remove the namespace +for ns in $(kubectl get ns | grep kuttl-test | cut -d' ' -f1); do + kubectl delete all --all -n $ns + kubectl delete ns $ns +done diff --git a/scripts/cleanup-prometheus.sh b/scripts/cleanup-prometheus.sh new file mode 100755 index 000000000..c14f9224b --- /dev/null +++ b/scripts/cleanup-prometheus.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# (c) Copyright [2021-2024] Open Text. +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A script that will clean up left over resources of Prometheus. + +NAMESPACE=$1 +kubectl delete clusterrole prometheus-kube-prometheus-operator -n $NAMESPACE +kubectl delete clusterrole prometheus-kube-prometheus-prometheus -n $NAMESPACE +kubectl delete clusterrolebinding prometheus-kube-prometheus-operator -n $NAMESPACE +kubectl delete clusterrolebinding prometheus-kube-prometheus-prometheus -n $NAMESPACE +kubectl delete svc prometheus-kube-prometheus-kube-proxy -n kube-system +kubectl delete svc prometheus-kube-prometheus-kubelet -n kube-system +kubectl delete MutatingWebhookConfiguration prometheus-kube-prometheus-admission -n $NAMESPACE +kubectl delete ValidatingWebhookConfiguration prometheus-kube-prometheus-admission -n $NAMESPACE