mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #3288 from bradbeam/starter
feat Making starter templates more versatile
This commit is contained in:
commit
14c7be1f92
5 changed files with 53 additions and 7 deletions
|
|
@ -849,6 +849,8 @@ considerations in mind:
|
|||
- The `Chart.yaml` will be overwritten by the generator.
|
||||
- Users will expect to modify such a chart's contents, so documentation
|
||||
should indicate how users can do so.
|
||||
- All occurances of `<CHARTNAME>` will be replaced with the specified chart
|
||||
name so that starter charts can be used as templates.
|
||||
|
||||
Currently the only way to add a chart to `$HELM_HOME/starters` is to manually
|
||||
copy it there. In your chart's documentation, you may want to explain that
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/helm/pkg/proto/hapi/chart"
|
||||
)
|
||||
|
|
@ -297,6 +296,17 @@ func CreateFrom(chartfile *chart.Metadata, dest string, src string) error {
|
|||
}
|
||||
|
||||
schart.Metadata = chartfile
|
||||
|
||||
var updatedTemplates []*chart.Template
|
||||
|
||||
for _, template := range schart.Templates {
|
||||
newData := Transform(string(template.Data), "<CHARTNAME>", schart.Metadata.Name)
|
||||
updatedTemplates = append(updatedTemplates, &chart.Template{Name: template.Name, Data: newData})
|
||||
}
|
||||
|
||||
schart.Templates = updatedTemplates
|
||||
schart.Values = &chart.Config{Raw: string(Transform(schart.Values.Raw, "<CHARTNAME>", schart.Metadata.Name))}
|
||||
|
||||
return SaveDir(schart, dest)
|
||||
}
|
||||
|
||||
|
|
@ -364,27 +374,27 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
|
|||
{
|
||||
// ingress.yaml
|
||||
path: filepath.Join(cdir, TemplatesDir, IngressFileName),
|
||||
content: []byte(strings.Replace(defaultIngress, "<CHARTNAME>", chartfile.Name, -1)),
|
||||
content: Transform(defaultIngress, "<CHARTNAME>", chartfile.Name),
|
||||
},
|
||||
{
|
||||
// deployment.yaml
|
||||
path: filepath.Join(cdir, TemplatesDir, DeploymentName),
|
||||
content: []byte(strings.Replace(defaultDeployment, "<CHARTNAME>", chartfile.Name, -1)),
|
||||
content: Transform(defaultDeployment, "<CHARTNAME>", chartfile.Name),
|
||||
},
|
||||
{
|
||||
// service.yaml
|
||||
path: filepath.Join(cdir, TemplatesDir, ServiceName),
|
||||
content: []byte(strings.Replace(defaultService, "<CHARTNAME>", chartfile.Name, -1)),
|
||||
content: Transform(defaultService, "<CHARTNAME>", chartfile.Name),
|
||||
},
|
||||
{
|
||||
// NOTES.txt
|
||||
path: filepath.Join(cdir, TemplatesDir, NotesName),
|
||||
content: []byte(strings.Replace(defaultNotes, "<CHARTNAME>", chartfile.Name, -1)),
|
||||
content: Transform(defaultNotes, "<CHARTNAME>", chartfile.Name),
|
||||
},
|
||||
{
|
||||
// _helpers.tpl
|
||||
path: filepath.Join(cdir, TemplatesDir, HelpersName),
|
||||
content: []byte(strings.Replace(defaultHelpers, "<CHARTNAME>", chartfile.Name, -1)),
|
||||
content: Transform(defaultHelpers, "<CHARTNAME>", chartfile.Name),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/helm/pkg/proto/hapi/chart"
|
||||
|
|
@ -125,4 +126,9 @@ func TestCreateFrom(t *testing.T) {
|
|||
t.Errorf("Expected %s to be a file.", f)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we replace `<CHARTNAME>`
|
||||
if strings.Contains(mychart.Values.Raw, "<CHARTNAME>") {
|
||||
t.Errorf("Did not expect %s to be present in %s", "<CHARTNAME>", mychart.Values.Raw)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
pkg/chartutil/testdata/mariner/values.yaml
vendored
5
pkg/chartutil/testdata/mariner/values.yaml
vendored
|
|
@ -1,4 +1,7 @@
|
|||
# Default values for mariner.
|
||||
# Default values for <CHARTNAME>.
|
||||
# This is a YAML-formatted file. https://github.com/toml-lang/toml
|
||||
# Declare name/value pairs to be passed into your templates.
|
||||
# name: "value"
|
||||
|
||||
<CHARTNAME>:
|
||||
test: true
|
||||
|
|
|
|||
25
pkg/chartutil/transform.go
Normal file
25
pkg/chartutil/transform.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 chartutil
|
||||
|
||||
import "strings"
|
||||
|
||||
// Transform performs a string replacement of the specified source for
|
||||
// a given key with the replacement string
|
||||
func Transform(src string, key string, replacement string) []byte {
|
||||
return []byte(strings.Replace(src, key, replacement, -1))
|
||||
}
|
||||
Loading…
Reference in a new issue