From 0aa391b0b18d278e6cd399953651ab884323b3af Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Mon, 29 Jul 2024 11:28:27 +0200 Subject: [PATCH] refactor: replace debug logs with returning errors Signed-off-by: Philip Laine --- src/cmd/connect.go | 2 +- src/pkg/cluster/zarf.go | 6 +++--- src/pkg/packager/deploy.go | 13 ++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/cmd/connect.go b/src/cmd/connect.go index 26f012660e..4258279ebf 100644 --- a/src/cmd/connect.go +++ b/src/cmd/connect.go @@ -65,7 +65,7 @@ var connectCmd = &cobra.Command{ } else { spinner.Updatef(lang.CmdConnectEstablishedWeb, tunnel.FullURL()) if err := exec.LaunchURL(tunnel.FullURL()); err != nil { - message.Debug(err) + return err } } diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index 71d6f73c9e..f9ac54ef0c 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -179,11 +179,11 @@ func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg types. func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg types.ZarfPackage, components []types.DeployedComponent, connectStrings types.ConnectStrings, generation int) (deployedPackage *types.DeployedPackage, err error) { packageName := pkg.Metadata.Name - // Attempt to load information about webhooks for the package + // Optionally try to get information about webhooks for the package. var componentWebhooks map[string]map[string]types.Webhook existingPackageSecret, err := c.GetDeployedPackage(ctx, packageName) - if err != nil { - message.Debugf("Unable to fetch existing secret for package '%s': %s", packageName, err.Error()) + if err != nil && !kerrors.IsNotFound(err) { + return nil, err } if existingPackageSecret != nil { componentWebhooks = existingPackageSecret.ComponentWebhooks diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 2f7304580b..a46b4fd526 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -177,7 +177,7 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t // Update the package secret to indicate that we are attempting to deploy this component if p.isConnectedToCluster() { if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, 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()) + return nil, err } } @@ -205,7 +205,7 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t deployedComponents[idx].Status = types.ComponentStatusFailed if p.isConnectedToCluster() { if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, p.connectStrings, p.generation, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { - message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) + return nil, err } } @@ -217,7 +217,7 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t deployedComponents[idx].Status = types.ComponentStatusSucceeded if p.isConnectedToCluster() { if _, err := p.cluster.RecordPackageDeploymentAndWait(ctx, p.cfg.Pkg, deployedComponents, p.connectStrings, p.generation, component, p.cfg.DeployOpts.SkipWebhooks); err != nil { - message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) + return nil, err } } @@ -311,10 +311,9 @@ func (p *Packager) deployComponent(ctx context.Context, component types.ZarfComp // Disable the registry HPA scale down if we are deploying images and it is not already disabled if hasImages && !p.hpaModified && p.state.RegistryInfo.InternalRegistry { if err := p.cluster.DisableRegHPAScaleDown(ctx); err != nil { - message.Debugf("unable to disable the registry HPA scale down: %s", err.Error()) - } else { - p.hpaModified = true + return nil, fmt.Errorf("unable to dsable the registry HPA scale down: %w", err) } + p.hpaModified = true } } @@ -406,7 +405,7 @@ func (p *Packager) processComponentFiles(component types.ZarfComponent, pkgLocat // Check if the file looks like a text file isText, err := helpers.IsTextFile(subFile) if err != nil { - message.Debugf("unable to determine if file %s is a text file: %s", subFile, err) + return err } // If the file is a text file, template it