Skip to content

Commit 372a248

Browse files
committed
Updated client information for migration utils
Signed-off-by: Christian Hernandez <christian@chernand.io>
1 parent 83f6d36 commit 372a248

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

cmd/scan.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ displays the results.
160160

161161
// Add all Helm Releases to the table
162162
for _, hr := range helmReleaseList.Items {
163-
// TESTING SUSPEND
164-
////hr.Spec.Suspend = true
165-
////k.Update(ctx, &hr)
166-
//
167163
t.AppendRow(table.Row{hr.Kind, hr.Name, hr.Namespace, hr.Status.Conditions[0].Message})
168164
}
169165

pkg/utils/utils.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"strconv"
66
"strings"
7+
"time"
78

89
"github.com/christianh814/mta/pkg/argo"
910
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
@@ -21,19 +22,19 @@ import (
2122
)
2223

2324
// MigrateKustomizationToApplicationSet migrates a Kustomization to an Argo CD ApplicationSet
24-
func MigrateKustomizationToApplicationSet(client client.Client, ctx context.Context, ans string, k kustomizev1.Kustomization) error {
25+
func MigrateKustomizationToApplicationSet(c client.Client, ctx context.Context, ans string, k kustomizev1.Kustomization) error {
2526
// Get the GitRepository from the Kustomization
2627
// get the gitsource
2728
gitSource := &sourcev1.GitRepository{}
28-
err := client.Get(ctx, types.NamespacedName{Namespace: k.Namespace, Name: k.Name}, gitSource)
29+
err := c.Get(ctx, types.NamespacedName{Namespace: k.Namespace, Name: k.Name}, gitSource)
2930
if err != nil {
3031
return err
3132
}
3233

3334
//Get the secret holding the info we need
3435
//secret, err := _.CoreV1().Secrets(k.Namespace).Get(ctx, gitSource.Spec.SecretRef.Name, v1.GetOptions{})
3536
secret := &apiv1.Secret{}
36-
err = client.Get(ctx, types.NamespacedName{Namespace: k.Namespace, Name: gitSource.Spec.SecretRef.Name}, secret)
37+
err = c.Get(ctx, types.NamespacedName{Namespace: k.Namespace, Name: gitSource.Spec.SecretRef.Name}, secret)
3738
if err != nil {
3839
return err
3940
}
@@ -78,13 +79,12 @@ func MigrateKustomizationToApplicationSet(client client.Client, ctx context.Cont
7879
// Generate the ApplicationSet Secret and set the GVK
7980
appsetSecret := GenK8SSecret(applicationSet)
8081

81-
// Create the Application on the cluster
8282
// Suspend reconcilation
8383
k.Spec.Suspend = true
84-
client.Update(ctx, &k)
84+
c.Update(ctx, &k)
8585

8686
// Finally, create the Argo CD Application
87-
if err := CreateK8SObjects(client, ctx, appsetSecret, appset); err != nil {
87+
if err := CreateK8SObjects(c, ctx, appsetSecret, appset); err != nil {
8888
return err
8989
}
9090

@@ -93,10 +93,10 @@ func MigrateKustomizationToApplicationSet(client client.Client, ctx context.Cont
9393
}
9494

9595
// MigrateHelmReleaseToApplication migrates a HelmRelease to an Argo CD Application
96-
func MigrateHelmReleaseToApplication(client client.Client, ctx context.Context, ans string, h helmv2.HelmRelease) error {
96+
func MigrateHelmReleaseToApplication(c client.Client, ctx context.Context, ans string, h helmv2.HelmRelease) error {
9797
// Get the helmchart based on type, report if error
9898
helmRepo := &sourcev1.HelmRepository{}
99-
err := client.Get(ctx, types.NamespacedName{Namespace: h.Namespace, Name: h.Spec.Chart.Spec.SourceRef.Name}, helmRepo)
99+
err := c.Get(ctx, types.NamespacedName{Namespace: h.Namespace, Name: h.Spec.Chart.Spec.SourceRef.Name}, helmRepo)
100100
if err != nil {
101101
return err
102102
}
@@ -125,13 +125,12 @@ func MigrateHelmReleaseToApplication(client client.Client, ctx context.Context,
125125
return err
126126
}
127127

128-
// Create the Application on the cluster
129128
// Suspend reconcilation
130129
h.Spec.Suspend = true
131-
client.Update(ctx, &h)
130+
c.Update(ctx, &h)
132131

133132
// Finally, create the Argo CD Application
134-
if err := CreateK8SObjects(client, ctx, helmArgoCdApp); err != nil {
133+
if err := CreateK8SObjects(c, ctx, helmArgoCdApp); err != nil {
135134
return err
136135
}
137136

@@ -141,6 +140,10 @@ func MigrateHelmReleaseToApplication(client client.Client, ctx context.Context,
141140

142141
// FluxCleanUp cleans up flux resources
143142
func FluxCleanUp(k client.Client, ctx context.Context, log log.Logger, ns string) error {
143+
// Set up the context with timeout
144+
cwt, cancel := context.WithTimeout(ctx, 5*time.Minute)
145+
defer cancel()
146+
144147
//Set up the flux uninstall options
145148
// TODO: Maybe make these configurable
146149
uninstallFlags := struct {
@@ -154,22 +157,22 @@ func FluxCleanUp(k client.Client, ctx context.Context, log log.Logger, ns string
154157
}
155158

156159
// Uninstall the components
157-
if err := fluxuninstall.Components(ctx, log, k, ns, uninstallFlags.dryRun); err != nil {
160+
if err := fluxuninstall.Components(cwt, log, k, ns, uninstallFlags.dryRun); err != nil {
158161
return err
159162
}
160163

161164
// Uninstall the finalizers
162-
if err := fluxuninstall.Finalizers(ctx, log, k, uninstallFlags.dryRun); err != nil {
165+
if err := fluxuninstall.Finalizers(cwt, log, k, uninstallFlags.dryRun); err != nil {
163166
return err
164167
}
165168

166169
// Uninstall CRDS
167-
if err := fluxuninstall.CustomResourceDefinitions(ctx, log, k, uninstallFlags.dryRun); err != nil {
170+
if err := fluxuninstall.CustomResourceDefinitions(cwt, log, k, uninstallFlags.dryRun); err != nil {
168171
return err
169172
}
170173

171174
// Uninstall the namespace
172-
if err := fluxuninstall.Namespace(ctx, log, k, ns, uninstallFlags.dryRun); err != nil {
175+
if err := fluxuninstall.Namespace(cwt, log, k, ns, uninstallFlags.dryRun); err != nil {
173176
return err
174177
}
175178

0 commit comments

Comments
 (0)