Merge pull request #5553 from bacongobbler/same-appversion-as-version

ref(create): app version should be 0.1.0
pull/5649/head
Matthew Fisher 5 years ago committed by GitHub
commit e2ccf13294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,7 +80,7 @@ func (o *createOptions) run(out io.Writer) error {
Description: "A Helm chart for Kubernetes", Description: "A Helm chart for Kubernetes",
Type: "application", Type: "application",
Version: "0.1.0", Version: "0.1.0",
AppVersion: "1.0", AppVersion: "0.1.0",
APIVersion: chart.APIVersionV1, APIVersion: chart.APIVersionV1,
} }
@ -90,6 +90,6 @@ func (o *createOptions) run(out io.Writer) error {
return chartutil.CreateFrom(cfile, filepath.Dir(o.name), lstarter) return chartutil.CreateFrom(cfile, filepath.Dir(o.name), lstarter)
} }
_, err := chartutil.Create(cfile, filepath.Dir(o.name)) _, err := chartutil.Create(chartname, filepath.Dir(o.name))
return err return err
} }

@ -73,11 +73,7 @@ func TestCreateStarterCmd(t *testing.T) {
// Create a starter. // Create a starter.
starterchart := hh.Starters() starterchart := hh.Starters()
os.Mkdir(starterchart, 0755) os.Mkdir(starterchart, 0755)
if dest, err := chartutil.Create(&chart.Metadata{ if dest, err := chartutil.Create("starterchart", starterchart); err != nil {
APIVersion: chart.APIVersionV1,
Name: "starterchart",
Version: "0.1.0",
}, starterchart); err != nil {
t.Fatalf("Could not create chart: %s", err) t.Fatalf("Could not create chart: %s", err)
} else { } else {
t.Logf("Created %s", dest) t.Logf("Created %s", dest)

@ -46,8 +46,9 @@ func TestDependencyUpdateCmd(t *testing.T) {
t.Logf("Listening on directory %s", srv.Root()) t.Logf("Listening on directory %s", srv.Root())
chartname := "depup" chartname := "depup"
md := createTestingMetadata(chartname, srv.URL()) ch := createTestingMetadata(chartname, srv.URL())
if _, err := chartutil.Create(md, hh.String()); err != nil { md := ch.Metadata
if err := chartutil.SaveDir(ch, hh.String()); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -203,14 +204,16 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) {
// createTestingMetadata creates a basic chart that depends on reqtest-0.1.0 // createTestingMetadata creates a basic chart that depends on reqtest-0.1.0
// //
// The baseURL can be used to point to a particular repository server. // The baseURL can be used to point to a particular repository server.
func createTestingMetadata(name, baseURL string) *chart.Metadata { func createTestingMetadata(name, baseURL string) *chart.Chart {
return &chart.Metadata{ return &chart.Chart{
APIVersion: chart.APIVersionV1, Metadata: &chart.Metadata{
Name: name, APIVersion: chart.APIVersionV1,
Version: "1.2.3", Name: name,
Dependencies: []*chart.Dependency{ Version: "1.2.3",
{Name: "reqtest", Version: "0.1.0", Repository: baseURL}, Dependencies: []*chart.Dependency{
{Name: "compressedchart", Version: "0.1.0", Repository: baseURL}, {Name: "reqtest", Version: "0.1.0", Repository: baseURL},
{Name: "compressedchart", Version: "0.1.0", Repository: baseURL},
},
}, },
} }
} }
@ -220,6 +223,5 @@ func createTestingMetadata(name, baseURL string) *chart.Metadata {
// The baseURL can be used to point to a particular repository server. // The baseURL can be used to point to a particular repository server.
func createTestingChart(dest, name, baseURL string) error { func createTestingChart(dest, name, baseURL string) error {
cfile := createTestingMetadata(name, baseURL) cfile := createTestingMetadata(name, baseURL)
_, err := chartutil.Create(cfile, dest) return chartutil.SaveDir(cfile, dest)
return err
} }

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=crazy-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=zany-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=funny-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=funny-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=funny-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=crazy-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -4,8 +4,3 @@ LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default NAMESPACE: default
STATUS: deployed STATUS: deployed
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods -l "app=testUpgradeChart,release=funny-bunny" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80

@ -18,6 +18,7 @@ package main
import ( import (
"fmt" "fmt"
"path/filepath"
"testing" "testing"
"helm.sh/helm/pkg/chart" "helm.sh/helm/pkg/chart"
@ -28,14 +29,16 @@ import (
func TestUpgradeCmd(t *testing.T) { func TestUpgradeCmd(t *testing.T) {
tmpChart := testTempDir(t) tmpChart := testTempDir(t)
cfile := &chart.Metadata{ cfile := &chart.Chart{
APIVersion: chart.APIVersionV1, Metadata: &chart.Metadata{
Name: "testUpgradeChart", APIVersion: chart.APIVersionV1,
Description: "A Helm chart for Kubernetes", Name: "testUpgradeChart",
Version: "0.1.0", Description: "A Helm chart for Kubernetes",
Version: "0.1.0",
},
} }
chartPath, err := chartutil.Create(cfile, tmpChart) chartPath := filepath.Join(tmpChart, cfile.Metadata.Name)
if err != nil { if err := chartutil.SaveDir(cfile, tmpChart); err != nil {
t.Fatalf("Error creating chart for upgrade: %v", err) t.Fatalf("Error creating chart for upgrade: %v", err)
} }
ch, err := loader.Load(chartPath) ch, err := loader.Load(chartPath)
@ -48,14 +51,9 @@ func TestUpgradeCmd(t *testing.T) {
}) })
// update chart version // update chart version
cfile = &chart.Metadata{ cfile.Metadata.Version = "0.1.2"
Name: "testUpgradeChart",
Description: "A Helm chart for Kubernetes",
Version: "0.1.2",
}
chartPath, err = chartutil.Create(cfile, tmpChart) if err := chartutil.SaveDir(cfile, tmpChart); err != nil {
if err != nil {
t.Fatalf("Error creating chart: %v", err) t.Fatalf("Error creating chart: %v", err)
} }
ch, err = loader.Load(chartPath) ch, err = loader.Load(chartPath)
@ -64,14 +62,9 @@ func TestUpgradeCmd(t *testing.T) {
} }
// update chart version again // update chart version again
cfile = &chart.Metadata{ cfile.Metadata.Version = "0.1.3"
Name: "testUpgradeChart",
Description: "A Helm chart for Kubernetes",
Version: "0.1.3",
}
chartPath, err = chartutil.Create(cfile, tmpChart) if err := chartutil.SaveDir(cfile, tmpChart); err != nil {
if err != nil {
t.Fatalf("Error creating chart: %v", err) t.Fatalf("Error creating chart: %v", err)
} }
var ch2 *chart.Chart var ch2 *chart.Chart

@ -53,6 +53,29 @@ const (
HelpersName = "_helpers.tpl" HelpersName = "_helpers.tpl"
) )
const defaultChartfile = `apiVersion: v1
name: %s
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 0.1.0
`
const defaultValues = `# Default values for %s. const defaultValues = `# Default values for %s.
# This is a YAML-formatted file. # This is a YAML-formatted file.
# Declare variables to be passed into your templates. # Declare variables to be passed into your templates.
@ -61,7 +84,6 @@ replicaCount: 1
image: image:
repository: nginx repository: nginx
tag: stable
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
nameOverride: "" nameOverride: ""
@ -189,7 +211,7 @@ spec:
spec: spec:
containers: containers:
- name: {{ .Chart.Name }} - name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" image: "{{ .Values.image.repository }}:{{ .Release.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
ports: ports:
- name: http - name: http
@ -339,7 +361,7 @@ func CreateFrom(chartfile *chart.Metadata, dest, src string) error {
// If Chart.yaml or any directories cannot be created, this will return an // If Chart.yaml or any directories cannot be created, this will return an
// error. In such a case, this will attempt to clean up by removing the // error. In such a case, this will attempt to clean up by removing the
// new chart directory. // new chart directory.
func Create(chartfile *chart.Metadata, dir string) (string, error) { func Create(name, dir string) (string, error) {
path, err := filepath.Abs(dir) path, err := filepath.Abs(dir)
if err != nil { if err != nil {
return path, err return path, err
@ -351,8 +373,7 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
return path, errors.Errorf("no such directory %s", path) return path, errors.Errorf("no such directory %s", path)
} }
n := chartfile.Name cdir := filepath.Join(path, name)
cdir := filepath.Join(path, n)
if fi, err := os.Stat(cdir); err == nil && !fi.IsDir() { if fi, err := os.Stat(cdir); err == nil && !fi.IsDir() {
return cdir, errors.Errorf("file %s already exists and is not a directory", cdir) return cdir, errors.Errorf("file %s already exists and is not a directory", cdir)
} }
@ -360,13 +381,6 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
return cdir, err return cdir, err
} }
cf := filepath.Join(cdir, ChartfileName)
if _, err := os.Stat(cf); err != nil {
if err := SaveChartfile(cf, chartfile); err != nil {
return cdir, err
}
}
for _, d := range []string{TemplatesDir, ChartsDir} { for _, d := range []string{TemplatesDir, ChartsDir} {
if err := os.MkdirAll(filepath.Join(cdir, d), 0755); err != nil { if err := os.MkdirAll(filepath.Join(cdir, d), 0755); err != nil {
return cdir, err return cdir, err
@ -377,10 +391,15 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
path string path string
content []byte content []byte
}{ }{
{
// Chart.yaml
path: filepath.Join(cdir, ChartfileName),
content: []byte(fmt.Sprintf(defaultChartfile, name)),
},
{ {
// values.yaml // values.yaml
path: filepath.Join(cdir, ValuesfileName), path: filepath.Join(cdir, ValuesfileName),
content: []byte(fmt.Sprintf(defaultValues, chartfile.Name)), content: []byte(fmt.Sprintf(defaultValues, name)),
}, },
{ {
// .helmignore // .helmignore
@ -390,27 +409,27 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
{ {
// ingress.yaml // ingress.yaml
path: filepath.Join(cdir, TemplatesDir, IngressFileName), path: filepath.Join(cdir, TemplatesDir, IngressFileName),
content: transform(defaultIngress, chartfile.Name), content: transform(defaultIngress, name),
}, },
{ {
// deployment.yaml // deployment.yaml
path: filepath.Join(cdir, TemplatesDir, DeploymentName), path: filepath.Join(cdir, TemplatesDir, DeploymentName),
content: transform(defaultDeployment, chartfile.Name), content: transform(defaultDeployment, name),
}, },
{ {
// service.yaml // service.yaml
path: filepath.Join(cdir, TemplatesDir, ServiceName), path: filepath.Join(cdir, TemplatesDir, ServiceName),
content: transform(defaultService, chartfile.Name), content: transform(defaultService, name),
}, },
{ {
// NOTES.txt // NOTES.txt
path: filepath.Join(cdir, TemplatesDir, NotesName), path: filepath.Join(cdir, TemplatesDir, NotesName),
content: transform(defaultNotes, chartfile.Name), content: transform(defaultNotes, name),
}, },
{ {
// _helpers.tpl // _helpers.tpl
path: filepath.Join(cdir, TemplatesDir, HelpersName), path: filepath.Join(cdir, TemplatesDir, HelpersName),
content: transform(defaultHelpers, chartfile.Name), content: transform(defaultHelpers, name),
}, },
} }

@ -34,13 +34,7 @@ func TestCreate(t *testing.T) {
} }
defer os.RemoveAll(tdir) defer os.RemoveAll(tdir)
cf := &chart.Metadata{ c, err := Create("foo", tdir)
APIVersion: chart.APIVersionV1,
Name: "foo",
Version: "0.1.0",
}
c, err := Create(cf, tdir)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -36,7 +36,10 @@ var headerBytes = []byte("+aHR0cHM6Ly95b3V0dS5iZS96OVV6MWljandyTQo=")
func SaveDir(c *chart.Chart, dest string) error { func SaveDir(c *chart.Chart, dest string) error {
// Create the chart directory // Create the chart directory
outdir := filepath.Join(dest, c.Name()) outdir := filepath.Join(dest, c.Name())
if err := os.Mkdir(outdir, 0755); err != nil { if fi, err := os.Stat(outdir); err == nil && !fi.IsDir() {
return errors.Errorf("file %s already exists and is not a directory", outdir)
}
if err := os.MkdirAll(outdir, 0755); err != nil {
return err return err
} }

Loading…
Cancel
Save