|
|
|
@ -25,9 +25,14 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/validation"
|
|
|
|
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
|
|
|
|
|
|
|
|
chart "helm.sh/helm/v4/internal/chart/v3"
|
|
|
|
chart "helm.sh/helm/v4/internal/chart/v3"
|
|
|
|
"helm.sh/helm/v4/internal/chart/v3/loader"
|
|
|
|
"helm.sh/helm/v4/internal/chart/v3/loader"
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/pkg/chart/common"
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/pkg/chart/common/util"
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/pkg/engine"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
|
|
|
func TestCreate(t *testing.T) {
|
|
|
|
@ -95,6 +100,61 @@ func TestCreateFrom(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestCreate_LabelValues(t *testing.T) {
|
|
|
|
|
|
|
|
tdir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c, err := Create("demo", tdir)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mychart, err := loader.LoadDir(c)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// "demo-" + version is 64 characters, so `trunc 63` cuts right after the
|
|
|
|
|
|
|
|
// character that precedes the final "1".
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
|
|
|
|
version string
|
|
|
|
|
|
|
|
appVersion string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
"truncated chart label ends in dot": {
|
|
|
|
|
|
|
|
version: "1.0.0-abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy.1",
|
|
|
|
|
|
|
|
appVersion: "1.16.0",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"truncated chart label ends in underscore": {
|
|
|
|
|
|
|
|
version: "1.0.0-abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy+1",
|
|
|
|
|
|
|
|
appVersion: "1.16.0",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"app version with build metadata longer than 63 characters": {
|
|
|
|
|
|
|
|
version: "0.1.0",
|
|
|
|
|
|
|
|
appVersion: "v1.2.3+build.123456789012345678901234567890123456789012345678901234567890",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
} {
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
|
|
|
mychart.Metadata.Version = tc.version
|
|
|
|
|
|
|
|
mychart.Metadata.AppVersion = tc.appVersion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts := common.ReleaseOptions{Name: "demo", Namespace: "default", Revision: 1, IsInstall: true}
|
|
|
|
|
|
|
|
vals, err := util.ToRenderValues(mychart, map[string]any{}, opts, common.DefaultCapabilities)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out, err := new(engine.Engine).RenderWithContext(t.Context(), mychart, vals)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sa struct {
|
|
|
|
|
|
|
|
Metadata struct {
|
|
|
|
|
|
|
|
Labels map[string]string `json:"labels"`
|
|
|
|
|
|
|
|
} `json:"metadata"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, yaml.Unmarshal([]byte(out["demo/templates/serviceaccount.yaml"]), &sa))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, key := range []string{"helm.sh/chart", "app.kubernetes.io/version"} {
|
|
|
|
|
|
|
|
v, ok := sa.Metadata.Labels[key]
|
|
|
|
|
|
|
|
require.True(t, ok, "expected label %q to be set", key)
|
|
|
|
|
|
|
|
assert.Empty(t, validation.IsValidLabelValue(v), "label %s=%q", key, v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TestCreate_Overwrite is a regression test for making sure that files are overwritten.
|
|
|
|
// TestCreate_Overwrite is a regression test for making sure that files are overwritten.
|
|
|
|
func TestCreate_Overwrite(t *testing.T) {
|
|
|
|
func TestCreate_Overwrite(t *testing.T) {
|
|
|
|
tdir := t.TempDir()
|
|
|
|
tdir := t.TempDir()
|
|
|
|
|