-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: allow ValuesFile from GCS #9182
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da9aa04
feat: allow ValuesFile from GCS
ashokhein a9af349
Merge branch 'GoogleContainerTools:main' into main
ashokhein 1bab52c
Merge branch 'GoogleContainerTools:main' into main
ashokhein ce8b80c
added extracted gcs function
ashokhein aa78d3b
Merge branch 'GoogleContainerTools:main' into main
ashokhein 0d1f8bc
added test cases for copy gcs func
ashokhein 1608c21
only create an tmp directory for gcs file
ashokhein 9180d22
fixed formatting
ashokhein 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
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 |
---|---|---|
|
@@ -19,6 +19,9 @@ package helm | |
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
"strconv" | ||
"strings" | ||
|
@@ -27,13 +30,19 @@ import ( | |
|
||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/constants" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/gcs" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util" | ||
maps "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util/map" | ||
) | ||
|
||
const ( | ||
gcsPrefix = "gs://" | ||
valueFileFromGCS = "valuefiles_from_gcs" | ||
) | ||
|
||
// ConstructOverrideArgs creates the command line arguments for overrides | ||
func ConstructOverrideArgs(r *latest.HelmRelease, builds []graph.Artifact, args []string, manifestOverrides map[string]string) ([]string, error) { | ||
for _, k := range maps.SortKeys(r.SetValues) { | ||
|
@@ -85,8 +94,26 @@ func ConstructOverrideArgs(r *latest.HelmRelease, builds []graph.Artifact, args | |
args = append(args, "--set", fmt.Sprintf("%s=%s", expandedKey, v)) | ||
} | ||
|
||
gcs := gcs.NewGsutil() | ||
|
||
for _, v := range r.ValuesFiles { | ||
exp, err := homedir.Expand(v) | ||
tempValueFile := v | ||
|
||
// if the file starts with gs:// then download it in tmp dir | ||
if strings.HasPrefix(v, gcsPrefix) { | ||
tempDir, err := os.MkdirTemp("", valueFileFromGCS) | ||
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. the condition's body can be extracted for better readability 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. Thanks for the suggestion, yes separated to the new function. |
||
if err != nil { | ||
return nil, fmt.Errorf("failed to create the tmp directory: %w", err) | ||
} | ||
|
||
if extractedFilePath, err := extractValueFileFromGCS(v, tempDir, gcs); err != nil { | ||
return nil, err | ||
} else { | ||
tempValueFile = extractedFilePath | ||
} | ||
} | ||
|
||
exp, err := homedir.Expand(tempValueFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to expand %q: %w", v, err) | ||
} | ||
|
@@ -151,3 +178,15 @@ func envVarForImage(imageName string, digest string) map[string]string { | |
customMap["IMAGE_FULLY_QUALIFIED"] = digest | ||
return customMap | ||
} | ||
|
||
// Copy the value file from the GCS bucket if it starts with gs:// | ||
func extractValueFileFromGCS(v, tempDir string, gcs gcs.Gsutil) (string, error) { | ||
// get a filename from gcs | ||
tempValueFile := filepath.Join(tempDir, path.Base(v)) | ||
|
||
if err := gcs.Copy(context.TODO(), v, tempValueFile, false); err != nil { | ||
return "", fmt.Errorf("failed to copy valuesFile from GCS: %w", err) | ||
} | ||
|
||
return tempValueFile, nil | ||
} |
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
Oops, something went wrong.
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.
it looks like it'll be better to contribute to the helm repository
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.
Skaffold has already been integrated with GCP, so I thought to make the change here.