-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow to process GCS File in Profile Section #9864
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
base: main
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @ashokhein, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances Skaffold's Helm deployer to support referencing Helm values files stored in Google Cloud Storage (GCS) buckets, specifically when defined within Skaffold's profile sections. This allows for centralized management of environment-specific configurations by automatically downloading GCS-hosted value files before Helm commands are executed.
Highlights
- GCS Support in Helm Profiles: Skaffold now processes GCS object references (e.g., gs://bucket/file.yaml) within Helm --values flags and valuesFiles defined in profiles sections of skaffold.yaml.
- Automated GCS File Resolution: The system automatically detects GCS URLs, downloads the files to temporary local paths, and passes these local paths to Helm commands, cleaning up afterwards.
- Documentation Updates: Comprehensive documentation has been added to the Helm deployer and profiles sections, providing clear examples for using GCS references.
- Code Refactoring for Reusability: The internal extractValueFileFromGCS function has been made public (ExtractValueFileFromGCS) to facilitate its reuse across different parts of the codebase.
- New GCS Flag Processing Logic: A new function processGCSFlags was introduced to specifically handle GCS URLs embedded within Helm --values or -f flags.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a valuable feature by allowing GCS file references in Helm profile patches, and the core logic and documentation updates look good. However, my main concern is the introduction of resource leaks. Both the new processGCSFlags
function and the modified ConstructOverrideArgs
create temporary directories that are never cleaned up, which will lead to an accumulation of files on the user's machine. I've flagged these as high-severity issues. Additionally, I've noted some minor issues in the documentation and tests that should be addressed for better code quality. Once the resource leaks are fixed, this will be a solid contribution.
func processGCSFlags(flags []string) ([]string, error) { | ||
if len(flags) == 0 { | ||
return flags, nil | ||
} | ||
|
||
var processedFlags []string | ||
gcs := gcs.NewGsutil() | ||
|
||
for i := 0; i < len(flags); i++ { | ||
flag := flags[i] | ||
|
||
// Check for --values flag with equals sign (--values=gs://...) | ||
if strings.HasPrefix(flag, "--values=") { | ||
value := strings.TrimPrefix(flag, "--values=") | ||
if strings.HasPrefix(value, "gs://") { | ||
tempDir, err := os.MkdirTemp("", "helm_values_from_gcs") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create temp directory: %w", err) | ||
} | ||
processedValue, err := extractValueFileFromGCSFunc(value, tempDir, gcs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
processedFlags = append(processedFlags, "--values="+processedValue) | ||
} else { | ||
processedFlags = append(processedFlags, flag) | ||
} | ||
} else if flag == "--values" || flag == "-f" { | ||
// Check for --values flag with separate argument (--values gs://... or -f gs://...) | ||
if i+1 < len(flags) { | ||
nextFlag := flags[i+1] | ||
if strings.HasPrefix(nextFlag, "gs://") { | ||
tempDir, err := os.MkdirTemp("", "helm_values_from_gcs") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create temp directory: %w", err) | ||
} | ||
processedValue, err := extractValueFileFromGCSFunc(nextFlag, tempDir, gcs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
processedFlags = append(processedFlags, flag, processedValue) | ||
i++ // Skip the next flag since we processed it | ||
} else { | ||
processedFlags = append(processedFlags, flag, nextFlag) | ||
i++ | ||
} | ||
} else { | ||
processedFlags = append(processedFlags, flag) | ||
} | ||
} else { | ||
processedFlags = append(processedFlags, flag) | ||
} | ||
} | ||
|
||
return processedFlags, nil | ||
} |
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.
The function processGCSFlags
creates temporary directories using os.MkdirTemp
for each GCS values file, but it doesn't arrange for them to be cleaned up. This will result in a resource leak, as temporary directories will accumulate on the user's machine. These directories should be cleaned up after the helm
command that uses them has finished.
A common pattern in Skaffold is to have the Deployer
manage the cleanup of temporary resources. I recommend modifying processGCSFlags
to return the paths of all temporary directories it creates. The caller (installArgs
) can then add these to a list on the Deployer
, and the Deployer.Cleanup
method can be updated to remove them.
tempDir, err := os.MkdirTemp("", valueFileFromGCS) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create the tmp directory: %w", err) | ||
} |
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.
A temporary directory is created here with os.MkdirTemp
but is never cleaned up. This will lead to a resource leak on the user's machine. This appears to be a pre-existing issue, but since this code block is modified, it's a good opportunity to fix it. The caller of ConstructOverrideArgs
should be made responsible for cleaning up these directories after they are no longer needed. This might require ConstructOverrideArgs
to return the list of temporary directories it creates, similar to the suggestion for processGCSFlags
.
|
||
# Or add GCS reference as --values flag | ||
- op: add | ||
path: /deploy/helm/flags/install/- | ||
value: "--values=gs://my-config-bucket/prod-values.yaml" | ||
- op: add | ||
path: /deploy/helm/flags/upgrade/- | ||
value: "--values=gs://my-config-bucket/prod-values.yaml" | ||
|
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.
There are some minor formatting issues in this YAML example, such as trailing whitespace on empty lines and extra spaces. Cleaning this up will improve the readability and consistency of the documentation.
# Or add GCS reference as --values flag | |
- op: add | |
path: /deploy/helm/flags/install/- | |
value: "--values=gs://my-config-bucket/prod-values.yaml" | |
- op: add | |
path: /deploy/helm/flags/upgrade/- | |
value: "--values=gs://my-config-bucket/prod-values.yaml" | |
# Or add GCS reference as --values flag | |
- op: add | |
path: /deploy/helm/flags/install/- | |
value: "--values=gs://my-config-bucket/prod-values.yaml" | |
- op: add | |
path: /deploy/helm/flags/upgrade/- | |
value: "--values=gs://my-config-bucket/prod-values.yaml" | |
if !strings.HasPrefix(value, "/") || !strings.HasSuffix(value, ".yaml") { | ||
t.Errorf("expected temp file path, got: %s", value) | ||
} | ||
} else if expectedFlag == "/tmp/test-file.yaml" { | ||
// For separate flags, check that it's a temp file path | ||
if !strings.HasPrefix(flag, "/") || !strings.HasSuffix(flag, ".yaml") { | ||
t.Errorf("expected temp file path, got: %s", flag) | ||
} |
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.
Description
We are now processing GCS Object/Value File references during the deploy step. To support this, the envTemplate logic has been rearranged so that environment variables are resolved before extracting GCS files.
However, the previous approach did not work for --values= references defined in the Profile section. To fix this, new code has been added to handle GCS references there as well.
This will convert to the following Helm Args
helm --kube-context gke_xx_b3 install release-xxx-backend --values=/var/folders/zd/js5hcjy968b_j_3zn9bt3r9m0000gp/T/helm_values_from_gcs1737245839/infra.yaml