generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 162
files: improve error for uncompressed Helm .tar archives #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bashSunny101
wants to merge
3
commits into
meshery:master
Choose a base branch
from
bashSunny101:fix/helm-uncompressed-tar-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ var ( | |||||
| ErrInvalidHelmChartCode = "meshkit-11292" | ||||||
| ErrInvalidDockerComposeCode = "meshkit-11293" | ||||||
| ErrInvalidKustomizationCode = "meshkit-11294" | ||||||
| ErrUncompressedTarCode = "meshkit-11305" | ||||||
| ErrFileTypeNotSupportedForDesignConversionCode = "meshkit-11300" | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -260,6 +261,22 @@ func ErrInvalidHelmChart(fileName string, err error) error { | |||||
| return errors.New(ErrInvalidHelmChartCode, errors.Critical, sdescription, ldescription, probableCause, remedy) | ||||||
| } | ||||||
|
|
||||||
| // ErrUncompressedTar returns an error explaining that Helm requires | ||||||
| // compressed tarballs (tgz / tar.gz) and that an uncompressed .tar was provided. | ||||||
| func ErrUncompressedTar(fileName string, err error) error { | ||||||
| return errors.New( | ||||||
| ErrUncompressedTarCode, | ||||||
| errors.Critical, | ||||||
| []string{fmt.Sprintf("The file '%s' appears to be an uncompressed TAR archive.", fileName)}, | ||||||
| []string{fmt.Sprintf("Helm expects chart archives to be compressed (e.g., .tgz or .tar.gz). Error details: %s", err.Error())}, | ||||||
| []string{"The archive was created as an uncompressed .tar, but Helm requires compressed archives."}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| []string{ | ||||||
| "Compress the .tar file to .tgz or .tar.gz and try again.", | ||||||
| "Create the Helm chart archive using 'helm package' or gzip the archive before uploading.", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| }, | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| func ErrInvalidDockerCompose(fileName string, err error) error { | ||||||
| sdescription := []string{ | ||||||
| fmt.Sprintf("The file '%s' is not a valid Docker Compose file.", fileName), | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||||
| package files_test | ||||||||||
|
|
||||||||||
| import ( | ||||||||||
| "archive/tar" | ||||||||||
| "bytes" | ||||||||||
| "os" | ||||||||||
| "path/filepath" | ||||||||||
| "testing" | ||||||||||
|
|
@@ -192,3 +194,55 @@ func TestSanitizeFile(t *testing.T) { | |||||||||
| }) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Test that providing an uncompressed .tar containing a Helm chart yields the | ||||||||||
| // helpful ErrUncompressedTarProvided (which uses ErrInvalidHelmChartCode). | ||||||||||
| func TestUncompressedHelmTarError(t *testing.T) { | ||||||||||
| // Build an in-memory uncompressed tar with a Chart.yaml | ||||||||||
| var buf bytes.Buffer | ||||||||||
| tw := tar.NewWriter(&buf) | ||||||||||
| chartYAML := []byte("apiVersion: v2\nname: test-chart\nversion: 0.1.0\n") | ||||||||||
| hdr := &tar.Header{ | ||||||||||
| Name: "Chart.yaml", | ||||||||||
| Mode: 0600, | ||||||||||
| Size: int64(len(chartYAML)), | ||||||||||
| } | ||||||||||
| if err := tw.WriteHeader(hdr); err != nil { | ||||||||||
| t.Fatalf("failed to write tar header: %v", err) | ||||||||||
| } | ||||||||||
| if _, err := tw.Write(chartYAML); err != nil { | ||||||||||
| t.Fatalf("failed to write chart content: %v", err) | ||||||||||
| } | ||||||||||
| if err := tw.Close(); err != nil { | ||||||||||
| t.Fatalf("failed to close tar writer: %v", err) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| tempDir, err := os.MkdirTemp("", "temp-tests") | ||||||||||
| if err != nil { | ||||||||||
| t.Fatalf("failed to create temp directory: %v", err) | ||||||||||
| } | ||||||||||
| defer os.RemoveAll(tempDir) | ||||||||||
|
|
||||||||||
| validExts := map[string]bool{ | ||||||||||
| ".json": true, | ||||||||||
| ".yml": true, | ||||||||||
| ".yaml": true, | ||||||||||
| ".tar": true, | ||||||||||
| ".tgz": true, | ||||||||||
| ".gz": true, | ||||||||||
| ".zip": true, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| sanitized, err := files.SanitizeFile(buf.Bytes(), "uncompressed-helm.tar", tempDir, validExts) | ||||||||||
| if err != nil { | ||||||||||
| t.Fatalf("unexpected sanitize error: %v", err) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| _, err = files.ParseFileAsHelmChart(sanitized) | ||||||||||
| if err == nil { | ||||||||||
| t.Fatalf("expected error when parsing uncompressed tar as helm chart, got nil") | ||||||||||
| } | ||||||||||
| if errors.GetCode(err) != files.ErrUncompressedTarCode { | ||||||||||
| t.Fatalf("expected error code %s, got %s (err: %v)", files.ErrUncompressedTarCode, errors.GetCode(err), err) | ||||||||||
|
Comment on lines
+245
to
+246
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
| } | ||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.