Skip to content
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

feat: allow ValuesFile from GCS #9182

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pkg/skaffold/helm/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package helm
import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
Expand All @@ -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) {
Expand Down Expand Up @@ -86,7 +95,25 @@ func ConstructOverrideArgs(r *latest.HelmRelease, builds []graph.Artifact, args
}

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) {
Copy link
Contributor

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

Copy link
Author

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.

tempDir, err := os.MkdirTemp("", valueFileFromGCS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition's body can be extracted for better readability

Copy link
Author

Choose a reason for hiding this comment

The 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)
}

//get a filename from gcs
tempValueFile = filepath.Join(tempDir, path.Base(v))

gcs := gcs.Gsutil{}
if err := gcs.Copy(context.Background(), v, tempValueFile, false); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why context.Background(), but not TODO()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to TODO() as it requires the context temporarily

return nil, fmt.Errorf("failed to copy valuesFile from GCS: %w", err)
}
}

exp, err := homedir.Expand(tempValueFile)
if err != nil {
return nil, fmt.Errorf("unable to expand %q: %w", v, err)
}
Expand Down