Merge pull request #9536 from mengjiao-liu/add-install-validate

validate release name during install
pull/10526/head
Matt Farina 3 years ago committed by GitHub
commit d9ffe37d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,7 +123,7 @@ func TestInstall(t *testing.T) {
// Install, using the name-template
{
name: "install with name-template",
cmd: "install testdata/testcharts/empty --name-template '{{upper \"foobar\"}}'",
cmd: "install testdata/testcharts/empty --name-template '{{ \"foobar\"}}'",
golden: "output/install-name-template.txt",
},
// Install, perform chart verification along the way.

@ -74,7 +74,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}
client.DryRun = true
client.ReleaseName = "RELEASE-NAME"
client.ReleaseName = "release-name"
client.Replace = true // Skip the name check
client.ClientOnly = !validate
client.APIVersions = chartutil.VersionSet(extraAPIs)

@ -43,7 +43,7 @@ func TestTemplateCmd(t *testing.T) {
},
{
name: "check name template",
cmd: fmt.Sprintf(`template '%s' --name-template='foobar-{{ b64enc "abc" }}-baz'`, chartPath),
cmd: fmt.Sprintf(`template '%s' --name-template='foobar-{{ b64enc "abc" | lower }}-baz'`, chartPath),
golden: "output/template-name-template.txt",
},
{

@ -1,4 +1,4 @@
NAME: FOOBAR
NAME: foobar
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed

@ -7,7 +7,7 @@ metadata:
app: chart-with-template-lib-archive-dep
chart: chart-with-template-lib-archive-dep-0.1.0
heritage: Helm
release: RELEASE-NAME
release: release-name
name: release-name-chart-with-template-lib-archive-dep
spec:
ports:
@ -16,30 +16,30 @@ spec:
targetPort: http
selector:
app: chart-with-template-lib-archive-dep
release: RELEASE-NAME
release: release-name
type: ClusterIP
---
# Source: chart-with-template-lib-archive-dep/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: RELEASE-NAME-chart-with-template-lib-archive-dep
name: release-name-chart-with-template-lib-archive-dep
labels:
app: chart-with-template-lib-archive-dep
chart: chart-with-template-lib-archive-dep-0.1.0
release: RELEASE-NAME
release: release-name
heritage: Helm
spec:
replicas: 1
selector:
matchLabels:
app: chart-with-template-lib-archive-dep
release: RELEASE-NAME
release: release-name
template:
metadata:
labels:
app: chart-with-template-lib-archive-dep
release: RELEASE-NAME
release: release-name
spec:
containers:
- name: chart-with-template-lib-archive-dep

@ -7,7 +7,7 @@ metadata:
app: chart-with-template-lib-dep
chart: chart-with-template-lib-dep-0.1.0
heritage: Helm
release: RELEASE-NAME
release: release-name
name: release-name-chart-with-template-lib-dep
spec:
ports:
@ -16,30 +16,30 @@ spec:
targetPort: http
selector:
app: chart-with-template-lib-dep
release: RELEASE-NAME
release: release-name
type: ClusterIP
---
# Source: chart-with-template-lib-dep/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: RELEASE-NAME-chart-with-template-lib-dep
name: release-name-chart-with-template-lib-dep
labels:
app: chart-with-template-lib-dep
chart: chart-with-template-lib-dep-0.1.0
release: RELEASE-NAME
release: release-name
heritage: Helm
spec:
replicas: 1
selector:
matchLabels:
app: chart-with-template-lib-dep
release: RELEASE-NAME
release: release-name
template:
metadata:
labels:
app: chart-with-template-lib-dep
release: RELEASE-NAME
release: release-name
spec:
containers:
- name: chart-with-template-lib-dep

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "foobar-YWJj-baz"
app.kubernetes.io/instance: "foobar-ywjj-baz"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -88,7 +88,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "foobar-YWJj-baz-testconfig"
name: "foobar-ywjj-baz-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -98,7 +98,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "foobar-YWJj-baz-test"
name: "foobar-ywjj-baz-test"
annotations:
"helm.sh/hook": test
spec:
@ -107,7 +107,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "foobar-YWJj-baz-testconfig"
name: "foobar-ywjj-baz-testconfig"
command:
- echo
- "$message"

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -88,7 +88,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -98,7 +98,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -107,7 +107,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -6,7 +6,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"

@ -6,7 +6,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -88,7 +88,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -98,7 +98,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -107,7 +107,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -89,7 +89,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -99,7 +99,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -108,7 +108,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -87,7 +87,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -105,7 +105,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -115,7 +115,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -124,7 +124,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -3,7 +3,7 @@
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-my-alpine"
name: "release-name-my-alpine"
spec:
containers:
- name: waiter

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "16"
kube-version/version: "v1.16.0"
@ -88,7 +88,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -98,7 +98,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -107,7 +107,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -70,7 +70,7 @@ metadata:
name: subchart
labels:
helm.sh/chart: "subchart-0.1.0"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
kube-version/major: "1"
kube-version/minor: "20"
kube-version/version: "v1.20.0"
@ -88,7 +88,7 @@ spec:
apiVersion: v1
kind: ConfigMap
metadata:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
annotations:
"helm.sh/hook": test
data:
@ -98,7 +98,7 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: "RELEASE-NAME-test"
name: "release-name-test"
annotations:
"helm.sh/hook": test
spec:
@ -107,7 +107,7 @@ spec:
image: "alpine:latest"
envFrom:
- configMapRef:
name: "RELEASE-NAME-testconfig"
name: "release-name-testconfig"
command:
- echo
- "$message"

@ -13,7 +13,7 @@ A few tips for working with Common:
- Be careful when using functions that generate random data (like `common.fullname.unique`).
They may trigger unwanted upgrades or have other side effects.
In this document, we use `RELEASE-NAME` as the name of the release.
In this document, we use `release-name` as the name of the release.
## Resource Kinds
@ -733,7 +733,7 @@ metadata:
labels:
app: metadata
heritage: "Tiller"
release: "RELEASE-NAME"
release: "release-name"
chart: metadata-0.1.0
first: "matt"
last: "butcher"
@ -748,7 +748,7 @@ metadata:
labels:
app: metadata
heritage: "Tiller"
release: "RELEASE-NAME"
release: "release-name"
chart: metadata-0.1.0
annotations:
```
@ -791,7 +791,7 @@ Example output:
```yaml
app: labelizer
heritage: "Tiller"
release: "RELEASE-NAME"
release: "release-name"
chart: labelizer-0.1.0
```

@ -13,7 +13,7 @@ A few tips for working with Common:
- Be careful when using functions that generate random data (like `common.fullname.unique`).
They may trigger unwanted upgrades or have other side effects.
In this document, we use `RELEASE-NAME` as the name of the release.
In this document, we use `release-name` as the name of the release.
## Resource Kinds
@ -733,7 +733,7 @@ metadata:
labels:
app.kubernetes.io/name: metadata
app.kubernetes.io/managed-by: "Helm"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
helm.sh/chart: metadata-0.1.0
first: "matt"
last: "butcher"
@ -748,7 +748,7 @@ metadata:
labels:
app.kubernetes.io/name: metadata
app.kubernetes.io/managed-by: "Helm"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
helm.sh/chart: metadata-0.1.0
annotations:
```
@ -791,7 +791,7 @@ Example output:
```yaml
app.kubernetes.io/name: labelizer
app.kubernetes.io/managed-by: "Tiller"
app.kubernetes.io/instance: "RELEASE-NAME"
app.kubernetes.io/instance: "release-name"
helm.sh/chart: labelizer-0.1.0
```

@ -54,13 +54,6 @@ import (
"helm.sh/helm/v3/pkg/storage/driver"
)
// releaseNameMaxLen is the maximum length of a release name.
//
// As of Kubernetes 1.4, the max limit on a name is 63 chars. We reserve 10 for
// charts to add data. Effectively, that gives us 53 chars.
// See https://github.com/helm/helm/issues/1528
const releaseNameMaxLen = 53
// NOTESFILE_SUFFIX that we want to treat special. It goes through the templating engine
// but it's not a yaml file (resource) hence can't have hooks, etc. And the user actually
// wants to see this file after rendering in the status command. However, it must be a suffix
@ -458,14 +451,10 @@ func (i *Install) failRelease(rel *release.Release, err error) (*release.Release
// - used by a deleted release, and i.Replace is false
func (i *Install) availableName() error {
start := i.ReleaseName
if start == "" {
return errors.New("name is required")
}
if len(start) > releaseNameMaxLen {
return errors.Errorf("release name %q exceeds max length of %d", start, releaseNameMaxLen)
if err := chartutil.ValidateReleaseName(start); err != nil {
return errors.Wrapf(err, "release name %q", start)
}
if i.DryRun {
return nil
}

@ -132,7 +132,7 @@ func TestInstallRelease_NoName(t *testing.T) {
if err == nil {
t.Fatal("expected failure when no name is specified")
}
assert.Contains(t, err.Error(), "name is required")
assert.Contains(t, err.Error(), "no name provided")
}
func TestInstallRelease_WithNotes(t *testing.T) {

@ -52,7 +52,12 @@ var (
)
const (
// maxNameLen is the maximum length Helm allows for a release name
// According to the Kubernetes docs (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names)
// some resource names have a max length of 63 characters while others have a max
// length of 253 characters. As we cannot be sure the resources used in a chart, we
// therefore need to limit it to 63 chars and reserve 10 chars for additional part to name
// of the resource. The reason is that chart maintainers can use release name as part of
// the resource name (and some additional chars).
maxReleaseNameLen = 53
// maxMetadataNameLen is the maximum length Kubernetes allows for any name.
maxMetadataNameLen = 253

Loading…
Cancel
Save