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

chore: add message asking if the user has init'ed their cluster and slim down error messages more generally #2177

Merged
merged 4 commits into from
Dec 6, 2023
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
10 changes: 5 additions & 5 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import "errors"
// Debug messages will not be a part of the language strings since they are not intended to be user facing
// Include sprintf formatting directives in the string if needed.
const (
ErrLoadState = "Failed to load the Zarf State from the Kubernetes cluster."
ErrSaveState = "Failed to save the Zarf State to the Kubernetes cluster."
ErrLoadPackageSecret = "Failed to load %s's secret from the Kubernetes cluster"
ErrNoClusterConnection = "Failed to connect to the Kubernetes cluster."
ErrTunnelFailed = "Failed to create a tunnel to the Kubernetes cluster."
ErrLoadState = "Failed to load the Zarf State from the cluster."
ErrSaveState = "Failed to save the Zarf State to the cluster."
ErrLoadPackageSecret = "Failed to load %s's secret from the cluster"
ErrNoClusterConnection = "Failed to connect to the cluster."
ErrTunnelFailed = "Failed to create a tunnel to the cluster."
ErrUnmarshal = "failed to unmarshal file: %w"
ErrWritingFile = "failed to write file %s: %s"
ErrDownloading = "failed to download %s: %s"
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/types"
"github.com/fatih/color"

"github.com/defenseunicorns/zarf/src/pkg/k8s"
"github.com/defenseunicorns/zarf/src/pkg/message"
Expand Down Expand Up @@ -157,7 +158,7 @@ func (c *Cluster) LoadZarfState() (state *types.ZarfState, err error) {
// Set up the API connection
secret, err := c.GetSecret(ZarfNamespaceName, ZarfStateSecretName)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w. %s", err, utils.ColorWrap("Did you remember to zarf init?", color.Bold))
}

err = json.Unmarshal(secret.Data[ZarfStateDataKey], &state)
Expand Down
15 changes: 8 additions & 7 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/internal/packager/git"
"github.com/defenseunicorns/zarf/src/internal/packager/helm"
"github.com/defenseunicorns/zarf/src/internal/packager/images"
Expand Down Expand Up @@ -74,7 +75,7 @@ func (p *Packager) Deploy() (err error) {
// Get a list of all the components we are deploying and actually deploy them
deployedComponents, err := p.deployComponents()
if err != nil {
return fmt.Errorf("unable to deploy all components in this Zarf Package: %w", err)
return err
}
if len(deployedComponents) == 0 {
message.Warn("No components were selected for deployment. Inspect the package to view the available components and select components interactively or by name with \"--components\"")
Expand Down Expand Up @@ -165,19 +166,19 @@ func (p *Packager) deployComponents() (deployedComponents []types.DeployedCompon
deployedComponents[idx].Status = types.ComponentStatusFailed
if p.isConnectedToCluster() {
if _, err := p.cluster.RecordPackageDeploymentAndWait(p.cfg.Pkg, deployedComponents, p.connectStrings, p.generation, component, p.cfg.DeployOpts.SkipWebhooks); err != nil {
message.Debugf("Unable to record package deployment for component %s: this will affect features like `zarf package remove`: %s", component.Name, err.Error())
message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error())
}
}

return deployedComponents, fmt.Errorf("unable to deploy component %s: %w", component.Name, deployErr)
return deployedComponents, fmt.Errorf("unable to deploy component %q: %w", component.Name, deployErr)
}

// Update the package secret to indicate that we successfully deployed this component
deployedComponents[idx].InstalledCharts = charts
deployedComponents[idx].Status = types.ComponentStatusSucceeded
if p.isConnectedToCluster() {
if _, err := p.cluster.RecordPackageDeploymentAndWait(p.cfg.Pkg, deployedComponents, p.connectStrings, p.generation, component, p.cfg.DeployOpts.SkipWebhooks); err != nil {
message.Debugf("Unable to record package deployment for component %s: this will affect features like `zarf package remove`: %s", component.Name, err.Error())
message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error())
}
}

Expand Down Expand Up @@ -222,7 +223,7 @@ func (p *Packager) deployInitComponent(component types.ZarfComponent) (charts []

charts, err = p.deployComponent(component, isAgent /* skip img checksum if isAgent */, isSeedRegistry /* skip image push if isSeedRegistry */)
if err != nil {
return charts, fmt.Errorf("unable to deploy component %s: %w", component.Name, err)
return charts, fmt.Errorf("unable to deploy component %q: %w", component.Name, err)
}

// Do cleanup for when we inject the seed registry during initialization
Expand Down Expand Up @@ -266,7 +267,7 @@ func (p *Packager) deployComponent(component types.ZarfComponent, noImgChecksum
// Setup the state in the config and get the valuesTemplate
p.valueTemplate, err = p.setupStateValuesTemplate()
if err != nil {
return charts, fmt.Errorf("unable to get the updated value template: %w", err)
return charts, err
}

// Disable the registry HPA scale down if we are deploying images and it is not already disabled
Expand Down Expand Up @@ -402,7 +403,7 @@ func (p *Packager) setupStateValuesTemplate() (values *template.Values, err erro
state, err := p.cluster.LoadZarfState()
// Return on error if we are not in YOLO mode
if err != nil && !p.cfg.Pkg.Metadata.YOLO {
return nil, fmt.Errorf("unable to load the Zarf State from the Kubernetes cluster: %w", err)
return nil, fmt.Errorf("%s %w", lang.ErrLoadState, err)
} else if state == nil && p.cfg.Pkg.Metadata.YOLO {
state = &types.ZarfState{}
// YOLO mode, so minimal state needed
Expand Down
Loading