@@ -79,15 +79,32 @@ func MigrateKustomizationToApplicationSet(c client.Client, ctx context.Context,
7979 // Generate the ApplicationSet Secret and set the GVK
8080 appsetSecret := GenK8SSecret (applicationSet )
8181
82- // Suspend reconcilation
83- k .Spec .Suspend = true
84- c .Update (ctx , & k )
82+ // Suspend Kustomization reconcilation
83+ if err := SuspendFluxObject (c , ctx , & k ); err != nil {
84+ return err
85+
86+ }
87+
88+ // Suspend git repo reconcilation
89+ if err := SuspendFluxObject (c , ctx , gitSource ); err != nil {
90+ return err
91+ }
8592
8693 // Finally, create the Argo CD Application
8794 if err := CreateK8SObjects (c , ctx , appsetSecret , appset ); err != nil {
8895 return err
8996 }
9097
98+ // Delete the Kustomization
99+ if err := DeleteK8SObjects (c , ctx , & k ); err != nil {
100+ return err
101+ }
102+
103+ // Delete the GitRepository
104+ if err := DeleteK8SObjects (c , ctx , gitSource ); err != nil {
105+ return err
106+ }
107+
91108 // If we're here, it should have gone okay...
92109 return nil
93110}
@@ -125,15 +142,31 @@ func MigrateHelmReleaseToApplication(c client.Client, ctx context.Context, ans s
125142 return err
126143 }
127144
128- // Suspend reconcilation
129- h .Spec .Suspend = true
130- c .Update (ctx , & h )
145+ // Suspend helm reconcilation
146+ if err := SuspendFluxObject (c , ctx , & h ); err != nil {
147+ return err
148+ }
149+
150+ // Suspend helm repo reconcilation
151+ if err := SuspendFluxObject (c , ctx , helmRepo ); err != nil {
152+ return err
153+ }
131154
132155 // Finally, create the Argo CD Application
133156 if err := CreateK8SObjects (c , ctx , helmArgoCdApp ); err != nil {
134157 return err
135158 }
136159
160+ // Delete the HelmRelease
161+ if err := DeleteK8SObjects (c , ctx , & h ); err != nil {
162+ return err
163+ }
164+
165+ // Delete the HelmRepository
166+ if err := DeleteK8SObjects (c , ctx , helmRepo ); err != nil {
167+ return err
168+ }
169+
137170 // If we're here, it should have gone okay...
138171 return nil
139172}
@@ -180,6 +213,19 @@ func FluxCleanUp(k client.Client, ctx context.Context, log log.Logger, ns string
180213 return nil
181214}
182215
216+ // SuspendFluxObject suspends Flux specific objects based on the schema passed in the client.
217+ func SuspendFluxObject (c client.Client , ctx context.Context , obj ... client.Object ) error {
218+ // suspend the objects
219+ for _ , o := range obj {
220+ if err := c .Patch (ctx , o , client .RawPatch (types .MergePatchType , []byte (`{"spec":{"suspend":true}}` ))); err != nil {
221+ return err
222+ }
223+ }
224+
225+ // If we're here, it should have gone okay...
226+ return nil
227+ }
228+
183229// CreateK8SObjects Creates Kubernetes Objects on the Cluster based on the schema passed in the client.
184230func CreateK8SObjects (c client.Client , ctx context.Context , obj ... client.Object ) error {
185231 // Migrate the objects
@@ -193,6 +239,19 @@ func CreateK8SObjects(c client.Client, ctx context.Context, obj ...client.Object
193239 return nil
194240}
195241
242+ // DeleteK8SObjects Deletes Kubernetes Objects on the Cluster based on the schema passed in the client.
243+ func DeleteK8SObjects (c client.Client , ctx context.Context , obj ... client.Object ) error {
244+ // Migrate the objects
245+ for _ , o := range obj {
246+ if err := c .Delete (ctx , o ); err != nil {
247+ return err
248+ }
249+ }
250+
251+ // If we're here, it should have gone okay...
252+ return nil
253+ }
254+
196255// GenK8SSecret generates a kubernetes secret using a clientset
197256func GenK8SSecret (a argo.GitDirApplicationSet ) * apiv1.Secret {
198257 // Some Defaults
0 commit comments