From f920a042722d261e6197893ebbf9b732a0841a85 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 19 Feb 2024 08:04:18 -0700 Subject: [PATCH 01/15] fix: multi-part tarballs being mismatched sizes --- src/pkg/utils/io.go | 28 ++++++++++++++++------------ src/test/e2e/05_tarball_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 7bda78ff7f..bb6ae79db2 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -339,7 +339,7 @@ func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256s // - fileNames: list of file paths srcFile was split across // - sha256sum: sha256sum of the srcFile before splitting // - err: any errors encountered -func SplitFile(srcFile string, chunkSizeBytes int) (err error) { +func SplitFile(srcPath string, chunkSizeBytes int) (err error) { var fileNames []string var sha256sum string hash := sha256.New() @@ -353,7 +353,7 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { buf := make([]byte, bufferSize) // get file size - fi, err := os.Stat(srcFile) + fi, err := os.Stat(srcPath) if err != nil { return err } @@ -364,15 +364,15 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { progressBar := message.NewProgressBar(fileSize, title) defer progressBar.Stop() - // open file - file, err := os.Open(srcFile) - defer file.Close() + // open srcFile + srcFile, err := os.Open(srcPath) if err != nil { return err } + defer srcFile.Close() // create file path starting from part 001 - path := fmt.Sprintf("%s.part001", srcFile) + path := fmt.Sprintf("%s.part001", srcPath) chunkFile, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err @@ -384,7 +384,7 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { chunkBytesRemaining := chunkSizeBytes // Loop over the tarball hashing as we go and breaking it into chunks based on the chunkSizeBytes for { - bytesRead, err := file.Read(buf) + bytesRead, err := srcFile.Read(buf) if err != nil { if err == io.EOF { @@ -404,10 +404,14 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { if err != nil { return err } + err = chunkFile.Close() + if err != nil { + return err + } // create new file - path = fmt.Sprintf("%s.part%03d", srcFile, len(fileNames)+1) - chunkFile, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) + path = fmt.Sprintf("%s.part%03d", srcPath, len(fileNames)+1) + chunkFile, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err } @@ -435,8 +439,8 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { title := fmt.Sprintf("[%d/%d] MB bytes written", progressBar.GetCurrent()/1000/1000, fileSize/1000/1000) progressBar.UpdateTitle(title) } - file.Close() - _ = os.RemoveAll(srcFile) + srcFile.Close() + _ = os.RemoveAll(srcPath) // calculate sha256 sum sha256sum = fmt.Sprintf("%x", hash.Sum(nil)) @@ -452,7 +456,7 @@ func SplitFile(srcFile string, chunkSizeBytes int) (err error) { } // write header file - path = fmt.Sprintf("%s.part000", srcFile) + path = fmt.Sprintf("%s.part000", srcPath) if err := os.WriteFile(path, jsonData, 0644); err != nil { return fmt.Errorf("unable to write the file %s: %w", path, err) } diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index 1e0e3c8473..caf2cf90ba 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -5,6 +5,7 @@ package test import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -36,6 +37,21 @@ func TestMultiPartPackage(t *testing.T) { require.NoError(t, err) // Length is 7 because there are 6 parts and 1 manifest require.Len(t, parts, 7) + // Check the file sizes are even + part1FileInfo, err := os.Stat(parts[1]) + require.NoError(t, err) + require.Equal(t, int64(1000000), part1FileInfo.Size()) + part2FileInfo, err := os.Stat(parts[2]) + require.NoError(t, err) + require.Equal(t, int64(1000000), part2FileInfo.Size()) + // Check the package data is correct + pkgData := types.ZarfSplitPackageData{} + part0File, err := os.ReadFile(parts[0]) + require.NoError(t, err) + err = json.Unmarshal(part0File, &pkgData) + require.NoError(t, err) + require.Equal(t, pkgData.Count, 6) + fmt.Printf("%#v", pkgData) stdOut, stdErr, err = e2e.Zarf("package", "deploy", deployPath, "--confirm") require.NoError(t, err, stdOut, stdErr) @@ -45,6 +61,17 @@ func TestMultiPartPackage(t *testing.T) { // deploying package combines parts back into single archive, check dir again to find all files parts, err = filepath.Glob("zarf-package-multi-part-*") + require.NoError(t, err) + // Length is 1 because `zarf package deploy` will recombine the file + require.Len(t, parts, 1) + // Ensure that the number of pkgData bytes was correct + fullFileInfo, err := os.Stat(parts[0]) + require.NoError(t, err) + require.Equal(t, pkgData.Bytes, fullFileInfo.Size()) + // Ensure that the pkgData shasum was correct (should be checked during deploy as well, but this is to double check) + err = utils.SHAsMatch(parts[0], pkgData.Sha256Sum) + require.NoError(t, err) + e2e.CleanFiles(parts...) e2e.CleanFiles(outputFile) } From 29cc6e2f349e10b30d9d960cd5e2761346b632e7 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 19 Feb 2024 14:07:36 -0700 Subject: [PATCH 02/15] update test to overcome 16MB buffer --- src/test/e2e/05_tarball_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index caf2cf90ba..f5bb5f2020 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -30,27 +30,27 @@ func TestMultiPartPackage(t *testing.T) { e2e.CleanFiles(deployPath, outputFile) // Create the package with a max size of 1MB - stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=1", "--confirm") + stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=2", "--confirm") require.NoError(t, err, stdOut, stdErr) parts, err := filepath.Glob("zarf-package-multi-part-*") require.NoError(t, err) - // Length is 7 because there are 6 parts and 1 manifest - require.Len(t, parts, 7) + // Length is 4 because there are 3 parts and 1 manifest + require.Len(t, parts, 4) // Check the file sizes are even part1FileInfo, err := os.Stat(parts[1]) require.NoError(t, err) - require.Equal(t, int64(1000000), part1FileInfo.Size()) + require.Equal(t, int64(2000000), part1FileInfo.Size()) part2FileInfo, err := os.Stat(parts[2]) require.NoError(t, err) - require.Equal(t, int64(1000000), part2FileInfo.Size()) + require.Equal(t, int64(2000000), part2FileInfo.Size()) // Check the package data is correct pkgData := types.ZarfSplitPackageData{} part0File, err := os.ReadFile(parts[0]) require.NoError(t, err) err = json.Unmarshal(part0File, &pkgData) require.NoError(t, err) - require.Equal(t, pkgData.Count, 6) + require.Equal(t, pkgData.Count, 3) fmt.Printf("%#v", pkgData) stdOut, stdErr, err = e2e.Zarf("package", "deploy", deployPath, "--confirm") From 9e7e080335588ff662ffe65f5d9ff401898ce294 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 19 Feb 2024 15:28:28 -0700 Subject: [PATCH 03/15] dynamically make a 50MiB file (more performant than a download) --- .gitignore | 1 + src/test/e2e/05_tarball_test.go | 8 ++++---- src/test/packages/05-multi-part/zarf.yaml | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 4270dbb1fb..3d96988028 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ *.bak *.key *.crt +*.dat *.run.zstd *.tar *.tar.gz diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index f5bb5f2020..02715455cd 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -24,13 +24,13 @@ func TestMultiPartPackage(t *testing.T) { var ( createPath = "src/test/packages/05-multi-part" deployPath = fmt.Sprintf("zarf-package-multi-part-%s.tar.zst.part000", e2e.Arch) - outputFile = "multi-part-demo.dat" + outputFile = "devops.stackexchange.com_en_all_2023-05.zim" ) e2e.CleanFiles(deployPath, outputFile) // Create the package with a max size of 1MB - stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=2", "--confirm") + stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=20", "--confirm") require.NoError(t, err, stdOut, stdErr) parts, err := filepath.Glob("zarf-package-multi-part-*") @@ -40,10 +40,10 @@ func TestMultiPartPackage(t *testing.T) { // Check the file sizes are even part1FileInfo, err := os.Stat(parts[1]) require.NoError(t, err) - require.Equal(t, int64(2000000), part1FileInfo.Size()) + require.Equal(t, int64(20000000), part1FileInfo.Size()) part2FileInfo, err := os.Stat(parts[2]) require.NoError(t, err) - require.Equal(t, int64(2000000), part2FileInfo.Size()) + require.Equal(t, int64(20000000), part2FileInfo.Size()) // Check the package data is correct pkgData := types.ZarfSplitPackageData{} part0File, err := os.ReadFile(parts[0]) diff --git a/src/test/packages/05-multi-part/zarf.yaml b/src/test/packages/05-multi-part/zarf.yaml index 78b47ba606..0fb4a75652 100644 --- a/src/test/packages/05-multi-part/zarf.yaml +++ b/src/test/packages/05-multi-part/zarf.yaml @@ -6,8 +6,11 @@ metadata: components: - name: big-ol-file required: true - description: Single 5 MB file needed to demonstrate a multi-part package + description: Include a 50 MB file needed to demonstrate a multi-part package + actions: + onCreate: + before: + - cmd: dd if=/dev/urandom of=multi-part-demo.dat bs=1048576 count=50 files: - - source: https://zarf-public.s3-us-gov-west-1.amazonaws.com/examples/multi-part-demo.dat - shasum: 22ebd38c2f5e04821c87c924c910be57d2169c292f85b2936d53cae24ebf8055 + - source: multi-part-demo.dat target: multi-part-demo.dat From 3157403d32e658616a36cc9abb792bdd03c3aba1 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 19 Feb 2024 15:29:10 -0700 Subject: [PATCH 04/15] dynamically make a 50MiB file (more performant than a download) --- src/test/e2e/05_tarball_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index 02715455cd..22d52d848a 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -24,7 +24,7 @@ func TestMultiPartPackage(t *testing.T) { var ( createPath = "src/test/packages/05-multi-part" deployPath = fmt.Sprintf("zarf-package-multi-part-%s.tar.zst.part000", e2e.Arch) - outputFile = "devops.stackexchange.com_en_all_2023-05.zim" + outputFile = "multi-part-demo.dat" ) e2e.CleanFiles(deployPath, outputFile) From 87794df9d101bde92b01e2d4fa5e3d1aca5ddff8 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 19 Feb 2024 15:52:08 -0700 Subject: [PATCH 05/15] close the file for windows file handlers --- src/pkg/packager/sources/split.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pkg/packager/sources/split.go b/src/pkg/packager/sources/split.go index 1aade2eee5..152e28a17b 100644 --- a/src/pkg/packager/sources/split.go +++ b/src/pkg/packager/sources/split.go @@ -85,6 +85,12 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) { if _, err = io.Copy(pkgFile, f); err != nil { return "", fmt.Errorf("unable to copy file %s: %w", file, err) } + + // Close the file when done copying + err = f.Close() + if err != nil { + return "", fmt.Errorf("unable to close file %s: %w", file, err) + } } if err := utils.SHAsMatch(reassembled, pkgData.Sha256Sum); err != nil { From 742378a2cd2e5e8d6ef5516f1086b49fae88b1c3 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Tue, 20 Feb 2024 17:10:07 -0700 Subject: [PATCH 06/15] fix: test fixes to the image push timeout --- src/internal/packager/images/push.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index bc0e3aa4a8..235a85d7b9 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -7,6 +7,7 @@ package images import ( "fmt" "net/http" + "time" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/cluster" @@ -50,6 +51,7 @@ func (i *ImageConfig) PushToZarfRegistry() error { httpTransport := http.DefaultTransport.(*http.Transport).Clone() httpTransport.TLSClientConfig.InsecureSkipVerify = i.Insecure + httpTransport.ResponseHeaderTimeout = 10 * time.Second progressBar := message.NewProgressBar(totalSize, fmt.Sprintf("Pushing %d images to the zarf registry", len(i.ImageList))) defer progressBar.Stop() craneTransport := utils.NewTransport(httpTransport, progressBar) From 9fef304eedc353a3c5dadfb9c75d3b3bf16eda5c Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Tue, 20 Feb 2024 17:12:29 -0700 Subject: [PATCH 07/15] fix test --- src/test/e2e/05_tarball_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index e0a04e5a5d..f6df5f7e1b 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -29,7 +29,6 @@ func TestMultiPartPackage(t *testing.T) { e2e.CleanFiles(deployPath, outputFile) - // Create the package with a max size of 20MB stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=20", "--confirm") require.NoError(t, err, stdOut, stdErr) From 1f07fef7d0e152933c00d8d4b74e1a93d10f2703 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Tue, 20 Feb 2024 18:23:57 -0700 Subject: [PATCH 08/15] add spinner to registry prune --- src/cmd/tools/crane.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index 80030fd361..1661f40f6b 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -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("Looking up images within package definitions") + defer spinner.Stop() + // Determine which image digests are currently used by Zarf packages pkgImages := map[string]bool{} for _, pkg := range zarfPackages { @@ -273,6 +276,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Updatef("Cataloging images in the registry") + // Find which images and tags are in the registry currently imageCatalog, err := crane.Catalog(registryEndpoint, authOption) if err != nil { @@ -295,6 +300,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Updatef("Calculating images to prune") + // Figure out which images are in the registry but not needed by packages imageDigestsToPrune := map[string]bool{} for digestRef, digest := range referenceToDigest { @@ -308,6 +315,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Success() + if len(imageDigestsToPrune) > 0 { message.Note(lang.CmdToolsRegistryPruneImageList) @@ -328,6 +337,9 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } if confirm { + spinner := message.NewProgressSpinner("Deleting unused images") + defer spinner.Stop() + // Delete the digest references that are to be pruned for digestRef := range imageDigestsToPrune { err = crane.Delete(digestRef, authOption) @@ -335,6 +347,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D return err } } + + spinner.Success() } } else { message.Note(lang.CmdToolsRegistryPruneNoImages) From 7518206e8efec669a9f41f60096e39c94b46ba01 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Tue, 20 Feb 2024 18:55:38 -0700 Subject: [PATCH 09/15] update messages to lang --- src/cmd/tools/crane.go | 8 ++++---- src/config/lang/english.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index 1661f40f6b..f1f1df6787 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -246,7 +246,7 @@ 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("Looking up images within package definitions") + spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneLookup) defer spinner.Stop() // Determine which image digests are currently used by Zarf packages @@ -276,7 +276,7 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } - spinner.Updatef("Cataloging images in the registry") + spinner.Updatef(lang.CmdToolsRegistryPruneCatalog) // Find which images and tags are in the registry currently imageCatalog, err := crane.Catalog(registryEndpoint, authOption) @@ -300,7 +300,7 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } - spinner.Updatef("Calculating images to prune") + spinner.Updatef(lang.CmdToolsRegistryPruneCalculate) // Figure out which images are in the registry but not needed by packages imageDigestsToPrune := map[string]bool{} @@ -337,7 +337,7 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } if confirm { - spinner := message.NewProgressSpinner("Deleting unused images") + spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneDelete) defer spinner.Stop() // Delete the digest references that are to be pruned diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 6a666474d7..14e3b19887 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -455,6 +455,10 @@ $ zarf tools registry digest reg.example.com/stefanprodan/podinfo:6.4.0 CmdToolsRegistryPruneFlagConfirm = "Confirm the image prune action to prevent accidental deletions" CmdToolsRegistryPruneImageList = "The following image digests will be pruned from the registry:" CmdToolsRegistryPruneNoImages = "There are no images to prune" + CmdToolsRegistryPruneLookup = "Looking up images within package definitions" + CmdToolsRegistryPruneCatalog = "Cataloging images in the registry" + CmdToolsRegistryPruneCalculate = "Calculating images to prune" + CmdToolsRegistryPruneDelete = "Deleting unused images" CmdToolsRegistryInvalidPlatformErr = "Invalid platform '%s': %s" CmdToolsRegistryFlagVerbose = "Enable debug logs" From 8ea6fe452a2e8f9b76952bedc262683d6edd7cd7 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 11:38:04 -0700 Subject: [PATCH 10/15] fix remaining codeql issues --- src/cmd/tools/common.go | 2 +- src/cmd/tools/crane.go | 2 +- src/cmd/tools/helm/repo_index.go | 4 ++-- src/cmd/tools/helm/repo_list.go | 2 +- src/cmd/tools/helm/repo_update.go | 4 ++-- src/cmd/tools/kubectl.go | 2 +- src/cmd/tools/wait.go | 2 +- src/cmd/tools/zarf.go | 12 ++++++------ src/internal/agent/http/proxy.go | 2 +- src/internal/agent/http/server.go | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cmd/tools/common.go b/src/cmd/tools/common.go index 81d33af4ec..d0fa000e86 100644 --- a/src/cmd/tools/common.go +++ b/src/cmd/tools/common.go @@ -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 diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index f1f1df6787..c0a521c153 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -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() diff --git a/src/cmd/tools/helm/repo_index.go b/src/cmd/tools/helm/repo_index.go index 79f941e79a..ab6b2845f5 100644 --- a/src/cmd/tools/helm/repo_index.go +++ b/src/cmd/tools/helm/repo_index.go @@ -58,7 +58,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { Short: "generate an index file given a directory containing packaged charts", Long: repoIndexDesc, Args: require.ExactArgs(1), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { // Allow file completion when completing the argument for the directory return nil, cobra.ShellCompDirectiveDefault @@ -66,7 +66,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { // No more completions, so disable file completion return nil, cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.dir = args[0] return o.run(out) }, diff --git a/src/cmd/tools/helm/repo_list.go b/src/cmd/tools/helm/repo_list.go index 02b4e34d86..7bf65bc95f 100644 --- a/src/cmd/tools/helm/repo_list.go +++ b/src/cmd/tools/helm/repo_list.go @@ -41,7 +41,7 @@ func newRepoListCmd(out io.Writer) *cobra.Command { Aliases: []string{"ls"}, Short: "list chart repositories", Args: require.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { f, _ := repo.LoadFile(settings.RepositoryConfig) if len(f.Repositories) == 0 && !(outfmt == output.JSON || outfmt == output.YAML) { return errors.New("no repositories to show") diff --git a/src/cmd/tools/helm/repo_update.go b/src/cmd/tools/helm/repo_update.go index c74d1eae75..92f82e261e 100644 --- a/src/cmd/tools/helm/repo_update.go +++ b/src/cmd/tools/helm/repo_update.go @@ -62,10 +62,10 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command { Short: "update information of available charts locally from chart repositories", Long: updateDesc, Args: require.MinimumNArgs(0), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return compListRepos(toComplete, args), cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.repoFile = settings.RepositoryConfig o.repoCache = settings.RepositoryCache o.names = args diff --git a/src/cmd/tools/kubectl.go b/src/cmd/tools/kubectl.go index ab9f16e920..e9eb820ff5 100644 --- a/src/cmd/tools/kubectl.go +++ b/src/cmd/tools/kubectl.go @@ -22,7 +22,7 @@ func init() { // Kubectl stub command. kubectlCmd := &cobra.Command{ Short: lang.CmdToolsKubectlDocs, - Run: func(cmd *cobra.Command, args []string) {}, + Run: func(_ *cobra.Command, _ []string) {}, } // Only load this command if it is being called directly. diff --git a/src/cmd/tools/wait.go b/src/cmd/tools/wait.go index 183fd226e8..9977c58011 100644 --- a/src/cmd/tools/wait.go +++ b/src/cmd/tools/wait.go @@ -28,7 +28,7 @@ var waitForCmd = &cobra.Command{ Long: lang.CmdToolsWaitForLong, Example: lang.CmdToolsWaitForExample, Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { // Parse the timeout string timeout, err := time.ParseDuration(waitTimeout) if err != nil { diff --git a/src/cmd/tools/zarf.go b/src/cmd/tools/zarf.go index 27cc36da6a..f0820962f8 100644 --- a/src/cmd/tools/zarf.go +++ b/src/cmd/tools/zarf.go @@ -35,7 +35,7 @@ var deprecatedGetGitCredsCmd = &cobra.Command{ Hidden: true, Short: lang.CmdToolsGetGitPasswdShort, Long: lang.CmdToolsGetGitPasswdLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { message.Warn(lang.CmdToolsGetGitPasswdDeprecation) getCredsCmd.Run(getCredsCmd, []string{"git"}) }, @@ -48,7 +48,7 @@ var getCredsCmd = &cobra.Command{ Example: lang.CmdToolsGetCredsExample, Aliases: []string{"gc"}, Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { state, err := cluster.NewClusterOrDie().LoadZarfState() if err != nil || state.Distro == "" { // If no distro the zarf secret did not load properly @@ -168,7 +168,7 @@ var clearCacheCmd = &cobra.Command{ Use: "clear-cache", Aliases: []string{"c"}, Short: lang.CmdToolsClearCacheShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { message.Notef(lang.CmdToolsClearCacheDir, config.GetAbsCachePath()) if err := os.RemoveAll(config.GetAbsCachePath()); err != nil { message.Fatalf(err, lang.CmdToolsClearCacheErr, config.GetAbsCachePath()) @@ -180,7 +180,7 @@ var clearCacheCmd = &cobra.Command{ var downloadInitCmd = &cobra.Command{ Use: "download-init", Short: lang.CmdToolsDownloadInitShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { url := oci.GetInitPackageURL(config.CLIVersion) remote, err := oci.NewOrasRemote(url, oci.PlatformForArch(config.GetArch())) @@ -202,7 +202,7 @@ var generatePKICmd = &cobra.Command{ Aliases: []string{"pki"}, Short: lang.CmdToolsGenPkiShort, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pki := pki.GeneratePKI(args[0], subAltNames...) if err := os.WriteFile("tls.ca", pki.CA, 0644); err != nil { message.Fatalf(err, lang.ErrWritingFile, "tls.ca", err.Error()) @@ -221,7 +221,7 @@ var generateKeyCmd = &cobra.Command{ Use: "gen-key", Aliases: []string{"key"}, Short: lang.CmdToolsGenKeyShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Utility function to prompt the user for the password to the private key passwordFunc := func(bool) ([]byte, error) { // perform the first prompt diff --git a/src/internal/agent/http/proxy.go b/src/internal/agent/http/proxy.go index b805d53564..ea0a54f024 100644 --- a/src/internal/agent/http/proxy.go +++ b/src/internal/agent/http/proxy.go @@ -30,7 +30,7 @@ func ProxyHandler() http.HandlerFunc { return } - proxy := &httputil.ReverseProxy{Director: func(r *http.Request) {}, ModifyResponse: proxyResponseTransform} + proxy := &httputil.ReverseProxy{Director: func(_ *http.Request) {}, ModifyResponse: proxyResponseTransform} proxy.ServeHTTP(w, r) } } diff --git a/src/internal/agent/http/server.go b/src/internal/agent/http/server.go index aa86133d85..4087308d3a 100644 --- a/src/internal/agent/http/server.go +++ b/src/internal/agent/http/server.go @@ -55,7 +55,7 @@ func NewProxyServer(port string) *http.Server { } func healthz() http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("ok")) } From 998cc9aa188f0486b04c3693da93ff41f6478296 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 11:48:17 -0700 Subject: [PATCH 11/15] fix remaining codeql issues --- src/cmd/tools/helm/dependency.go | 2 +- src/cmd/tools/helm/dependency_build.go | 2 +- src/cmd/tools/helm/dependency_update.go | 2 +- src/cmd/tools/helm/flags.go | 2 +- src/cmd/tools/helm/load_plugins.go | 2 +- src/cmd/tools/helm/repo_remove.go | 4 ++-- src/cmd/tools/helm/root.go | 4 ++-- src/cmd/tools/k9s.go | 2 +- src/internal/packager/images/pull.go | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmd/tools/helm/dependency.go b/src/cmd/tools/helm/dependency.go index b96d1e39b2..4ab004b036 100644 --- a/src/cmd/tools/helm/dependency.go +++ b/src/cmd/tools/helm/dependency.go @@ -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]) diff --git a/src/cmd/tools/helm/dependency_build.go b/src/cmd/tools/helm/dependency_build.go index 0e84e244bb..618c137174 100644 --- a/src/cmd/tools/helm/dependency_build.go +++ b/src/cmd/tools/helm/dependency_build.go @@ -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]) diff --git a/src/cmd/tools/helm/dependency_update.go b/src/cmd/tools/helm/dependency_update.go index 86c9f48de3..f069b7f59d 100644 --- a/src/cmd/tools/helm/dependency_update.go +++ b/src/cmd/tools/helm/dependency_update.go @@ -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]) diff --git a/src/cmd/tools/helm/flags.go b/src/cmd/tools/helm/flags.go index d567d920ec..d0130a6fb1 100644 --- a/src/cmd/tools/helm/flags.go +++ b/src/cmd/tools/helm/flags.go @@ -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)) diff --git a/src/cmd/tools/helm/load_plugins.go b/src/cmd/tools/helm/load_plugins.go index 6890f52edc..39edb9c3d9 100644 --- a/src/cmd/tools/helm/load_plugins.go +++ b/src/cmd/tools/helm/load_plugins.go @@ -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) diff --git a/src/cmd/tools/helm/repo_remove.go b/src/cmd/tools/helm/repo_remove.go index 61340f8a49..13110072cd 100644 --- a/src/cmd/tools/helm/repo_remove.go +++ b/src/cmd/tools/helm/repo_remove.go @@ -49,10 +49,10 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command { Aliases: []string{"rm"}, Short: "remove one or more chart repositories", Args: require.MinimumNArgs(1), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return compListRepos(toComplete, args), cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.repoFile = settings.RepositoryConfig o.repoCache = settings.RepositoryCache o.names = args diff --git a/src/cmd/tools/helm/root.go b/src/cmd/tools/helm/root.go index 63b9bf8f17..e496a93cec 100644 --- a/src/cmd/tools/helm/root.go +++ b/src/cmd/tools/helm/root.go @@ -105,7 +105,7 @@ func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string addKlogFlags(flags) // Setup shell completion for the namespace flag - err := cmd.RegisterFlagCompletionFunc("namespace", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + err := cmd.RegisterFlagCompletionFunc("namespace", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { if client, err := actionConfig.KubernetesClientSet(); err == nil { // Choose a long enough timeout that the user notices something is not working // but short enough that the user is not made to wait very long @@ -128,7 +128,7 @@ func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string } // Setup shell completion for the kube-context flag - err = cmd.RegisterFlagCompletionFunc("kube-context", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + err = cmd.RegisterFlagCompletionFunc("kube-context", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { cobra.CompDebugln("About to get the different kube-contexts", settings.Debug) loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() diff --git a/src/cmd/tools/k9s.go b/src/cmd/tools/k9s.go index d38992ead9..ceabe6a547 100644 --- a/src/cmd/tools/k9s.go +++ b/src/cmd/tools/k9s.go @@ -23,7 +23,7 @@ func init() { Use: "monitor", Aliases: []string{"m", "k9s"}, Short: lang.CmdToolsMonitorShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Hack to make k9s think it's all alone os.Args = []string{os.Args[0]} k9s.Execute() diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 160c0d506a..92ed0d5775 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -379,7 +379,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) { }() } - onImageSavingProgress := func(finishedImage digestInfo, iteration int) { + onImageSavingProgress := func(finishedImage digestInfo, _ int) { referenceToDigest[finishedImage.refInfo.Reference] = finishedImage.digest } From b9c6b52e717e60920ae175172e98e246cf5f102d Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 11:52:21 -0700 Subject: [PATCH 12/15] fix remaining codeql issues --- src/cmd/destroy.go | 2 +- src/cmd/initialize.go | 2 +- src/cmd/internal.go | 20 ++++++++++---------- src/cmd/tools/archiver.go | 4 ++-- src/cmd/tools/helm/repo_add.go | 2 +- src/cmd/tools/helm/repo_index.go | 2 +- src/pkg/transform/git_test.go | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cmd/destroy.go b/src/cmd/destroy.go index be3ffbe2a9..0a60d05503 100644 --- a/src/cmd/destroy.go +++ b/src/cmd/destroy.go @@ -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) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 192fb961e0..906f484720 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -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) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index a10067398c..68e512d1c6 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -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() }, } @@ -46,7 +46,7 @@ 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() }, } @@ -54,7 +54,7 @@ var httpProxyCmd = &cobra.Command{ 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 @@ -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 { @@ -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 { @@ -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 { @@ -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() @@ -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) @@ -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) @@ -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) diff --git a/src/cmd/tools/archiver.go b/src/cmd/tools/archiver.go index e392b8c3ad..b6110b7a18 100644 --- a/src/cmd/tools/archiver.go +++ b/src/cmd/tools/archiver.go @@ -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 { @@ -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 { diff --git a/src/cmd/tools/helm/repo_add.go b/src/cmd/tools/helm/repo_add.go index ce2e236267..d167adc3fc 100644 --- a/src/cmd/tools/helm/repo_add.go +++ b/src/cmd/tools/helm/repo_add.go @@ -76,7 +76,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command { Use: "add [NAME] [URL]", Short: "add a chart repository", Args: require.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.name = args[0] o.url = args[1] o.repoFile = settings.RepositoryConfig diff --git a/src/cmd/tools/helm/repo_index.go b/src/cmd/tools/helm/repo_index.go index ab6b2845f5..1770cedcf9 100644 --- a/src/cmd/tools/helm/repo_index.go +++ b/src/cmd/tools/helm/repo_index.go @@ -58,7 +58,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { Short: "generate an index file given a directory containing packaged charts", Long: repoIndexDesc, Args: require.ExactArgs(1), - ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { // Allow file completion when completing the argument for the directory return nil, cobra.ShellCompDirectiveDefault diff --git a/src/pkg/transform/git_test.go b/src/pkg/transform/git_test.go index 0bee04260d..70145275aa 100644 --- a/src/pkg/transform/git_test.go +++ b/src/pkg/transform/git_test.go @@ -44,7 +44,7 @@ var badGitURLs = []string{ } func TestMutateGitURLsInText(t *testing.T) { - dummyLogger := func(content string, args ...any) {} + dummyLogger := func(_ string, _ ...any) {} originalText := ` # Here we handle invalid URLs (see below comment) # We transform https://*/*.git URLs From af9277fbcb2f07bcabe7361ed47c71e254a9da7c Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 11:57:49 -0700 Subject: [PATCH 13/15] fix remaining codeql issues --- src/cmd/connect.go | 4 ++-- src/cmd/package.go | 16 ++++++++-------- src/cmd/root.go | 2 +- src/cmd/version.go | 4 ++-- src/pkg/k8s/common.go | 2 +- src/pkg/packager/sources/validate.go | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cmd/connect.go b/src/cmd/connect.go index 73fab7665a..fe3442e395 100644 --- a/src/cmd/connect.go +++ b/src/cmd/connect.go @@ -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] @@ -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() }, } diff --git a/src/cmd/package.go b/src/cmd/package.go index 1ccd3e3061..3e29b74b64 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -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\_\-\/\.\~\\:]+$`) @@ -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 @@ -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 @@ -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() @@ -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 { @@ -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() @@ -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]) { @@ -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 diff --git a/src/cmd/root.go b/src/cmd/root.go index 3d5660e8a2..9563f382d3 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -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 diff --git a/src/cmd/version.go b/src/cmd/version.go index 18984a6e82..1daa7af61f 100644 --- a/src/cmd/version.go +++ b/src/cmd/version.go @@ -24,12 +24,12 @@ var outputFormat string var versionCmd = &cobra.Command{ Use: "version", Aliases: []string{"v"}, - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(_ *cobra.Command, _ []string) { config.SkipLogFile = true }, Short: lang.CmdVersionShort, Long: lang.CmdVersionLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { output := make(map[string]interface{}) buildInfo, ok := debug.ReadBuildInfo() diff --git a/src/pkg/k8s/common.go b/src/pkg/k8s/common.go index bb678050e4..d11be666d2 100644 --- a/src/pkg/k8s/common.go +++ b/src/pkg/k8s/common.go @@ -22,7 +22,7 @@ import ( // New creates a new K8s client. func New(logger Log, defaultLabels Labels) (*K8s, error) { - klog.SetLogger(funcr.New(func(prefix, args string) { + klog.SetLogger(funcr.New(func(_, args string) { logger(args) }, funcr.Options{})) diff --git a/src/pkg/packager/sources/validate.go b/src/pkg/packager/sources/validate.go index 2e06f85056..38e4581b0a 100644 --- a/src/pkg/packager/sources/validate.go +++ b/src/pkg/packager/sources/validate.go @@ -157,7 +157,7 @@ func pathCheckMap(dir string) (map[string]bool, error) { return nil } filepathMap[path] = false - return nil + return err }) return filepathMap, err } From d33fa76b019990d7d1bb661e1f507559193652da Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 12:00:24 -0700 Subject: [PATCH 14/15] fix remaining codeql issues --- src/cmd/dev.go | 12 ++++++------ src/pkg/packager/common_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 63426692ea..bccac8b781 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -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() @@ -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 @@ -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 @@ -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) @@ -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 @@ -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( diff --git a/src/pkg/packager/common_test.go b/src/pkg/packager/common_test.go index 690837f6c3..105daf0242 100644 --- a/src/pkg/packager/common_test.go +++ b/src/pkg/packager/common_test.go @@ -104,7 +104,7 @@ func TestValidatePackageArchitecture(t *testing.T) { } // Set up test data for fetching cluster architecture. - mockClient.Fake.PrependReactor("list", "nodes", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) { + mockClient.Fake.PrependReactor("list", "nodes", func(_ k8sTesting.Action) (bool, runtime.Object, error) { // Return an error for cases that test this error path. if testCase.getArchError != nil { return true, nil, testCase.getArchError From 503dfa51d9f5539dc16546d16de23088a7155056 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 12:56:48 -0700 Subject: [PATCH 15/15] clean PR --- src/cmd/tools/crane.go | 14 -------------- src/config/lang/english.go | 4 ---- src/internal/packager/images/push.go | 2 -- 3 files changed, 20 deletions(-) diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index c0a521c153..6d0919067d 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -246,9 +246,6 @@ 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 { @@ -276,8 +273,6 @@ 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 { @@ -300,8 +295,6 @@ 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 { @@ -315,8 +308,6 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } - spinner.Success() - if len(imageDigestsToPrune) > 0 { message.Note(lang.CmdToolsRegistryPruneImageList) @@ -337,9 +328,6 @@ 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) @@ -347,8 +335,6 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D return err } } - - spinner.Success() } } else { message.Note(lang.CmdToolsRegistryPruneNoImages) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 14e3b19887..6a666474d7 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -455,10 +455,6 @@ $ zarf tools registry digest reg.example.com/stefanprodan/podinfo:6.4.0 CmdToolsRegistryPruneFlagConfirm = "Confirm the image prune action to prevent accidental deletions" CmdToolsRegistryPruneImageList = "The following image digests will be pruned from the registry:" CmdToolsRegistryPruneNoImages = "There are no images to prune" - CmdToolsRegistryPruneLookup = "Looking up images within package definitions" - CmdToolsRegistryPruneCatalog = "Cataloging images in the registry" - CmdToolsRegistryPruneCalculate = "Calculating images to prune" - CmdToolsRegistryPruneDelete = "Deleting unused images" CmdToolsRegistryInvalidPlatformErr = "Invalid platform '%s': %s" CmdToolsRegistryFlagVerbose = "Enable debug logs" diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index 235a85d7b9..bc0e3aa4a8 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -7,7 +7,6 @@ package images import ( "fmt" "net/http" - "time" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/pkg/cluster" @@ -51,7 +50,6 @@ func (i *ImageConfig) PushToZarfRegistry() error { httpTransport := http.DefaultTransport.(*http.Transport).Clone() httpTransport.TLSClientConfig.InsecureSkipVerify = i.Insecure - httpTransport.ResponseHeaderTimeout = 10 * time.Second progressBar := message.NewProgressBar(totalSize, fmt.Sprintf("Pushing %d images to the zarf registry", len(i.ImageList))) defer progressBar.Stop() craneTransport := utils.NewTransport(httpTransport, progressBar)