From ec4a99cce64fd66205ef445e1418e3b389d036c6 Mon Sep 17 00:00:00 2001
From: Adam Buran <aburan28@gmail.com>
Date: Thu, 21 Nov 2024 09:30:03 -0800
Subject: [PATCH] add crd resource keep

Signed-off-by: Adam Buran <aburan28@gmail.com>
---
 helm/aws-load-balancer-controller/crds/crds.yaml | 14 ++++++++++++++
 helm/aws-load-balancer-controller/values.yaml    |  9 +++++++++
 2 files changed, 23 insertions(+)

diff --git a/helm/aws-load-balancer-controller/crds/crds.yaml b/helm/aws-load-balancer-controller/crds/crds.yaml
index 048d51e84..52fbcf18c 100644
--- a/helm/aws-load-balancer-controller/crds/crds.yaml
+++ b/helm/aws-load-balancer-controller/crds/crds.yaml
@@ -1,8 +1,15 @@
+{{- if .Values.crds.install }}
 apiVersion: apiextensions.k8s.io/v1
 kind: CustomResourceDefinition
 metadata:
   annotations:
     controller-gen.kubebuilder.io/version: v0.14.0
+    {{- if .Values.crds.keep }}
+    "helm.sh/resource-policy": keep
+    {{- end }}
+    {{- with .Values.crds.annotations }}
+    {{- toYaml . | nindent 4 }}
+    {{- end }}
   name: ingressclassparams.elbv2.k8s.aws
 spec:
   group: elbv2.k8s.aws
@@ -244,6 +251,12 @@ kind: CustomResourceDefinition
 metadata:
   annotations:
     controller-gen.kubebuilder.io/version: v0.14.0
+    {{- if .Values.crds.keep }}
+    "helm.sh/resource-policy": keep
+    {{- end }}
+    {{- with .Values.crds.annotations }}
+    {{- toYaml . | nindent 4 }}
+    {{- end }}
   name: targetgroupbindings.elbv2.k8s.aws
 spec:
   group: elbv2.k8s.aws
@@ -657,3 +670,4 @@ spec:
     storage: true
     subresources:
       status: {}
+{{- end }}
\ No newline at end of file
diff --git a/helm/aws-load-balancer-controller/values.yaml b/helm/aws-load-balancer-controller/values.yaml
index a33542b8b..389e0a858 100644
--- a/helm/aws-load-balancer-controller/values.yaml
+++ b/helm/aws-load-balancer-controller/values.yaml
@@ -430,3 +430,12 @@ loadBalancerClass:
 
 # creator will disable helm default labels, so you can only add yours
 # creator: "me"
+
+# custom resource definitions configuration
+crds:
+  # retain CRDs upon chart uninstall
+  keep: true
+  # install CRDs 
+  install: true
+  # pass in annotations to CRDs
+  annotations: {}
\ No newline at end of file