mirror of https://github.com/helm/helm
parent
1819f1f616
commit
f9d8645c17
@ -0,0 +1 @@
|
|||||||
|
glob-external-1
|
@ -0,0 +1 @@
|
|||||||
|
glob-external-2
|
@ -0,0 +1 @@
|
|||||||
|
out-of-chart-dir
|
@ -0,0 +1,6 @@
|
|||||||
|
NAME: virgil
|
||||||
|
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
|
||||||
|
NAMESPACE: default
|
||||||
|
STATUS: deployed
|
||||||
|
REVISION: 1
|
||||||
|
TEST SUITE: None
|
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
# Source: configmap/templates/config-map.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: "RELEASE-NAME-"
|
||||||
|
labels:
|
||||||
|
# The "app.kubernetes.io/managed-by" label is used to track which tool
|
||||||
|
# deployed a given chart. It is useful for admins who want to see what
|
||||||
|
# releases a particular tool is responsible for.
|
||||||
|
app.kubernetes.io/managed-by: "Helm"
|
||||||
|
# The "app.kubernetes.io/instance" convention makes it easy to tie a release
|
||||||
|
# to all of the Kubernetes resources that were created as part of that
|
||||||
|
# release.
|
||||||
|
app.kubernetes.io/instance: "RELEASE-NAME"
|
||||||
|
app.kubernetes.io/version: 1.0
|
||||||
|
# This makes it easy to audit chart usage.
|
||||||
|
helm.sh/chart: "configmap-0.1.0"
|
||||||
|
data:
|
||||||
|
external.1.conf: glob-external-1
|
||||||
|
external.2.conf: glob-external-2
|
||||||
|
external.txt: out-of-chart-dir
|
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
# Source: configmap/templates/config-map.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: "RELEASE-NAME-"
|
||||||
|
labels:
|
||||||
|
# The "app.kubernetes.io/managed-by" label is used to track which tool
|
||||||
|
# deployed a given chart. It is useful for admins who want to see what
|
||||||
|
# releases a particular tool is responsible for.
|
||||||
|
app.kubernetes.io/managed-by: "Helm"
|
||||||
|
# The "app.kubernetes.io/instance" convention makes it easy to tie a release
|
||||||
|
# to all of the Kubernetes resources that were created as part of that
|
||||||
|
# release.
|
||||||
|
app.kubernetes.io/instance: "RELEASE-NAME"
|
||||||
|
app.kubernetes.io/version: 1.0
|
||||||
|
# This makes it easy to audit chart usage.
|
||||||
|
helm.sh/chart: "configmap-0.1.0"
|
||||||
|
data:
|
||||||
|
external.txt: out-of-chart-dir
|
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
# Source: configmap/templates/config-map.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: "RELEASE-NAME-"
|
||||||
|
labels:
|
||||||
|
# The "app.kubernetes.io/managed-by" label is used to track which tool
|
||||||
|
# deployed a given chart. It is useful for admins who want to see what
|
||||||
|
# releases a particular tool is responsible for.
|
||||||
|
app.kubernetes.io/managed-by: "Helm"
|
||||||
|
# The "app.kubernetes.io/instance" convention makes it easy to tie a release
|
||||||
|
# to all of the Kubernetes resources that were created as part of that
|
||||||
|
# release.
|
||||||
|
app.kubernetes.io/instance: "RELEASE-NAME"
|
||||||
|
app.kubernetes.io/version: 1.0
|
||||||
|
# This makes it easy to audit chart usage.
|
||||||
|
helm.sh/chart: "configmap-0.1.0"
|
||||||
|
data:
|
||||||
|
external.1.conf: glob-external-1
|
||||||
|
external.2.conf: glob-external-2
|
@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
appVersion: "1.0"
|
||||||
|
description: Deploy a basic Config Map from an external file
|
||||||
|
home: https://helm.sh/helm
|
||||||
|
name: configmap
|
||||||
|
sources:
|
||||||
|
- https://github.com/helm/helm
|
||||||
|
version: 0.1.0
|
@ -0,0 +1 @@
|
|||||||
|
in-chart
|
@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: "{{.Release.Name}}-{{.Values.Name}}"
|
||||||
|
labels:
|
||||||
|
# The "app.kubernetes.io/managed-by" label is used to track which tool
|
||||||
|
# deployed a given chart. It is useful for admins who want to see what
|
||||||
|
# releases a particular tool is responsible for.
|
||||||
|
app.kubernetes.io/managed-by: {{.Release.Service | quote }}
|
||||||
|
# The "app.kubernetes.io/instance" convention makes it easy to tie a release
|
||||||
|
# to all of the Kubernetes resources that were created as part of that
|
||||||
|
# release.
|
||||||
|
app.kubernetes.io/instance: {{.Release.Name | quote }}
|
||||||
|
app.kubernetes.io/version: {{ .Chart.AppVersion }}
|
||||||
|
# This makes it easy to audit chart usage.
|
||||||
|
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
|
||||||
|
data:
|
||||||
|
{{- if .Values.external }}
|
||||||
|
{{ (.Files.Glob .Values.external).AsConfig | indent 2 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.glob.enabled }}
|
||||||
|
{{ (.Files.Glob .Values.glob.path).AsConfig | indent 2 }}
|
||||||
|
{{- end }}
|
@ -0,0 +1,4 @@
|
|||||||
|
external: false
|
||||||
|
glob:
|
||||||
|
enabled: false
|
||||||
|
path: "glob/*"
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package loader
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ExpandLocalPath expands a local file, dir or glob path to a list of files
|
||||||
|
func ExpandLocalPath(name string, path string) (map[string]string, error) {
|
||||||
|
if strings.Contains(path, "*") {
|
||||||
|
// if this is a glob, we expand it and return a list of files
|
||||||
|
return expandGlob(name, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.IsDir() {
|
||||||
|
// if this is a valid dir, we return all files within
|
||||||
|
return expandDir(name, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally, this is a file, so we return it
|
||||||
|
return map[string]string{name: path}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func expandGlob(name string, path string) (map[string]string, error) {
|
||||||
|
fmap := make(map[string]string)
|
||||||
|
paths, err := filepath.Glob(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(paths) == 0 {
|
||||||
|
return nil, errors.New("empty glob")
|
||||||
|
}
|
||||||
|
|
||||||
|
namePrefix := strings.TrimRight(name, "/") + "/"
|
||||||
|
for _, p := range paths {
|
||||||
|
key := namePrefix + filepath.Base(p)
|
||||||
|
fmap[key] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func expandDir(name string, path string) (map[string]string, error) {
|
||||||
|
fmap := make(map[string]string)
|
||||||
|
|
||||||
|
f, err := os.Open(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
files, err := f.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
localDirName := strings.TrimRight(path, "/") + "/"
|
||||||
|
namePrefix := strings.TrimRight(name, "/") + "/"
|
||||||
|
for _, file := range files {
|
||||||
|
key := namePrefix + file.Name()
|
||||||
|
fmap[key] = localDirName + file.Name()
|
||||||
|
}
|
||||||
|
return fmap, nil
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package loader
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExpandLocalPath(t *testing.T) {
|
||||||
|
need := require.New(t)
|
||||||
|
is := assert.New(t)
|
||||||
|
|
||||||
|
glob, err := ExpandLocalPath("glob", "testdata/frobnitz/*.yaml")
|
||||||
|
need.NoError(err)
|
||||||
|
need.Contains(glob, "glob/Chart.yaml")
|
||||||
|
need.Contains(glob, "glob/values.yaml")
|
||||||
|
is.Equal("testdata/frobnitz/Chart.yaml", glob["glob/Chart.yaml"])
|
||||||
|
is.Equal("testdata/frobnitz/values.yaml", glob["glob/values.yaml"])
|
||||||
|
|
||||||
|
dir, err := ExpandLocalPath("dir", "testdata/albatross/")
|
||||||
|
need.NoError(err)
|
||||||
|
need.Contains(dir, "dir/Chart.yaml")
|
||||||
|
need.Contains(dir, "dir/values.yaml")
|
||||||
|
is.Equal("testdata/albatross/Chart.yaml", dir["dir/Chart.yaml"])
|
||||||
|
is.Equal("testdata/albatross/values.yaml", dir["dir/values.yaml"])
|
||||||
|
|
||||||
|
file, err := ExpandLocalPath("file", "testdata/albatross/Chart.yaml")
|
||||||
|
need.NoError(err)
|
||||||
|
need.Contains(file, "file")
|
||||||
|
is.Equal("testdata/albatross/Chart.yaml", file["file"])
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package files
|
||||||
|
|
||||||
|
// ExternalFiles holds the list of external files or globs
|
||||||
|
type ExternalFiles struct {
|
||||||
|
Files []string
|
||||||
|
Globs []string
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ParseIntoString parses a include-file line and merges the result into dest.
|
||||||
|
func ParseIntoString(s string, dest map[string]string) error {
|
||||||
|
for _, val := range strings.Split(s, ",") {
|
||||||
|
val = strings.TrimSpace(val)
|
||||||
|
splt := strings.SplitN(val, "=", 2)
|
||||||
|
|
||||||
|
if len(splt) != 2 {
|
||||||
|
return errors.New("Could not parse line")
|
||||||
|
}
|
||||||
|
|
||||||
|
name := strings.TrimSpace(splt[0])
|
||||||
|
path := strings.TrimSpace(splt[1])
|
||||||
|
dest[name] = path
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//ParseGlobIntoString parses an include-dir file line and merges all files found into dest.
|
||||||
|
func ParseGlobIntoString(g string, dest map[string]string) error {
|
||||||
|
globs := make(map[string]string)
|
||||||
|
err := ParseIntoString(g, globs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for k, g := range globs {
|
||||||
|
if !strings.Contains(g, "*") {
|
||||||
|
// force glob style on simple directories
|
||||||
|
g = strings.TrimRight(g, "/") + "/*"
|
||||||
|
}
|
||||||
|
|
||||||
|
paths, err := filepath.Glob(g)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
k = strings.TrimRight(k, "/")
|
||||||
|
for _, path := range paths {
|
||||||
|
dest[fmt.Sprintf("%s/%s", k, filepath.Base(path))] = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseIntoString(t *testing.T) {
|
||||||
|
need := require.New(t)
|
||||||
|
is := assert.New(t)
|
||||||
|
|
||||||
|
dest := make(map[string]string)
|
||||||
|
goodFlag := "foo.txt=../foo.txt"
|
||||||
|
anotherFlag := " bar.txt=~/bar.txt, baz.txt=/path/to/baz.txt"
|
||||||
|
|
||||||
|
err := ParseIntoString(goodFlag, dest)
|
||||||
|
need.NoError(err)
|
||||||
|
|
||||||
|
err = ParseIntoString(anotherFlag, dest)
|
||||||
|
need.NoError(err)
|
||||||
|
|
||||||
|
is.Contains(dest, "foo.txt")
|
||||||
|
is.Contains(dest, "bar.txt")
|
||||||
|
is.Contains(dest, "baz.txt")
|
||||||
|
|
||||||
|
is.Equal(dest["foo.txt"], "../foo.txt", "foo.txt not mapped properly")
|
||||||
|
is.Equal(dest["bar.txt"], "~/bar.txt", "bar.txt not mapped properly")
|
||||||
|
is.Equal(dest["baz.txt"], "/path/to/baz.txt", "baz.txt not mapped properly")
|
||||||
|
|
||||||
|
overwriteFlag := "foo.txt=../new_foo.txt"
|
||||||
|
err = ParseIntoString(overwriteFlag, dest)
|
||||||
|
need.NoError(err)
|
||||||
|
|
||||||
|
is.Equal(dest["foo.txt"], "../new_foo.txt")
|
||||||
|
|
||||||
|
badFlag := "empty.txt"
|
||||||
|
err = ParseIntoString(badFlag, dest)
|
||||||
|
is.NotNil(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseGlobIntoString(t *testing.T) {
|
||||||
|
need := require.New(t)
|
||||||
|
is := assert.New(t)
|
||||||
|
|
||||||
|
dest := make(map[string]string)
|
||||||
|
globFlagSlash := "glob/=testdata/foo/foo.*"
|
||||||
|
dirFlagNoSlash := "dir=testdata/foo/"
|
||||||
|
|
||||||
|
err := ParseGlobIntoString(globFlagSlash, dest)
|
||||||
|
need.NoError(err)
|
||||||
|
need.Contains(dest, "glob/foo.txt")
|
||||||
|
is.Equal("testdata/foo/foo.txt", dest["glob/foo.txt"])
|
||||||
|
|
||||||
|
err = ParseGlobIntoString(dirFlagNoSlash, dest)
|
||||||
|
need.NoError(err)
|
||||||
|
need.Contains(dest, "dir/foo.txt")
|
||||||
|
need.Contains(dest, "dir/bar.txt")
|
||||||
|
is.Equal("testdata/foo/foo.txt", dest["dir/foo.txt"])
|
||||||
|
is.Equal("testdata/foo/bar.txt", dest["dir/bar.txt"])
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
bar
|
@ -0,0 +1 @@
|
|||||||
|
foo
|
Loading…
Reference in new issue