Commit 27480470 authored by Adam Reese's avatar Adam Reese Committed by GitHub

Merge pull request #1118 from adamreese/feat/1117-init-version

feat(cmd): install latest tagged image on `helm init`
parents d5170d23 5d820c4d
...@@ -17,15 +17,20 @@ limitations under the License. ...@@ -17,15 +17,20 @@ limitations under the License.
package installer // import "k8s.io/helm/cmd/helm/installer" package installer // import "k8s.io/helm/cmd/helm/installer"
import ( import (
"bytes"
"fmt" "fmt"
"text/template" "strings"
"github.com/Masterminds/sprig" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
"k8s.io/helm/pkg/version"
) )
const defaultImage = "gcr.io/kubernetes-helm/tiller"
// Install uses kubernetes client to install tiller // Install uses kubernetes client to install tiller
// //
// Returns the string output received from the operation, and an error if the // Returns the string output received from the operation, and an error if the
...@@ -43,59 +48,89 @@ func Install(namespace, image string, verbose bool) error { ...@@ -43,59 +48,89 @@ func Install(namespace, image string, verbose bool) error {
namespace = ns namespace = ns
} }
var b bytes.Buffer c, err := kc.Client()
if err != nil {
// Add main install YAML
istpl := template.New("install").Funcs(sprig.TxtFuncMap())
cfg := struct {
Namespace, Image string
}{namespace, image}
if err := template.Must(istpl.Parse(InstallYAML)).Execute(&b, cfg); err != nil {
return err return err
} }
if verbose { ns := generateNamespace(namespace)
fmt.Println(b.String()) if _, err := c.Namespaces().Create(ns); err != nil {
if !errors.IsAlreadyExists(err) {
return err
}
}
if image == "" {
// strip git sha off version
tag := strings.Split(version.Version, "+")[0]
image = fmt.Sprintf("%s:%s", defaultImage, tag)
} }
return kc.Create(namespace, &b) rc := generateDeployment(image)
_, err = c.Deployments(namespace).Create(rc)
return err
}
func generateLabels(labels map[string]string) map[string]string {
labels["app"] = "helm"
return labels
}
func generateDeployment(image string) *extensions.Deployment {
labels := generateLabels(map[string]string{"name": "tiller"})
d := &extensions.Deployment{
ObjectMeta: api.ObjectMeta{
Name: "tiller-deploy",
Labels: labels,
},
Spec: extensions.DeploymentSpec{
Replicas: 1,
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: labels,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "tiller",
Image: image,
ImagePullPolicy: "Always",
Ports: []api.ContainerPort{{ContainerPort: 44134, Name: "tiller"}},
LivenessProbe: &api.Probe{
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/liveness",
Port: intstr.FromInt(44135),
},
},
InitialDelaySeconds: 1,
TimeoutSeconds: 1,
},
ReadinessProbe: &api.Probe{
Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{
Path: "/readiness",
Port: intstr.FromInt(44135),
},
},
InitialDelaySeconds: 1,
TimeoutSeconds: 1,
},
},
},
},
},
},
}
return d
} }
// InstallYAML is the installation YAML for DM. func generateNamespace(namespace string) *api.Namespace {
const InstallYAML = ` return &api.Namespace{
--- ObjectMeta: api.ObjectMeta{
apiVersion: extensions/v1beta1 Name: namespace,
kind: Deployment Labels: generateLabels(map[string]string{"name": "helm-namespace"}),
metadata: },
name: tiller-deploy }
namespace: {{ .Namespace }} }
spec:
replicas: 1
template:
metadata:
labels:
app: helm
name: tiller
spec:
containers:
- image: {{default "gcr.io/kubernetes-helm/tiller:canary" .Image}}
name: tiller
ports:
- containerPort: 44134
name: tiller
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /liveness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /readiness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
`
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment