Skip to content

Commit

Permalink
changing how this works
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 20, 2024
1 parent a19fb62 commit d3ef620
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/zarf-dev/zarf/src/pkg/pki"
"github.com/zarf-dev/zarf/src/pkg/zoci"
"github.com/zarf-dev/zarf/src/types"
kerrors "k8s.io/apimachinery/pkg/api/errors"
)

var subAltNames []string
Expand Down Expand Up @@ -116,7 +115,7 @@ var updateCredsCmd = &cobra.Command{
}
// TODO: Determine if this is actually needed.
if oldState.Distro == "" {
return errors.New("Zarf state secret did not load properly")
return errors.New("zarf state secret did not load properly")
}
newState, err := cluster.MergeZarfState(oldState, updateCredsInitOpts, args)
if err != nil {
Expand Down Expand Up @@ -152,20 +151,18 @@ var updateCredsCmd = &cobra.Command{
return err
}
}
// TODO once Zarf is changed so the default state is empty for a service when it is not deployed
// and sufficient time has passed for users state to get updated we should error on isNotFound
internalGitServerExists, err := c.InternalGitServerExists(cmd.Context())
if err != nil {
return err
}

// Update artifact token (if internal)
if slices.Contains(args, message.ArtifactKey) && newState.ArtifactServer.PushToken == "" && newState.ArtifactServer.IsInternal() {
pushToken, err := c.UpdateInternalArtifactServerToken(ctx, oldState.GitServer)
updateErr := fmt.Errorf("unable to create the new Gitea artifact token: %w", err)
// TODO once Zarf is changed so the default state is empty for a service when it is not deployed
// and sufficient time has passed for users state to get updated we should error on isNotFound
if err != nil && !kerrors.IsNotFound(err) {
return updateErr
}
if kerrors.IsNotFound(err) {
message.Warn(updateErr.Error())
} else {
newState.ArtifactServer.PushToken = pushToken
if slices.Contains(args, message.ArtifactKey) && newState.ArtifactServer.PushToken == "" && newState.ArtifactServer.IsInternal() && internalGitServerExists {
newState.ArtifactServer.PushToken, err = c.UpdateInternalArtifactServerToken(ctx, oldState.GitServer)
if err != nil {
return fmt.Errorf("unable to create the new Gitea artifact token: %w", err)
}
}

Expand All @@ -185,14 +182,10 @@ var updateCredsCmd = &cobra.Command{
message.Warnf(lang.CmdToolsUpdateCredsUnableUpdateRegistry, err.Error())
}
}
if slices.Contains(args, message.GitKey) && newState.GitServer.IsInternal() {
if slices.Contains(args, message.GitKey) && newState.GitServer.IsInternal() && internalGitServerExists {
err := c.UpdateInternalGitServerSecret(cmd.Context(), oldState.GitServer, newState.GitServer)
updateErr := fmt.Errorf("unable to update Zarf Git Server values: %w", err)
if err != nil && !kerrors.IsNotFound(err) {
return updateErr
}
if kerrors.IsNotFound(err) {
message.Warn(updateErr.Error())
if err != nil {
return fmt.Errorf("unable to update Zarf Git Server values: %w", err)
}
}
if slices.Contains(args, message.AgentKey) {
Expand Down

0 comments on commit d3ef620

Please sign in to comment.