Skip to content

Commit

Permalink
fix: improve rollback logic, messaging, and support for local tarballs (
Browse files Browse the repository at this point in the history
#2157)

## Description

This hotfixes the max release history to be all releases in case the
most recent release was a failure.

## Related Issue

Fixes #N/A

## Type of change

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Racer159 authored Nov 29, 2023
1 parent 587c695 commit 68238ab
Show file tree
Hide file tree
Showing 39 changed files with 919 additions and 469 deletions.
3 changes: 3 additions & 0 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
## Options

```
--adopt-existing-resources Adopts any pre-existing K8s resources into the Helm charts managed by Zarf. ONLY use when you have existing deployments you want Zarf to takeover.
--artifact-push-token string [alpha] API Token for the push-user to access the artifact registry
--artifact-push-username string [alpha] Username to access to the artifact registry Zarf is configured to use. User must be able to upload package artifacts.
--artifact-url string [alpha] External artifact registry url to use for this Zarf cluster
Expand All @@ -69,7 +70,9 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
--registry-secret string Registry secret value
--registry-url string External registry url address to use for this Zarf cluster
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
--skip-webhooks [alpha] Skip waiting for external webhooks to execute as each package component is deployed
--storage-class string Specify the storage class to use for the registry and git server. E.g. --storage-class=standard
--timeout duration Timeout for Helm operations such as installs and rollbacks (default 15m0s)
```

## Options inherited from parent commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ zarf package deploy [ PACKAGE_SOURCE ] [flags]
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
--shasum string Shasum of the package to deploy. Required if deploying a remote package and "--insecure" is not provided
--skip-webhooks [alpha] Skip waiting for external webhooks to execute as each package component is deployed
--timeout duration Timeout for Helm operations such as installs and rollbacks (default 15m0s)
```

## Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ Must be one of:
 
<blockquote>

**Description:** The path to the chart folder
**Description:** The path to the local chart's folder or .tgz archive

| | |
| -------- | -------- |
Expand Down
5 changes: 5 additions & 0 deletions examples/helm-charts/values.yaml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/helm-charts/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ components:
version: 6.4.0
namespace: podinfo-from-local-chart
localPath: chart
valuesFiles:
- values.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
# This is the cosign signature for the podinfo image for image signature verification
Expand All @@ -34,6 +36,8 @@ components:
namespace: podinfo-from-git
url: https://github.com/stefanprodan/podinfo.git
gitPath: charts/podinfo
valuesFiles:
- values.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
# This is the cosign signature for the podinfo image for image signature verification
Expand All @@ -55,6 +59,8 @@ components:
version: 6.4.0
namespace: podinfo-from-oci
url: oci://ghcr.io/stefanprodan/charts/podinfo
valuesFiles:
- values.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
# This is the cosign signature for the podinfo image for image signature verification
Expand Down Expand Up @@ -84,6 +90,8 @@ components:
namespace: helm-alt-release-name
url: https://stefanprodan.github.io/podinfo
releaseName: cool-name
valuesFiles:
- values.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
# This is the cosign signature for the podinfo image for image signature verification
Expand Down
17 changes: 17 additions & 0 deletions src/cmd/common/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strings"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/spf13/viper"
Expand Down Expand Up @@ -82,6 +83,7 @@ const (
VPkgDeployShasum = "package.deploy.shasum"
VPkgDeploySget = "package.deploy.sget"
VPkgDeploySkipWebhooks = "package.deploy.skip_webhooks"
VPkgDeployTimeout = "package.deploy.timeout"

// Package publish config keys

Expand Down Expand Up @@ -137,6 +139,9 @@ func InitViper() *viper.Viper {
// Optional, so ignore errors
vConfigError = v.ReadInConfig()

// Set default values for viper
setDefaults()

return v
}

Expand Down Expand Up @@ -167,3 +172,15 @@ func printViperConfigUsed() {
message.Notef(lang.CmdViperInfoUsingConfigFile, v.ConfigFileUsed())
}
}

func setDefaults() {
// Root defaults that are non-zero values
v.SetDefault(VLogLevel, "info")
v.SetDefault(VZarfCache, config.ZarfDefaultCachePath)

// Package defaults that are non-zero values
v.SetDefault(VPkgOCIConcurrency, 3)

// Deploy opts that are non-zero values
v.SetDefault(VPkgDeployTimeout, config.ZarfDefaultHelmTimeout)
}
3 changes: 1 addition & 2 deletions src/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ var destroyCmd = &cobra.Command{
}
} else {
// Perform chart uninstallation
helmCfg := helm.Helm{}
helmCfg.Destroy(removeComponents)
helm.Destroy(removeComponents)

// If Zarf didn't deploy the cluster, only delete the ZarfNamespace
c.DeleteZarfNamespace()
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func init() {
rootCmd.AddCommand(initCmd)

// Init package variable defaults that are non-zero values
// NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default
v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser)

Expand Down Expand Up @@ -211,5 +212,13 @@ func init() {
initCmd.Flags().StringVar(&pkgConfig.InitOpts.ArtifactServer.PushUsername, "artifact-push-username", v.GetString(common.VInitArtifactPushUser), lang.CmdInitFlagArtifactPushUser)
initCmd.Flags().StringVar(&pkgConfig.InitOpts.ArtifactServer.PushToken, "artifact-push-token", v.GetString(common.VInitArtifactPushToken), lang.CmdInitFlagArtifactPushToken)

// Flags that control how a deployment proceeds
// Always require adopt-existing-resources flag (no viper)
initCmd.Flags().BoolVar(&pkgConfig.DeployOpts.AdoptExistingResources, "adopt-existing-resources", false, lang.CmdPackageDeployFlagAdoptExistingResources)

initCmd.Flags().BoolVar(&pkgConfig.DeployOpts.SkipWebhooks, "skip-webhooks", v.GetBool(common.VPkgDeploySkipWebhooks), lang.CmdPackageDeployFlagSkipWebhooks)

initCmd.Flags().DurationVar(&pkgConfig.DeployOpts.Timeout, "timeout", v.GetDuration(common.VPkgDeployTimeout), lang.CmdPackageDeployFlagTimeout)

initCmd.Flags().SortFlags = true
}
29 changes: 16 additions & 13 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
"github.com/defenseunicorns/zarf/src/pkg/utils"

"github.com/pterm/pterm"
"oras.land/oras-go/v2/registry"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -158,10 +157,8 @@ var packageListCmd = &cobra.Command{
message.Fatalf(errs, lang.CmdPackageListNoPackageWarn)
}

// Populate a pterm table of all the deployed packages
packageTable := pterm.TableData{
{" Package ", "Version", "Components"},
}
// Populate a matrix of all the deployed packages
packageData := [][]string{}

for _, pkg := range deployedZarfPackages {
var components []string
Expand All @@ -170,15 +167,14 @@ var packageListCmd = &cobra.Command{
components = append(components, component.Name)
}

packageTable = append(packageTable, pterm.TableData{{
fmt.Sprintf(" %s", pkg.Name),
pkg.Data.Metadata.Version,
fmt.Sprintf("%v", components),
}}...)
packageData = append(packageData, []string{
pkg.Name, pkg.Data.Metadata.Version, fmt.Sprintf("%v", components),
})
}

// Print out the table for the user
_ = pterm.DefaultTable.WithHasHeader().WithData(packageTable).Render()
header := []string{"Package", "Version", "Components"}
message.Table(header, packageData)

// Print out any unmarshalling errors
if len(errs) > 0 {
Expand Down Expand Up @@ -345,7 +341,6 @@ func init() {

func bindPackageFlags(v *viper.Viper) {
packageFlags := packageCmd.PersistentFlags()
v.SetDefault(common.VPkgOCIConcurrency, 3)
packageFlags.IntVar(&config.CommonOptions.OCIConcurrency, "oci-concurrency", v.GetInt(common.VPkgOCIConcurrency), lang.CmdPackageFlagConcurrency)
packageFlags.StringVarP(&pkgConfig.PkgOpts.PublicKeyPath, "key", "k", v.GetString(common.VPkgPublicKey), lang.CmdPackageFlagFlagPublicKey)
}
Expand Down Expand Up @@ -393,18 +388,26 @@ func bindDeployFlags(v *viper.Viper) {
// Always require adopt-existing-resources flag (no viper)
deployFlags.BoolVar(&pkgConfig.DeployOpts.AdoptExistingResources, "adopt-existing-resources", false, lang.CmdPackageDeployFlagAdoptExistingResources)

deployFlags.BoolVar(&pkgConfig.DeployOpts.SkipWebhooks, "skip-webhooks", v.GetBool(common.VPkgDeploySkipWebhooks), lang.CmdPackageDeployFlagSkipWebhooks)

deployFlags.DurationVar(&pkgConfig.DeployOpts.Timeout, "timeout", v.GetDuration(common.VPkgDeployTimeout), lang.CmdPackageDeployFlagTimeout)

deployFlags.StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet)
deployFlags.StringVar(&pkgConfig.PkgOpts.OptionalComponents, "components", v.GetString(common.VPkgDeployComponents), lang.CmdPackageDeployFlagComponents)
deployFlags.StringVar(&pkgConfig.PkgOpts.Shasum, "shasum", v.GetString(common.VPkgDeployShasum), lang.CmdPackageDeployFlagShasum)
deployFlags.StringVar(&pkgConfig.PkgOpts.SGetKeyPath, "sget", v.GetString(common.VPkgDeploySget), lang.CmdPackageDeployFlagSget)
deployFlags.BoolVar(&pkgConfig.DeployOpts.SkipWebhooks, "skip-webhooks", v.GetBool(common.VPkgDeploySkipWebhooks), lang.CmdPackageDeployFlagSkipWebhooks)

deployFlags.MarkHidden("sget")
}

func bindMirrorFlags(v *viper.Viper) {
mirrorFlags := packageMirrorCmd.Flags()

// Init package variable defaults that are non-zero values
// NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default
v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser)

// Always require confirm flag (no viper)
mirrorFlags.BoolVar(&config.CommonOptions.Confirm, "confirm", false, lang.CmdPackageDeployFlagConfirm)

Expand Down
3 changes: 0 additions & 3 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ func init() {

v := common.InitViper()

v.SetDefault(common.VLogLevel, "info")
v.SetDefault(common.VZarfCache, config.ZarfDefaultCachePath)

rootCmd.PersistentFlags().StringVarP(&common.LogLevelCLI, "log-level", "l", v.GetString(common.VLogLevel), lang.RootCmdFlagLogLevel)
rootCmd.PersistentFlags().StringVarP(&config.CLIArch, "architecture", "a", v.GetString(common.VArchitecture), lang.RootCmdFlagArch)
rootCmd.PersistentFlags().BoolVar(&config.SkipLogFile, "no-log-file", v.GetBool(common.VNoLogFile), lang.RootCmdFlagSkipLogFile)
Expand Down
7 changes: 1 addition & 6 deletions src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ var updateCredsCmd = &cobra.Command{
}

// Update Zarf 'init' component Helm releases if present
h := helm.Helm{
Cluster: c,
Cfg: &types.PackagerConfig{
State: newState,
},
}
h := helm.NewClusterOnly(&types.PackagerConfig{State: newState}, c)

if slices.Contains(args, message.RegistryKey) && newState.RegistryInfo.InternalRegistry {
err = h.UpdateZarfRegistryValues()
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ var (
operationStartTime = time.Now().Unix()
dataInjectionMarker = ".zarf-injection-%d"

ZarfDefaultCachePath = filepath.Join("~", ".zarf-cache")
ZarfDefaultCachePath = filepath.Join("~", ".zarf-cache")
ZarfDefaultHelmTimeout = 15 * time.Minute
)

// GetArch returns the arch based on a priority list with options for overriding.
Expand Down
1 change: 1 addition & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ $ zarf package mirror-resources <your-package.tar.zst> \
CmdPackageDeployFlagShasum = "Shasum of the package to deploy. Required if deploying a remote package and \"--insecure\" is not provided"
CmdPackageDeployFlagSget = "[Deprecated] Path to public sget key file for remote packages signed via cosign. This flag will be removed in v1.0.0 please use the --key flag instead."
CmdPackageDeployFlagSkipWebhooks = "[alpha] Skip waiting for external webhooks to execute as each package component is deployed"
CmdPackageDeployFlagTimeout = "Timeout for Helm operations such as installs and rollbacks"
CmdPackageDeployValidateArchitectureErr = "this package architecture is %s, but the target cluster only has the %s architecture(s). These architectures must be compatible when \"images\" are present"
CmdPackageDeployValidateLastNonBreakingVersionWarn = "The version of this Zarf binary '%s' is less than the LastNonBreakingVersion of '%s'. You may need to upgrade your Zarf version to at least '%s' to deploy this package"
CmdPackageDeployInvalidCLIVersionWarn = "CLIVersion is set to '%s' which can cause issues with package creation and deployment. To avoid such issues, please set the value to the valid semantic version for this version of Zarf."
Expand Down
27 changes: 8 additions & 19 deletions src/extensions/bigbang/bigbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ func Run(YOLO bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (typ
bbRepo := fmt.Sprintf("%s@%s", cfg.Repo, cfg.Version)

// Configure helm to pull down the Big Bang chart.
helmCfg := helm.Helm{
Chart: types.ZarfChart{
helmCfg := helm.New(
types.ZarfChart{
Name: bb,
Namespace: bb,
URL: bbRepo,
Version: cfg.Version,
ValuesFiles: cfg.ValuesFiles,
GitPath: "./chart",
},
BasePath: tmpPaths.Temp,
}
path.Join(tmpPaths.Temp, bb),
path.Join(tmpPaths.Temp, bb, "values"),
)

// Download the chart from Git and save it to a temporary directory.
chartPath := path.Join(tmpPaths.Temp, bb)
helmCfg.ChartLoadOverride, err = helmCfg.PackageChartFromGit(chartPath)
err = helmCfg.PackageChartFromGit(c.DeprecatedCosignKeyPath)
if err != nil {
return c, fmt.Errorf("unable to download Big Bang Chart: %w", err)
}
Expand Down Expand Up @@ -530,25 +530,14 @@ func findImagesforBBChartRepo(repo string, values chartutil.Values) (images []st
spinner := message.NewProgressSpinner("Discovering images in %s", repo)
defer spinner.Stop()

chart := types.ZarfChart{
Name: repo,
URL: repo,
Version: matches[1],
GitPath: "chart",
}

helmCfg := helm.Helm{
Chart: chart,
}

gitPath, err := helmCfg.DownloadChartFromGitToTemp(spinner)
gitPath, err := helm.DownloadChartFromGitToTemp(repo, spinner)
if err != nil {
return images, err
}
defer os.RemoveAll(gitPath)

// Set the directory for the chart
chartPath := filepath.Join(gitPath, helmCfg.Chart.GitPath)
chartPath := filepath.Join(gitPath, "chart")

images, err = helm.FindAnnotatedImagesForChart(chartPath, values)
if err != nil {
Expand Down
Loading

0 comments on commit 68238ab

Please sign in to comment.