Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update post-renderer to verify secret data for existing secrets #331

Merged
merged 3 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ var destroyCmd = &cobra.Command{

// If Zarf didn't deploy the cluster, only delete the ZarfNamespace
k8s.DeleteZarfNamespace()

// Delete the zarf-registry secret in the default namespace
defaultSecret, _ := k8s.GetSecret("default", "zarf-registry")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeff-mccoy Should we just delete all the zarf-registry secrets across all the namespaces? I can't think of a good reason to keep the secrets if we're doing a destroy since the registry the creds are for won't exist anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I must have skipped it since it was out of date and didnt have latest commit tested

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine for now, we need to discuss this vs the "created-by" label tracking for deletion of resources at some point.

k8s.DeleteSecret(defaultSecret)
}
},
}
Expand Down
14 changes: 9 additions & 5 deletions cli/internal/helm/post-render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"os"
"reflect"
"time"

"github.com/defenseunicorns/zarf/cli/config"
Expand Down Expand Up @@ -186,11 +187,14 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) {
}
}

// Try to get an existing secret
if secret, _ := k8s.GetSecret(name, secretName); secret.Name != secretName {
// create the missing zarf secret
secret = k8s.GenerateRegistryPullCreds(name, secretName)
if err := k8s.CreateSecret(secret); err != nil {
// Create the secret
validSecret := k8s.GenerateRegistryPullCreds(name, secretName)

// Try to get a valid existing secret
currentSecret, _ := k8s.GetSecret(name, secretName)
if currentSecret.Name != secretName || !reflect.DeepEqual(currentSecret.Data, validSecret.Data) {
// create/update the missing zarf secret
if err := k8s.ReplaceSecret(validSecret); err != nil {
message.Errorf(err, "Problem creating registry secret for the %s namespace", name)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cli/internal/k8s/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package k8s

import (
"context"
"os"
"time"

"github.com/defenseunicorns/zarf/cli/internal/message"
Expand Down Expand Up @@ -76,7 +75,7 @@ func DeleteZarfNamespace() {
_, err := clientset.CoreV1().Namespaces().Get(context.TODO(), ZarfNamespace, metav1.GetOptions{})
if errors.IsNotFound(err) {
spinner.Successf("Zarf removed from this cluster")
os.Exit(0)
return
}
time.Sleep(1 * time.Second)
}
Expand Down