Merge remote-tracking branch 'helm/master'

pull/7767/head
Liu Ming 5 years ago
commit 98ec2760c8

@ -22,6 +22,7 @@ import (
"io"
"path/filepath"
"regexp"
"sort"
"strings"
"github.com/spf13/cobra"
@ -86,12 +87,21 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
// if we have a list of files to render, then check that each of the
// provided files exists in the chart.
if len(showFiles) > 0 {
// This is necessary to ensure consistent manifest ordering when using --show-only
// with globs or directory names.
splitManifests := releaseutil.SplitManifests(manifests.String())
manifestsKeys := make([]string, 0, len(splitManifests))
for k := range splitManifests {
manifestsKeys = append(manifestsKeys, k)
}
sort.Sort(releaseutil.BySplitManifestsOrder(manifestsKeys))
manifestNameRegex := regexp.MustCompile("# Source: [^/]+/(.+)")
var manifestsToRender []string
for _, f := range showFiles {
missing := true
for _, manifest := range splitManifests {
for _, manifestKey := range manifestsKeys {
manifest := splitManifests[manifestKey]
submatch := manifestNameRegex.FindStringSubmatch(manifest)
if len(submatch) == 0 {
continue
@ -104,10 +114,11 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
// if the filepath provided matches a manifest path in the
// chart, render that manifest
if f == manifestPath {
manifestsToRender = append(manifestsToRender, manifest)
missing = false
if matched, _ := filepath.Match(f, manifestPath); !matched {
continue
}
manifestsToRender = append(manifestsToRender, manifest)
missing = false
}
if missing {
return fmt.Errorf("could not find template %s in chart", f)

@ -94,6 +94,13 @@ func TestTemplateCmd(t *testing.T) {
cmd: fmt.Sprintf("template '%s' --show-only templates/service.yaml --show-only charts/subcharta/templates/service.yaml", chartPath),
golden: "output/template-show-only-multiple.txt",
},
{
name: "template with show-only glob",
cmd: fmt.Sprintf("template '%s' --show-only templates/subdir/role*", chartPath),
golden: "output/template-show-only-glob.txt",
// Repeat to ensure manifest ordering regressions are caught
repeat: 10,
},
{
name: "sorted output of manifests (order of filenames, then order of objects within each YAML file)",
cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/object-order"),

@ -1,4 +1,33 @@
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -1,4 +1,33 @@
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -0,0 +1,23 @@
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default

@ -1,4 +1,33 @@
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -1,4 +1,33 @@
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -15,6 +15,35 @@ spec:
singular: authconfig
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -1,4 +1,33 @@
---
# Source: subchart1/templates/subdir/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: subchart1-sa
---
# Source: subchart1/templates/subdir/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: subchart1-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]
---
# Source: subchart1/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: subchart1-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: subchart1-role
subjects:
- kind: ServiceAccount
name: subchart1-sa
namespace: default
---
# Source: subchart1/charts/subcharta/templates/service.yaml
apiVersion: v1
kind: Service

@ -78,3 +78,21 @@ func TestSaveChartNoRawData(t *testing.T) {
is.Equal([]*File(nil), res.Raw)
}
func TestMetadata(t *testing.T) {
chrt := Chart{
Metadata: &Metadata{
Name: "foo.yaml",
AppVersion: "1.0.0",
APIVersion: "v2",
Version: "1.0.0",
Type: "application",
},
}
is := assert.New(t)
is.Equal("foo.yaml", chrt.Name())
is.Equal("1.0.0", chrt.AppVersion())
is.Equal(nil, chrt.Validate())
}

@ -97,6 +97,8 @@ replicaCount: 1
image:
repository: nginx
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart version.
tag: ""
imagePullSecrets: []
nameOverride: ""
@ -111,6 +113,8 @@ serviceAccount:
# If not set and create is true, a name is generated using the fullname template
name:
podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000
@ -248,6 +252,10 @@ spec:
{{- include "<CHARTNAME>.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "<CHARTNAME>.selectorLabels" . | nindent 8 }}
spec:
@ -262,7 +270,7 @@ spec:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http

@ -0,0 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Chart.Name }}-role
rules:
- resources: ["*"]
verbs: ["get","list","watch"]

@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Chart.Name }}-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ .Chart.Name }}-role
subjects:
- kind: ServiceAccount
name: {{ .Chart.Name }}-sa
namespace: default

@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Chart.Name }}-sa

@ -246,12 +246,17 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
func (c *Client) Delete(resources ResourceList) (*Result, []error) {
var errs []error
res := &Result{}
mtx := sync.Mutex{}
err := perform(resources, func(info *resource.Info) error {
c.Log("Starting delete for %q %s", info.Name, info.Mapping.GroupVersionKind.Kind)
if err := c.skipIfNotFound(deleteResource(info)); err != nil {
mtx.Lock()
defer mtx.Unlock()
// Collect the error and continue on
errs = append(errs, err)
} else {
mtx.Lock()
defer mtx.Unlock()
res.Deleted = append(res.Deleted, info)
}
return nil

Loading…
Cancel
Save