diff --git a/util/config/reader.go b/util/config/reader.go index c8b93c1c68fa7..d2891eba1dbb4 100644 --- a/util/config/reader.go +++ b/util/config/reader.go @@ -52,7 +52,7 @@ func UnmarshalLocalFile(path string, obj interface{}) error { // UnmarshalRemoteFile retrieves JSON or YAML through a GET request. // The caller is responsible for checking error return values. func UnmarshalRemoteFile(url string, obj interface{}) error { - data, err := readRemoteFile(url) + data, err := ReadRemoteFile(url) if err == nil { err = unmarshalObject(data, obj) } @@ -61,7 +61,7 @@ func UnmarshalRemoteFile(url string, obj interface{}) error { // ReadRemoteFile issues a GET request to retrieve the contents of the specified URL as a byte array. // The caller is responsible for checking error return values. -func readRemoteFile(url string) ([]byte, error) { +func ReadRemoteFile(url string) ([]byte, error) { var data []byte resp, err := http.Get(url) if err == nil { diff --git a/util/config/reader_test.go b/util/config/reader_test.go index 6c3e5b611b2a7..70b9c99fa1088 100644 --- a/util/config/reader_test.go +++ b/util/config/reader_test.go @@ -74,7 +74,7 @@ func TestUnmarshalRemoteFile(t *testing.T) { address := <-c t.Logf("Listening at address: %s", address) - data, err := readRemoteFile("http://" + address) + data, err := ReadRemoteFile("http://" + address) if string(data) != sentinel { t.Errorf("Test data did not match (err = %v)! Expected %q and received %q", err, sentinel, string(data)) } diff --git a/util/helm/helm.go b/util/helm/helm.go index 93b5f8974d690..3e12ced6cc819 100644 --- a/util/helm/helm.go +++ b/util/helm/helm.go @@ -3,6 +3,7 @@ package helm import ( "fmt" "io/ioutil" + "net/url" "os/exec" "path" "strings" @@ -12,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" argoappv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" + "github.com/argoproj/argo-cd/util/config" "github.com/argoproj/argo-cd/util/kube" ) @@ -80,7 +82,13 @@ func (h *helm) GetParameters(valuesFiles []string) ([]*argoappv1.ComponentParame } values := append([]string{out}) for _, file := range valuesFiles { - fileValues, err := ioutil.ReadFile(path.Join(h.path, file)) + var fileValues []byte + parsedURL, err := url.ParseRequestURI(file) + if err == nil && (parsedURL.Scheme == "http" || parsedURL.Scheme == "https") { + fileValues, err = config.ReadRemoteFile(file) + } else { + fileValues, err = ioutil.ReadFile(path.Join(h.path, file)) + } if err != nil { return nil, fmt.Errorf("failed to read value file %s: %s", file, err) } diff --git a/util/helm/helm_test.go b/util/helm/helm_test.go index 675ae2338657c..c3520526c06c0 100644 --- a/util/helm/helm_test.go +++ b/util/helm/helm_test.go @@ -64,7 +64,17 @@ func TestHelmTemplateValues(t *testing.T) { assert.Equal(t, int32(3), *dep.Spec.Replicas) } } +} +func TestHelmTemplateValuesURL(t *testing.T) { + h := NewHelmApp("./testdata/redis") + valuesFiles := []string{"https://raw.githubusercontent.com/argoproj/argo-cd/master/util/helm/testdata/redis/values-production.yaml"} + objs, err := h.Template("test", "", valuesFiles, nil) + assert.Nil(t, err) + assert.Equal(t, 8, len(objs)) + params, err := h.GetParameters(valuesFiles) + assert.NoError(t, err) + assert.True(t, len(params) > 0) } func TestHelmGetParams(t *testing.T) {