Skip to content

Commit

Permalink
remove patches
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Oct 17, 2024
1 parent 9d1a35d commit 9f757e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
8 changes: 1 addition & 7 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package packager

import (
"context"
"encoding/json"
"fmt"
"net/url"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
33 changes: 10 additions & 23 deletions src/pkg/packager/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 9f757e9

Please sign in to comment.