Skip to content

Commit

Permalink
Add --preserve-name flag (#34)
Browse files Browse the repository at this point in the history
The resources name will be same as input when true.
Default: false - Existing logic
  • Loading branch information
yadavnikhil authored and tamalsaha committed Jun 1, 2017
1 parent b195c64 commit 22d4a14
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ chartify create NAME [FLAGS]
--services stringSlice Specify the names of services(service@namespace) to include in chart
--statefulsets stringSlice Specify the names of statefulsets(statefulset@namespace) to include in chart
--storageclasses stringSlice Specify the names of storageclasses(storageclass@namespace) to include in chart
--preserve-name bool Specify if you want to preserve resources name from input yaml true/false (default: false)
```

### Issues
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func NewCmdCreate() *cobra.Command {
var (
kubeDir string
chartDir string
preserveName bool
)
ko := pkg.KubeObjects{}

Expand All @@ -29,6 +30,7 @@ func NewCmdCreate() *cobra.Command {
Location: checkLocation(chartDir),
ChartName: args[0],
}
pkg.PreserveName = preserveName
if len(kubeDir) != 0 {
gen.YamlFiles = pkg.ReadLocalFiles(kubeDir)
} else {
Expand All @@ -44,6 +46,7 @@ func NewCmdCreate() *cobra.Command {
}
cmd.Flags().StringVar(&kubeDir, "kube-dir", "", "Specify the directory of the yaml files for Kubernetes objects")
cmd.Flags().StringVar(&chartDir, "chart-dir", "charts", "Specify the location where charts will be created")
cmd.Flags().BoolVar(&preserveName, "preserve-name", false, "Specify if you want to preserve resources name from input yaml true/false (default: false)")
cmd.Flags().StringSliceVar(&ko.ConfigMaps, "configmaps", ko.ConfigMaps, "Specify the names of configmaps(configmap@namespace) to include in chart")
cmd.Flags().StringSliceVar(&ko.Daemons, "daemons", ko.Daemons, "Specify the names of daemons(daemon@namespace) to include in chart")
cmd.Flags().StringSliceVar(&ko.Deployments, "deployments", ko.Deployments, "Specify the names of deployments(deployments@namespace) to include in chart")
Expand Down
14 changes: 9 additions & 5 deletions pkg/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ import (
"k8s.io/helm/pkg/proto/hapi/chart"
)

var PreserveName bool

func generateObjectMetaTemplate(objectMeta v1.ObjectMeta, key string, value map[string]interface{}, extraTagForName string) v1.ObjectMeta {
if len(objectMeta.Name) != 0 {
objectMeta.Name = fmt.Sprintf(`{{ template "fullname" . }}`)
}
if len(extraTagForName) != 0 {
objectMeta.Name = fmt.Sprintf("%s-%s", objectMeta.Name, extraTagForName)
if !PreserveName {
if len(objectMeta.Name) != 0 {
objectMeta.Name = fmt.Sprintf(`{{ template "fullname" . }}`)
}
if len(extraTagForName) != 0 {
objectMeta.Name = fmt.Sprintf("%s-%s", objectMeta.Name, extraTagForName)
}
}
if len(objectMeta.ClusterName) != 0 {
value[ClusterName] = objectMeta.ClusterName
Expand Down
2 changes: 1 addition & 1 deletion testdata/replicaset/output/replicaset_chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
containers:
- env:
- name: GET_HOSTS_FROM
value: '{{.Values.frontend.phpredis.GETHOSTSFROM}}'
value: '{{.Values.frontend.phpredis.gethostsfrom}}'
image: '{{.Values.frontend.phpredis.image}}:{{.Values.frontend.phpredis.imageTag}}'
imagePullPolicy: '{{.Values.frontend.phpredis.imagePullPolicy}}'
name: php-redis
Expand Down
2 changes: 1 addition & 1 deletion testdata/replicaset/output/replicaset_value.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: default
phpredis:
GETHOSTSFROM: dns
gethostsfrom: dns
image: gcr.io/google_samples/gb-frontend
imagePullPolicy: IfNotPresent
imageTag: v3
Expand Down

0 comments on commit 22d4a14

Please sign in to comment.