From 9f757e9953581bc962841a465c331521d698cc72 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 17 Oct 2024 19:26:59 +0000 Subject: [PATCH] remove patches Signed-off-by: Austin Abro --- src/pkg/cluster/state.go | 1 - src/pkg/packager/deploy.go | 8 +------- src/pkg/packager/remove.go | 33 ++++++++++----------------------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index bdb5b97985..65494fadd4 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -108,7 +108,6 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO } // Try to create the zarf namespace. - // TODO is the test failing here spinner.Updatef("Creating the Zarf namespace") zarfNamespace := NewZarfManagedNamespace(ZarfNamespaceName) _, err = c.Clientset.CoreV1().Namespaces().Apply(ctx, zarfNamespace, metav1.ApplyOptions{FieldManager: "zarf", Force: true}) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 9e2cf4714c..c4dbb1b61f 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -6,7 +6,6 @@ package packager import ( "context" - "encoding/json" "fmt" "net/url" "os" @@ -23,7 +22,6 @@ import ( corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - ktypes "k8s.io/apimachinery/pkg/types" "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/api/v1alpha1" @@ -478,11 +476,7 @@ func (p *Packager) setupState(ctx context.Context) error { // Try to create the zarf namespace spinner.Updatef("Creating the Zarf namespace") zarfNamespace := cluster.NewZarfManagedNamespace(cluster.ZarfNamespaceName) - b, err := json.Marshal(zarfNamespace) - if err != nil { - return err - } - _, err = p.cluster.Clientset.CoreV1().Namespaces().Patch(ctx, cluster.ZarfNamespaceName, ktypes.ApplyPatchType, b, metav1.PatchOptions{Force: helpers.BoolPtr(true)}) + _, err = p.cluster.Clientset.CoreV1().Namespaces().Apply(ctx, zarfNamespace, metav1.ApplyOptions{Force: true, FieldManager: "zarf"}) if err != nil { return fmt.Errorf("unable to create the Zarf namespace: %w", err) } diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index f631bf92f8..e2d89a083a 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -16,7 +16,7 @@ import ( "helm.sh/helm/v3/pkg/storage/driver" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - ktypes "k8s.io/apimachinery/pkg/types" + v1ac "k8s.io/client-go/applyconfigurations/core/v1" "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" @@ -117,29 +117,16 @@ func (p *Packager) updatePackageSecret(ctx context.Context, deployedPackage type secretName := config.ZarfPackagePrefix + deployedPackage.Name // Save the new secret with the removed components removed from the secret - newPackageSecret := &corev1.Secret{ - TypeMeta: metav1.TypeMeta{ - APIVersion: corev1.SchemeGroupVersion.String(), - Kind: "Secret", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: secretName, - Namespace: cluster.ZarfNamespaceName, - Labels: map[string]string{ - cluster.ZarfManagedByLabel: "zarf", - cluster.ZarfPackageInfoLabel: deployedPackage.Name, - }, - }, - Type: corev1.SecretTypeOpaque, - Data: map[string][]byte{ + newPackageSecret := v1ac.Secret(secretName, cluster.ZarfNamespaceName). + WithLabels(map[string]string{ + cluster.ZarfManagedByLabel: "zarf", + cluster.ZarfPackageInfoLabel: deployedPackage.Name, + }).WithType(corev1.SecretTypeOpaque). + WithData(map[string][]byte{ "data": newPackageSecretData, - }, - } - b, err := json.Marshal(newPackageSecret) - if err != nil { - return err - } - _, err = p.cluster.Clientset.CoreV1().Secrets(newPackageSecret.Namespace).Patch(ctx, newPackageSecret.Name, ktypes.ApplyPatchType, b, metav1.PatchOptions{Force: helpers.BoolPtr(true)}) + }) + + _, err = p.cluster.Clientset.CoreV1().Secrets(*newPackageSecret.Namespace).Apply(ctx, newPackageSecret, metav1.ApplyOptions{Force: true, FieldManager: "zarf"}) // We warn and ignore errors because we may have removed the cluster that this package was inside of if err != nil { message.Warnf("Unable to apply the '%s' package secret: '%s' (this may be normal if the cluster was removed)", secretName, err.Error())