-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
create.go
118 lines (99 loc) · 3.34 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
Copyright The Helm Authors.
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 main
import (
"errors"
"fmt"
"io"
"path/filepath"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/proto/hapi/chart"
)
const createDesc = `
This command creates a chart directory along with the common files and
directories used in a chart. It provides a basic example and is not
meant to cover all Kubernetes resources.
For example, 'helm create foo' will create a directory structure that looks
something like this:
foo/
|
|- .helmignore # Contains patterns to ignore when packaging Helm charts.
|
|- Chart.yaml # Information about your chart
|
|- values.yaml # The default values for your templates
|
|- charts/ # Charts that this chart depends on
|
|- templates/ # The template files
|
|- templates/tests/ # The test files
'helm create' takes a path for an argument. If directories in the given path
do not exist, Helm will attempt to create them as it goes. If the given
destination exists and there are files in that directory, conflicting files
will be overwritten, but other files will be left alone.
The chart that is created by invoking this command contains a Deployment, Ingress
and a Service. To use other Kubernetes resources with your chart, refer to
[The Chart Template Developer's Guide](https://helm.sh/docs/chart_template_guide).
`
type createCmd struct {
home helmpath.Home
name string
out io.Writer
starter string
}
func newCreateCmd(out io.Writer) *cobra.Command {
cc := &createCmd{out: out}
cmd := &cobra.Command{
Use: "create NAME",
Short: "Create a new chart with the given name",
Long: createDesc,
RunE: func(cmd *cobra.Command, args []string) error {
cc.home = settings.Home
if len(args) == 0 {
return errors.New("the name of the new chart is required")
}
if len(args) > 1 {
return errors.New("command 'create' doesn't support multiple arguments")
}
cc.name = args[0]
return cc.run()
},
}
cmd.Flags().StringVarP(&cc.starter, "starter", "p", "", "The name or absolute path to Helm starter scaffold")
return cmd
}
func (c *createCmd) run() error {
fmt.Fprintf(c.out, "Creating %s\n", c.name)
chartname := filepath.Base(c.name)
cfile := &chart.Metadata{
Name: chartname,
Description: "A Helm chart for Kubernetes",
Version: "0.1.0",
AppVersion: "1.0",
ApiVersion: chartutil.ApiVersionV1,
}
if c.starter != "" {
// Create from the starter
lstarter := filepath.Join(c.home.Starters(), c.starter)
// If path is absolute, we don't want to prefix it with helm starters folder
if filepath.IsAbs(c.starter) {
lstarter = c.starter
}
return chartutil.CreateFrom(cfile, filepath.Dir(c.name), lstarter)
}
_, err := chartutil.Create(cfile, filepath.Dir(c.name))
return err
}