[platform] Another logic for deleting components (#811)

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Streamlined the internal deployment process by consolidating deletion
operations and simplifying task dependencies.
- **New Features**
- Enhanced release management with updated logic that automatically
determines whether to deploy or remove components based on their enabled
status.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Andrei Kvapil
2025-04-14 17:34:28 +02:00
committed by GitHub
2 changed files with 16 additions and 30 deletions

View File

@@ -7,18 +7,11 @@ show:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS)
apply:
@echo "Applying active HelmReleases..."
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) \
| yq 'select(.metadata.annotations."cozystack.io/marked-for-deletion" != "true")' - \
| kubectl apply -f-
kubectl delete helmreleases.helm.toolkit.fluxcd.io -l cozystack.io/marked-for-deletion=true -A
delete:
@echo "Deleting marked-for-deletion HelmReleases..."
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) \
| yq 'select(.metadata.annotations."cozystack.io/marked-for-deletion" == "true")' - \
| kubectl delete -f - --ignore-not-found=true
reconcile: apply delete
reconcile: apply
namespaces-show:
helm template -n $(NAMESPACE) $(NAME) . --dry-run=server $(API_VERSIONS_FLAGS) -s templates/namespaces.yaml

View File

@@ -11,8 +11,17 @@
{{- end }}
{{- range $x := $bundle.releases }}
{{- if not (has $x.name $disabledComponents) }}
{{- if or (not $x.optional) (and ($x.optional) (has $x.name $enabledComponents)) }}
{{- $shouldInstall := true }}
{{- $shouldDelete := false }}
{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
{{- $shouldInstall = false }}
{{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
{{- $shouldDelete = true }}
{{- end }}
{{- end }}
{{- if or $shouldInstall $shouldDelete }}
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
@@ -22,6 +31,9 @@ metadata:
labels:
cozystack.io/repository: system
cozystack.io/system-app: "true"
{{- if $shouldDelete }}
cozystack.io/marked-for-deletion: "true"
{{- end }}
spec:
interval: 5m
releaseName: {{ $x.releaseName | default $x.name }}
@@ -79,22 +91,3 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- range $name := $disabledComponents }}
{{- if ne $name "" }}
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: {{ $name }}
namespace: {{ index $dependencyNamespaces $name | default "cozy-system" }}
annotations:
cozystack.io/marked-for-deletion: "true"
labels:
cozystack.io/repository: system
cozystack.io/system-app: "true"
spec:
suspend: true
{{- end }}
{{- end }}