Skip to content

Commit

Permalink
Ignore not found delete errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed Jun 3, 2024
1 parent a22a7ad commit df1dbc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ go 1.21.8
replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6

require (
cuelang.org/go v0.7.0
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.2.1
github.com/agnivade/levenshtein v1.1.1
Expand Down Expand Up @@ -62,6 +61,8 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require cuelang.org/go v0.7.0 // indirect

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
Expand Down
8 changes: 4 additions & 4 deletions src/internal/packager/helm/post-render.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"slices"

"github.com/defenseunicorns/pkg/helpers"
"github.com/defenseunicorns/zarf/src/config"
Expand Down Expand Up @@ -139,9 +139,9 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error {
return fmt.Errorf("unable to create the missing namespace %s", name)
}
} else if r.cfg.DeployOpts.AdoptExistingResources {
// IsInitialNamespace returns true if the given namespace name is an initial k8s namespace: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#initial-namespaces
if name == "default" || strings.HasPrefix(name, "kube-") {
// If this is a K8s initial namespace, refuse to adopt it
// Refuse to adopt namespace if it is one of four initial Kubernetes namespaces.
// https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#initial-namespaces
if slices.Contains([]string{"default", "kube-node-lease", "kube-public", "kube-system"}, name) {
message.Warnf("Refusing to adopt the initial namespace: %s", name)
} else {
// This is an existing namespace to adopt
Expand Down
8 changes: 5 additions & 3 deletions src/pkg/cluster/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ func (c *Cluster) DeleteZarfNamespace(ctx context.Context) error {
spinner := message.NewProgressSpinner("Deleting the zarf namespace from this cluster")
defer spinner.Stop()

gracePeriod := int64(0)
err := c.Clientset.CoreV1().Namespaces().Delete(ctx, ZarfNamespaceName, metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod})
if err != nil && !kerrors.IsNotFound(err) {
err := c.Clientset.CoreV1().Namespaces().Delete(ctx, ZarfNamespaceName, metav1.DeleteOptions{})
if kerrors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
timer := time.NewTimer(0)
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ func (p *Packager) setupState(ctx context.Context) (err error) {
if err != nil && !kerrors.IsAlreadyExists(err) {
return err
}
if err == nil {
return nil
}
_, err = p.cluster.Clientset.CoreV1().Namespaces().Update(ctx, zarfNamespace, metav1.UpdateOptions{})
if err != nil {
return err
Expand Down

0 comments on commit df1dbc0

Please sign in to comment.