Skip to content

Commit

Permalink
Merge branch 'main' into hotfix-test-http-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 authored Feb 21, 2024
2 parents 84cd3e1 + 714f7c0 commit c552a75
Show file tree
Hide file tree
Showing 34 changed files with 84 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
Aliases: []string{"c"},
Short: lang.CmdConnectShort,
Long: lang.CmdConnectLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
var target string
if len(args) > 0 {
target = args[0]
Expand Down Expand Up @@ -89,7 +89,7 @@ var (
Use: "list",
Aliases: []string{"l"},
Short: lang.CmdConnectListShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
cluster.NewClusterOrDie().PrintConnectTable()
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var destroyCmd = &cobra.Command{
Aliases: []string{"d"},
Short: lang.CmdDestroyShort,
Long: lang.CmdDestroyLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
c, err := cluster.NewClusterWithWait(cluster.DefaultTimeout)
if err != nil {
message.Fatalf(err, lang.ErrNoClusterConnection)
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var devDeployCmd = &cobra.Command{
Args: cobra.MaximumNArgs(1),
Short: lang.CmdDevDeployShort,
Long: lang.CmdDevDeployLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)

v := common.GetViper()
Expand All @@ -65,7 +65,7 @@ var devTransformGitLinksCmd = &cobra.Command{
Aliases: []string{"p"},
Short: lang.CmdDevPatchGitShort,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
host, fileName := args[0], args[1]

// Read the contents of the given file
Expand Down Expand Up @@ -108,7 +108,7 @@ var devSha256SumCmd = &cobra.Command{
Aliases: []string{"s"},
Short: lang.CmdDevSha256sumShort,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
fileName := args[0]

var tmp string
Expand Down Expand Up @@ -184,7 +184,7 @@ var devFindImagesCmd = &cobra.Command{
Args: cobra.MaximumNArgs(1),
Short: lang.CmdDevFindImagesShort,
Long: lang.CmdDevFindImagesLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
// If a directory was provided, use that as the base directory
common.SetBaseDirectory(args, &pkgConfig)

Expand All @@ -210,7 +210,7 @@ var devGenConfigFileCmd = &cobra.Command{
Args: cobra.MaximumNArgs(1),
Short: lang.CmdDevGenerateConfigShort,
Long: lang.CmdDevGenerateConfigLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
fileName := "zarf-config.toml"

// If a filename was provided, use that
Expand All @@ -231,7 +231,7 @@ var devLintCmd = &cobra.Command{
Aliases: []string{"l"},
Short: lang.CmdDevLintShort,
Long: lang.CmdDevLintLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)
v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var initCmd = &cobra.Command{
Short: lang.CmdInitShort,
Long: lang.CmdInitLong,
Example: lang.CmdInitExample,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
zarfLogo := message.GetLogo()
_, _ = fmt.Fprintln(os.Stderr, zarfLogo)

Expand Down
20 changes: 10 additions & 10 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var agentCmd = &cobra.Command{
Use: "agent",
Short: lang.CmdInternalAgentShort,
Long: lang.CmdInternalAgentLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
agent.StartWebhook()
},
}
Expand All @@ -46,15 +46,15 @@ var httpProxyCmd = &cobra.Command{
Use: "http-proxy",
Short: lang.CmdInternalProxyShort,
Long: lang.CmdInternalProxyLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
agent.StartHTTPProxy()
},
}

var genCLIDocs = &cobra.Command{
Use: "gen-cli-docs",
Short: lang.CmdInternalGenerateCliDocsShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// Don't include the datestamp in the output
rootCmd.DisableAutoGenTag = true

Expand Down Expand Up @@ -126,7 +126,7 @@ var genConfigSchemaCmd = &cobra.Command{
Use: "gen-config-schema",
Aliases: []string{"gc"},
Short: lang.CmdInternalConfigSchemaShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
schema := jsonschema.Reflect(&types.ZarfPackage{})
output, err := json.MarshalIndent(schema, "", " ")
if err != nil {
Expand All @@ -146,7 +146,7 @@ var genTypesSchemaCmd = &cobra.Command{
Use: "gen-types-schema",
Aliases: []string{"gt"},
Short: lang.CmdInternalTypesSchemaShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
schema := jsonschema.Reflect(&zarfTypes{})
output, err := json.MarshalIndent(schema, "", " ")
if err != nil {
Expand All @@ -160,7 +160,7 @@ var createReadOnlyGiteaUser = &cobra.Command{
Use: "create-read-only-gitea-user",
Short: lang.CmdInternalCreateReadOnlyGiteaUserShort,
Long: lang.CmdInternalCreateReadOnlyGiteaUserLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// Load the state so we can get the credentials for the admin git user
state, err := cluster.NewClusterOrDie().LoadZarfState()
if err != nil {
Expand All @@ -178,7 +178,7 @@ var createPackageRegistryToken = &cobra.Command{
Use: "create-artifact-registry-token",
Short: lang.CmdInternalArtifactRegistryGiteaTokenShort,
Long: lang.CmdInternalArtifactRegistryGiteaTokenLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// Load the state so we can get the credentials for the admin git user
c := cluster.NewClusterOrDie()
state, err := c.LoadZarfState()
Expand All @@ -204,7 +204,7 @@ var updateGiteaPVC = &cobra.Command{
Use: "update-gitea-pvc",
Short: lang.CmdInternalUpdateGiteaPVCShort,
Long: lang.CmdInternalUpdateGiteaPVCLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {

// There is a possibility that the pvc does not yet exist and Gitea helm chart should create it
helmShouldCreate, err := git.UpdateGiteaPVC(rollback)
Expand All @@ -219,7 +219,7 @@ var updateGiteaPVC = &cobra.Command{
var isValidHostname = &cobra.Command{
Use: "is-valid-hostname",
Short: lang.CmdInternalIsValidHostnameShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
if valid := helpers.IsValidHostName(); !valid {
hostname, _ := os.Hostname()
message.Fatalf(nil, lang.CmdInternalIsValidHostnameErr, hostname)
Expand All @@ -232,7 +232,7 @@ var computeCrc32 = &cobra.Command{
Aliases: []string{"c"},
Short: lang.CmdInternalCrc32Short,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
text := args[0]
hash := helpers.GetCRCHash(text)
fmt.Printf("%d\n", hash)
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var packageCreateCmd = &cobra.Command{
Args: cobra.MaximumNArgs(1),
Short: lang.CmdPackageCreateShort,
Long: lang.CmdPackageCreateLong,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)

var isCleanPathRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-\/\.\~\\:]+$`)
Expand Down Expand Up @@ -70,7 +70,7 @@ var packageDeployCmd = &cobra.Command{
Short: lang.CmdPackageDeployShort,
Long: lang.CmdPackageDeployLong,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = choosePackage(args)

// Ensure uppercase keys from viper and CLI --set
Expand Down Expand Up @@ -98,7 +98,7 @@ var packageMirrorCmd = &cobra.Command{
Long: lang.CmdPackageMirrorLong,
Example: lang.CmdPackageMirrorExample,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = choosePackage(args)

// Configure the packager
Expand All @@ -118,7 +118,7 @@ var packageInspectCmd = &cobra.Command{
Short: lang.CmdPackageInspectShort,
Long: lang.CmdPackageInspectLong,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = choosePackage(args)

src := identifyAndFallbackToClusterSource()
Expand All @@ -139,7 +139,7 @@ var packageListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"l", "ls"},
Short: lang.CmdPackageListShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// Get all the deployed packages
deployedZarfPackages, errs := cluster.NewClusterOrDie().GetDeployedZarfPackages()
if len(errs) > 0 && len(deployedZarfPackages) == 0 {
Expand Down Expand Up @@ -177,7 +177,7 @@ var packageRemoveCmd = &cobra.Command{
Aliases: []string{"u", "rm"},
Args: cobra.MaximumNArgs(1),
Short: lang.CmdPackageRemoveShort,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = choosePackage(args)

src := identifyAndFallbackToClusterSource()
Expand All @@ -197,7 +197,7 @@ var packagePublishCmd = &cobra.Command{
Short: lang.CmdPackagePublishShort,
Example: lang.CmdPackagePublishExample,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = args[0]

if !helpers.IsOCIURL(args[1]) {
Expand Down Expand Up @@ -236,7 +236,7 @@ var packagePullCmd = &cobra.Command{
Short: lang.CmdPackagePullShort,
Example: lang.CmdPackagePullExample,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
pkgConfig.PkgOpts.PackageSource = args[0]

// Configure the packager
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (

var rootCmd = &cobra.Command{
Use: "zarf COMMAND",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
// Skip for vendor-only commands
if common.CheckVendorOnlyFromPath(cmd) {
return
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/tools/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var archiverCompressCmd = &cobra.Command{
Aliases: []string{"c"},
Short: lang.CmdToolsArchiverCompressShort,
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
sourceFiles, destinationArchive := args[:len(args)-1], args[len(args)-1]
err := archiver.Archive(sourceFiles, destinationArchive)
if err != nil {
Expand All @@ -44,7 +44,7 @@ var archiverDecompressCmd = &cobra.Command{
Aliases: []string{"d"},
Short: lang.CmdToolsArchiverDecompressShort,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
sourceArchive, destinationPath := args[0], args[1]
err := archiver.Unarchive(sourceArchive, destinationPath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var toolsCmd = &cobra.Command{
Use: "tools",
Aliases: []string{"t"},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
config.SkipLogFile = true

// Skip for vendor-only commands
Expand Down
16 changes: 15 additions & 1 deletion src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
Use: "registry",
Aliases: []string{"r", "crane"},
Short: lang.CmdToolsRegistryShort,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {

exec.ExitOnInterrupt()

Expand Down Expand Up @@ -246,6 +246,9 @@ func pruneImages(_ *cobra.Command, _ []string) error {
func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.DeployedPackage, registryEndpoint string) error {
authOption := config.GetCraneAuthOption(zarfState.RegistryInfo.PushUsername, zarfState.RegistryInfo.PushPassword)

spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneLookup)
defer spinner.Stop()

// Determine which image digests are currently used by Zarf packages
pkgImages := map[string]bool{}
for _, pkg := range zarfPackages {
Expand Down Expand Up @@ -273,6 +276,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Updatef(lang.CmdToolsRegistryPruneCatalog)

// Find which images and tags are in the registry currently
imageCatalog, err := crane.Catalog(registryEndpoint, authOption)
if err != nil {
Expand All @@ -295,6 +300,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Updatef(lang.CmdToolsRegistryPruneCalculate)

// Figure out which images are in the registry but not needed by packages
imageDigestsToPrune := map[string]bool{}
for digestRef, digest := range referenceToDigest {
Expand All @@ -308,6 +315,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Success()

if len(imageDigestsToPrune) > 0 {
message.Note(lang.CmdToolsRegistryPruneImageList)

Expand All @@ -328,13 +337,18 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}
if confirm {
spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneDelete)
defer spinner.Stop()

// Delete the digest references that are to be pruned
for digestRef := range imageDigestsToPrune {
err = crane.Delete(digestRef, authOption)
if err != nil {
return err
}
}

spinner.Success()
}
} else {
message.Note(lang.CmdToolsRegistryPruneNoImages)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/helm/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func newDependencyListCmd(out io.Writer) *cobra.Command {
Short: "list the dependencies for the given chart",
Long: dependencyListDesc,
Args: require.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
chartpath := "."
if len(args) > 0 {
chartpath = filepath.Clean(args[0])
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/helm/dependency_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Comm
Short: "rebuild the charts/ directory based on the Chart.lock file",
Long: dependencyBuildDesc,
Args: require.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
chartpath := "."
if len(args) > 0 {
chartpath = filepath.Clean(args[0])
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/helm/dependency_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com
Short: "update charts/ based on the contents of Chart.yaml",
Long: dependencyUpDesc,
Args: require.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
chartpath := "."
if len(args) > 0 {
chartpath = filepath.Clean(args[0])
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/helm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) {
cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o",
fmt.Sprintf("prints the output in the specified format. Allowed values: %s", strings.Join(output.Formats(), ", ")))

err := cmd.RegisterFlagCompletionFunc(outputFlag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
err := cmd.RegisterFlagCompletionFunc(outputFlag, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
var formatNames []string
for format, desc := range output.FormatsWithDesc() {
formatNames = append(formatNames, fmt.Sprintf("%s\t%s", format, desc))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/tools/helm/load_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func addPluginCommands(plugin *plugin.Plugin, baseCmd *cobra.Command, cmds *plug
// to the dynamic completion script of the plugin.
DisableFlagParsing: true,
// A Run is required for it to be a valid command without subcommands
Run: func(cmd *cobra.Command, args []string) {},
Run: func(_ *cobra.Command, _ []string) {},
}
baseCmd.AddCommand(subCmd)
addPluginCommands(plugin, subCmd, &cmd)
Expand Down
Loading

0 comments on commit c552a75

Please sign in to comment.