Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
5ea81b47
Commit
5ea81b47
authored
Oct 26, 2016
by
Adnan Abdulhussein
Committed by
GitHub
Oct 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1461 from viglesiasce/update-create-templates
Add deployment, service and NOTES to create
parents
f175a14c
665615f3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
4 deletions
+141
-4
create.go
pkg/chartutil/create.go
+132
-3
create_test.go
pkg/chartutil/create_test.go
+9
-1
No files found.
pkg/chartutil/create.go
View file @
5ea81b47
...
...
@@ -36,12 +36,37 @@ const (
ChartsDir
=
"charts"
// IgnorefileName is the name of the Helm ignore file.
IgnorefileName
=
".helmignore"
// DeploymentName is the name of the example deployment file.
DeploymentName
=
"deployment.yaml"
// ServiceName is the name of the example service file.
ServiceName
=
"service.yaml"
// NotesName is the name of the example NOTES.txt file.
NotesName
=
"NOTES.txt"
// HelpersName is the name of the example NOTES.txt file.
HelpersName
=
"_helpers.tpl"
)
const
defaultValues
=
`# Default values for %s.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
service:
name: nginx
type: ClusterIP
externalPort: 80
internalPort: 80
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
`
const
defaultIgnore
=
`# Patterns to ignore when building packages.
...
...
@@ -67,6 +92,89 @@ const defaultIgnore = `# Patterns to ignore when building packages.
*.tmproj
`
const
defaultDeployment
=
`apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ template "fullname" . }}
spec:
containers:
- name: nginx
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.internalPort }}
livenessProbe:
httpGet:
path: /
port: 80
readinessProbe:
httpGet:
path: /
port: 80
resources:
{{ toYaml .Values.resources | indent 12 }}
`
const
defaultService
=
`apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "fullname" . }}
`
const
defaultNotes
=
`1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.Master.ServicePort }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "component={{ template "fullname" . }}-master" -o jsonpath="{.items[0].metadata.name}")
echo http://127.0.0.1:{{ .Values.service.externalPort }}
kubectl port-forward $POD_NAME {{ .Values.service.externalPort }}:{{ .Values.service.externalPort }}
{{- end }}
`
const
defaultHelpers
=
`{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 24 -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 24 -}}
{{- end -}}
`
// Create creates a new chart in a directory.
//
// Inside of dir, this will create a directory based on the name of
...
...
@@ -120,5 +228,26 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
return
cdir
,
err
}
}
return
cdir
,
nil
// Write out deployment.yaml
val
=
[]
byte
(
defaultDeployment
)
if
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
cdir
,
TemplatesDir
,
DeploymentName
),
val
,
0644
);
err
!=
nil
{
return
cdir
,
err
}
// Write out service.yaml
val
=
[]
byte
(
defaultService
)
if
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
cdir
,
TemplatesDir
,
ServiceName
),
val
,
0644
);
err
!=
nil
{
return
cdir
,
err
}
// Write out NOTES.txt
val
=
[]
byte
(
defaultNotes
)
if
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
cdir
,
TemplatesDir
,
NotesName
),
val
,
0644
);
err
!=
nil
{
return
cdir
,
err
}
// Write out _helpers.tpl
val
=
[]
byte
(
defaultHelpers
)
return
cdir
,
ioutil
.
WriteFile
(
filepath
.
Join
(
cdir
,
TemplatesDir
,
HelpersName
),
val
,
0644
)
}
pkg/chartutil/create_test.go
View file @
5ea81b47
...
...
@@ -62,7 +62,15 @@ func TestCreate(t *testing.T) {
if
fi
,
err
:=
os
.
Stat
(
filepath
.
Join
(
dir
,
f
));
err
!=
nil
{
t
.
Errorf
(
"Expected %s file: %s"
,
f
,
err
)
}
else
if
fi
.
IsDir
()
{
t
.
Errorf
(
"Expected %s to be a fle."
,
f
)
t
.
Errorf
(
"Expected %s to be a file."
,
f
)
}
}
for
_
,
f
:=
range
[]
string
{
NotesName
,
DeploymentName
,
ServiceName
,
HelpersName
}
{
if
fi
,
err
:=
os
.
Stat
(
filepath
.
Join
(
dir
,
TemplatesDir
,
f
));
err
!=
nil
{
t
.
Errorf
(
"Expected %s file: %s"
,
f
,
err
)
}
else
if
fi
.
IsDir
()
{
t
.
Errorf
(
"Expected %s to be a file."
,
f
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment