mirror of https://github.com/helm/helm
Merge branch 'dev-v3' of https://github.com/helm/helm into test-as-hook
commit
08b2d8a2dc
@ -1,52 +0,0 @@
|
||||
/*
|
||||
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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"helm.sh/helm/cmd/helm/require"
|
||||
)
|
||||
|
||||
var longHomeHelp = `
|
||||
This command displays the location of HELM_HOME. This is where
|
||||
any helm configuration files live.
|
||||
`
|
||||
|
||||
func newHomeCmd(out io.Writer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "home",
|
||||
Short: "displays the location of HELM_HOME",
|
||||
Long: longHomeHelp,
|
||||
Args: require.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
h := settings.Home
|
||||
fmt.Fprintln(out, h)
|
||||
if settings.Debug {
|
||||
fmt.Fprintf(out, "Repository: %s\n", h.Repository())
|
||||
fmt.Fprintf(out, "RepositoryFile: %s\n", h.RepositoryFile())
|
||||
fmt.Fprintf(out, "Cache: %s\n", h.Cache())
|
||||
fmt.Fprintf(out, "Starters: %s\n", h.Starters())
|
||||
fmt.Fprintf(out, "Plugins: %s\n", h.Plugins())
|
||||
}
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"helm.sh/helm/cmd/helm/require"
|
||||
"helm.sh/helm/pkg/helmpath"
|
||||
)
|
||||
|
||||
var longPathHelp = `
|
||||
This command displays the locations where Helm stores files.
|
||||
|
||||
To display a specific location, use 'helm path [config|data|cache]'.
|
||||
`
|
||||
|
||||
var pathArgMap = map[string]string{
|
||||
"config": helmpath.ConfigPath(),
|
||||
"data": helmpath.DataPath(),
|
||||
"cache": helmpath.CachePath(),
|
||||
}
|
||||
|
||||
func newPathCmd(out io.Writer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "path",
|
||||
Short: "displays the locations where Helm stores files",
|
||||
Aliases: []string{"home"},
|
||||
Long: longPathHelp,
|
||||
Args: require.MinimumNArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) > 0 {
|
||||
if p, ok := pathArgMap[args[0]]; ok {
|
||||
fmt.Fprintln(out, p)
|
||||
} else {
|
||||
var validArgs []string
|
||||
for arg := range pathArgMap {
|
||||
validArgs = append(validArgs, arg)
|
||||
}
|
||||
return fmt.Errorf("invalid argument '%s'. Must be one of: %s", args[0], validArgs)
|
||||
}
|
||||
} else {
|
||||
// NOTE(bacongobbler): the order here is important: we want to display the config path
|
||||
// first so users can parse the first line to replicate Helm 2's `helm home`.
|
||||
fmt.Fprintln(out, helmpath.ConfigPath())
|
||||
fmt.Fprintln(out, helmpath.DataPath())
|
||||
fmt.Fprintln(out, helmpath.CachePath())
|
||||
if settings.Debug {
|
||||
fmt.Fprintf(out, "Archive: %s\n", helmpath.Archive())
|
||||
fmt.Fprintf(out, "PluginCache: %s\n", helmpath.PluginCache())
|
||||
fmt.Fprintf(out, "Plugins: %s\n", helmpath.Plugins())
|
||||
fmt.Fprintf(out, "Registry: %s\n", helmpath.Registry())
|
||||
fmt.Fprintf(out, "RepositoryCache: %s\n", helmpath.RepositoryCache())
|
||||
fmt.Fprintf(out, "RepositoryFile: %s\n", helmpath.RepositoryFile())
|
||||
fmt.Fprintf(out, "Starters: %s\n", helmpath.Starters())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
name: env
|
||||
usage: "env stuff"
|
||||
description: "show the env"
|
||||
command: "echo $HELM_HOME"
|
||||
command: "echo $HELM_PATH_CONFIG"
|
@ -1,3 +1,3 @@
|
||||
Error: "helm rollback" requires 2 arguments
|
||||
Error: "helm rollback" requires at least 1 argument
|
||||
|
||||
Usage: helm rollback [RELEASE] [REVISION] [flags]
|
||||
Usage: helm rollback <RELEASE> [REVISION] [flags]
|
||||
|
@ -0,0 +1 @@
|
||||
Rollback was a success! Happy Helming!
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 ensure
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"helm.sh/helm/pkg/helmpath"
|
||||
"helm.sh/helm/pkg/helmpath/xdg"
|
||||
)
|
||||
|
||||
// HelmHome sets up a Helm Home in a temp dir.
|
||||
func HelmHome(t *testing.T) {
|
||||
t.Helper()
|
||||
cachePath := TempDir(t)
|
||||
configPath := TempDir(t)
|
||||
dataPath := TempDir(t)
|
||||
os.Setenv(xdg.CacheHomeEnvVar, cachePath)
|
||||
os.Setenv(xdg.ConfigHomeEnvVar, configPath)
|
||||
os.Setenv(xdg.DataHomeEnvVar, dataPath)
|
||||
HomeDirs(t)
|
||||
}
|
||||
|
||||
// HomeDirs creates a home directory like ensureHome, but without remote references.
|
||||
func HomeDirs(t *testing.T) {
|
||||
t.Helper()
|
||||
for _, p := range []string{
|
||||
helmpath.CachePath(),
|
||||
helmpath.ConfigPath(),
|
||||
helmpath.DataPath(),
|
||||
helmpath.RepositoryCache(),
|
||||
helmpath.Plugins(),
|
||||
helmpath.PluginCache(),
|
||||
helmpath.Starters(),
|
||||
} {
|
||||
if err := os.MkdirAll(p, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CleanHomeDirs removes the directories created by HomeDirs.
|
||||
func CleanHomeDirs(t *testing.T) {
|
||||
t.Helper()
|
||||
for _, p := range []string{
|
||||
helmpath.CachePath(),
|
||||
helmpath.ConfigPath(),
|
||||
helmpath.DataPath(),
|
||||
helmpath.RepositoryCache(),
|
||||
helmpath.Plugins(),
|
||||
helmpath.PluginCache(),
|
||||
helmpath.Starters(),
|
||||
} {
|
||||
if err := os.RemoveAll(p); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TempDir ensures a scratch test directory for unit testing purposes.
|
||||
func TempDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
d, err := ioutil.TempDir("", "helm")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
@ -0,0 +1 @@
|
||||
ignore/
|
@ -0,0 +1,20 @@
|
||||
apiVersion: v2
|
||||
name: frobnitz
|
||||
description: This is a frobnitz.
|
||||
version: "1.2.3"
|
||||
keywords:
|
||||
- frobnitz
|
||||
- sprocket
|
||||
- dodad
|
||||
maintainers:
|
||||
- name: The Helm Team
|
||||
email: helm@example.com
|
||||
- name: Someone Else
|
||||
email: nobody@example.com
|
||||
sources:
|
||||
- https://example.com/foo/bar
|
||||
home: http://example.com
|
||||
icon: https://example.com/64x64.png
|
||||
annotations:
|
||||
extrakey: extravalue
|
||||
anotherkey: anothervalue
|
@ -0,0 +1 @@
|
||||
This is an install document. The client may display this.
|
@ -0,0 +1 @@
|
||||
LICENSE placeholder.
|
@ -0,0 +1,11 @@
|
||||
# Frobnitz
|
||||
|
||||
This is an example chart.
|
||||
|
||||
## Usage
|
||||
|
||||
This is an example. It has no usage.
|
||||
|
||||
## Development
|
||||
|
||||
For developer info, see the top-level repository.
|
@ -0,0 +1 @@
|
||||
This should be ignored by the loader, but may be included in a chart.
|
@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
name: alpine
|
||||
description: Deploy a basic Alpine Linux pod
|
||||
version: 0.1.0
|
||||
home: https://helm.sh/helm
|
@ -0,0 +1,9 @@
|
||||
This example was generated using the command `helm create alpine`.
|
||||
|
||||
The `templates/` directory contains a very simple pod resource with a
|
||||
couple of parameters.
|
||||
|
||||
The `values.toml` file contains the default values for the
|
||||
`alpine-pod.yaml` template.
|
||||
|
||||
You can install this example using `helm install ./alpine`.
|
@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
name: mast1
|
||||
description: A Helm chart for Kubernetes
|
||||
version: 0.1.0
|
||||
home: ""
|
@ -0,0 +1,4 @@
|
||||
# Default values for mast1.
|
||||
# This is a YAML-formatted file.
|
||||
# Declare name/value pairs to be passed into your templates.
|
||||
# name = "value"
|
Binary file not shown.
@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: {{.Release.Name}}-{{.Chart.Name}}
|
||||
labels:
|
||||
app.kubernetes.io/managed-by: {{.Release.Service}}
|
||||
app.kubernetes.io/name: {{.Chart.Name}}
|
||||
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
|
||||
spec:
|
||||
restartPolicy: {{default "Never" .restart_policy}}
|
||||
containers:
|
||||
- name: waiter
|
||||
image: "alpine:3.9"
|
||||
command: ["/bin/sleep","9000"]
|
@ -0,0 +1,2 @@
|
||||
# The pod name
|
||||
name: "my-alpine"
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This is a placeholder for documentation.
|
After Width: | Height: | Size: 374 B |
@ -0,0 +1,7 @@
|
||||
dependencies:
|
||||
- name: alpine
|
||||
version: "0.1.0"
|
||||
repository: https://example.com/charts
|
||||
- name: mariner
|
||||
version: "4.3.2"
|
||||
repository: https://example.com/charts
|
@ -0,0 +1 @@
|
||||
Hello {{.Name | default "world"}}
|
@ -0,0 +1,6 @@
|
||||
# A values file contains configuration.
|
||||
|
||||
name: "Some Name"
|
||||
|
||||
section:
|
||||
name: "Name in a section"
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
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 values
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"helm.sh/helm/pkg/cli"
|
||||
"helm.sh/helm/pkg/getter"
|
||||
"helm.sh/helm/pkg/strvals"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
ValueFiles []string
|
||||
StringValues []string
|
||||
Values []string
|
||||
}
|
||||
|
||||
// MergeValues merges values from files specified via -f/--values and
|
||||
// directly via --set or --set-string, marshaling them to YAML
|
||||
func (opts *Options) MergeValues(settings cli.EnvSettings) (map[string]interface{}, error) {
|
||||
base := map[string]interface{}{}
|
||||
|
||||
// User specified a values files via -f/--values
|
||||
for _, filePath := range opts.ValueFiles {
|
||||
currentMap := map[string]interface{}{}
|
||||
|
||||
bytes, err := readFile(filePath, settings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(bytes, ¤tMap); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse %s", filePath)
|
||||
}
|
||||
// Merge with the previous map
|
||||
base = mergeMaps(base, currentMap)
|
||||
}
|
||||
|
||||
// User specified a value via --set
|
||||
for _, value := range opts.Values {
|
||||
if err := strvals.ParseInto(value, base); err != nil {
|
||||
return nil, errors.Wrap(err, "failed parsing --set data")
|
||||
}
|
||||
}
|
||||
|
||||
// User specified a value via --set-string
|
||||
for _, value := range opts.StringValues {
|
||||
if err := strvals.ParseIntoString(value, base); err != nil {
|
||||
return nil, errors.Wrap(err, "failed parsing --set-string data")
|
||||
}
|
||||
}
|
||||
|
||||
return base, nil
|
||||
}
|
||||
|
||||
func mergeMaps(a, b map[string]interface{}) map[string]interface{} {
|
||||
out := make(map[string]interface{}, len(a))
|
||||
for k, v := range a {
|
||||
out[k] = v
|
||||
}
|
||||
for k, v := range b {
|
||||
if v, ok := v.(map[string]interface{}); ok {
|
||||
if bv, ok := out[k]; ok {
|
||||
if bv, ok := bv.(map[string]interface{}); ok {
|
||||
out[k] = mergeMaps(bv, v)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
out[k] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// readFile load a file from stdin, the local directory, or a remote file with a url.
|
||||
func readFile(filePath string, settings cli.EnvSettings) ([]byte, error) {
|
||||
if strings.TrimSpace(filePath) == "-" {
|
||||
return ioutil.ReadAll(os.Stdin)
|
||||
}
|
||||
u, _ := url.Parse(filePath)
|
||||
p := getter.All(settings)
|
||||
|
||||
// FIXME: maybe someone handle other protocols like ftp.
|
||||
getterConstructor, err := p.ByScheme(u.Scheme)
|
||||
|
||||
if err != nil {
|
||||
return ioutil.ReadFile(filePath)
|
||||
}
|
||||
|
||||
getter, err := getterConstructor(getter.WithURL(filePath))
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
data, err := getter.Get(filePath)
|
||||
return data.Bytes(), err
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
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 values
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMergeValues(t *testing.T) {
|
||||
nestedMap := map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"baz": map[string]string{
|
||||
"cool": "stuff",
|
||||
},
|
||||
}
|
||||
anotherNestedMap := map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"baz": map[string]string{
|
||||
"cool": "things",
|
||||
"awesome": "stuff",
|
||||
},
|
||||
}
|
||||
flatMap := map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"baz": "stuff",
|
||||
}
|
||||
anotherFlatMap := map[string]interface{}{
|
||||
"testing": "fun",
|
||||
}
|
||||
|
||||
testMap := mergeMaps(flatMap, nestedMap)
|
||||
equal := reflect.DeepEqual(testMap, nestedMap)
|
||||
if !equal {
|
||||
t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", nestedMap, testMap)
|
||||
}
|
||||
|
||||
testMap = mergeMaps(nestedMap, flatMap)
|
||||
equal = reflect.DeepEqual(testMap, flatMap)
|
||||
if !equal {
|
||||
t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", flatMap, testMap)
|
||||
}
|
||||
|
||||
testMap = mergeMaps(nestedMap, anotherNestedMap)
|
||||
equal = reflect.DeepEqual(testMap, anotherNestedMap)
|
||||
if !equal {
|
||||
t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", anotherNestedMap, testMap)
|
||||
}
|
||||
|
||||
testMap = mergeMaps(anotherFlatMap, anotherNestedMap)
|
||||
expectedMap := map[string]interface{}{
|
||||
"testing": "fun",
|
||||
"foo": "bar",
|
||||
"baz": map[string]string{
|
||||
"cool": "things",
|
||||
"awesome": "stuff",
|
||||
},
|
||||
}
|
||||
equal = reflect.DeepEqual(testMap, expectedMap)
|
||||
if !equal {
|
||||
t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap)
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue