Skip to content

Commit 0bbcad9

Browse files
committed
fix: fix helm
Signed-off-by: jishiwen.jsw <[email protected]>
1 parent 5973a9c commit 0bbcad9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tools/make/helm.mk

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NC ?= \033[0m
2323
helm-uninstall helm-status helm-list helm-history helm-rollback helm-test \
2424
helm-package helm-dev helm-prod helm-values helm-manifest \
2525
helm-port-forward-api helm-port-forward-grpc helm-port-forward-metrics \
26-
helm-logs helm-clean helm-setup helm-cleanup help-helm _check-k8s
26+
helm-logs helm-clean helm-setup helm-cleanup helm-reinstall help-helm _check-k8s
2727

2828
helm-lint: ## Lint the Helm chart
2929
helm-lint:
@@ -48,11 +48,12 @@ helm-install: _check-k8s
4848
echo "$(BLUE)[INFO]$(NC) Use 'make helm-upgrade' to upgrade or 'make helm-uninstall' to remove it first"; \
4949
exit 1; \
5050
fi
51+
@echo "$(BLUE)[INFO]$(NC) Ensuring namespace $(HELM_NAMESPACE) exists..."
52+
@kubectl get namespace $(HELM_NAMESPACE) &>/dev/null || kubectl create namespace $(HELM_NAMESPACE)
5153
@helm install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) \
5254
$(if $(HELM_VALUES_FILE),-f $(HELM_VALUES_FILE)) \
5355
$(if $(HELM_SET_VALUES),--set $(HELM_SET_VALUES)) \
5456
--namespace $(HELM_NAMESPACE) \
55-
--create-namespace \
5657
--wait \
5758
--timeout $(HELM_TIMEOUT)
5859
@echo "$(GREEN)[SUCCESS]$(NC) Helm chart installed successfully"
@@ -210,6 +211,34 @@ helm-cleanup:
210211
helm-clean: ## Alias for helm-cleanup
211212
helm-clean: helm-cleanup
212213

214+
helm-reinstall: ## Force reinstall: cleanup and install fresh
215+
helm-reinstall:
216+
@$(LOG_TARGET)
217+
@echo "$(YELLOW)[INFO]$(NC) Force reinstalling Helm release..."
218+
@echo "$(BLUE)[STEP 1/5]$(NC) Uninstalling existing release (if any)..."
219+
@helm uninstall $(HELM_RELEASE_NAME) --namespace $(HELM_NAMESPACE) 2>/dev/null || echo "No existing release found"
220+
@echo "$(BLUE)[STEP 2/5]$(NC) Deleting namespace..."
221+
@kubectl delete namespace $(HELM_NAMESPACE) --ignore-not-found=true --wait=false 2>/dev/null || true
222+
@echo "$(BLUE)[STEP 3/5]$(NC) Waiting for namespace to be fully deleted..."
223+
@timeout=30; \
224+
elapsed=0; \
225+
while kubectl get namespace $(HELM_NAMESPACE) &>/dev/null && [ $$elapsed -lt $$timeout ]; do \
226+
echo " Waiting for namespace $(HELM_NAMESPACE) to terminate... ($$elapsed/$$timeout seconds)"; \
227+
sleep 2; \
228+
elapsed=$$((elapsed + 2)); \
229+
done; \
230+
if kubectl get namespace $(HELM_NAMESPACE) &>/dev/null; then \
231+
echo "$(YELLOW)[WARNING]$(NC) Namespace still exists after $$timeout seconds, forcing cleanup..."; \
232+
kubectl get namespace $(HELM_NAMESPACE) -o json 2>/dev/null | jq '.spec.finalizers = []' | kubectl replace --raw /api/v1/namespaces/$(HELM_NAMESPACE)/finalize -f - 2>/dev/null || true; \
233+
sleep 2; \
234+
fi
235+
@echo "$(GREEN)[✓]$(NC) Namespace deleted successfully"
236+
@echo "$(BLUE)[STEP 4/5]$(NC) Ensuring namespace is gone..."
237+
@sleep 3
238+
@echo "$(BLUE)[STEP 5/5]$(NC) Installing fresh release..."
239+
@$(MAKE) helm-install
240+
@echo "$(GREEN)[SUCCESS]$(NC) Helm release reinstalled successfully!"
241+
213242
# Internal helper target to check if Kubernetes is available
214243
_check-k8s:
215244
@if ! kubectl cluster-info &>/dev/null; then \

0 commit comments

Comments
 (0)