github.com/felipejfc/helm@v2.1.2+incompatible/cmd/helm/installer/install.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package installer // import "k8s.io/helm/cmd/helm/installer" 18 19 import ( 20 "fmt" 21 22 "github.com/ghodss/yaml" 23 24 "k8s.io/kubernetes/pkg/api" 25 "k8s.io/kubernetes/pkg/apis/extensions" 26 extensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion" 27 "k8s.io/kubernetes/pkg/util/intstr" 28 29 "k8s.io/helm/pkg/version" 30 ) 31 32 const defaultImage = "gcr.io/kubernetes-helm/tiller" 33 34 // Install uses kubernetes client to install tiller 35 // 36 // Returns the string output received from the operation, and an error if the 37 // command failed. 38 // 39 // If verbose is true, this will print the manifest to stdout. 40 func Install(client extensionsclient.DeploymentsGetter, namespace, image string, canary, verbose bool) error { 41 obj := deployment(namespace, image, canary) 42 _, err := client.Deployments(obj.Namespace).Create(obj) 43 return err 44 } 45 46 // deployment gets the deployment object that installs Tiller. 47 func deployment(namespace, image string, canary bool) *extensions.Deployment { 48 switch { 49 case canary: 50 image = defaultImage + ":canary" 51 case image == "": 52 image = fmt.Sprintf("%s:%s", defaultImage, version.Version) 53 } 54 return generateDeployment(namespace, image) 55 } 56 57 // DeploymentManifest gets the manifest (as a string) that describes the Tiller Deployment 58 // resource. 59 func DeploymentManifest(namespace, image string, canary bool) (string, error) { 60 obj := deployment(namespace, image, canary) 61 62 buf, err := yaml.Marshal(obj) 63 return string(buf), err 64 } 65 66 func generateLabels(labels map[string]string) map[string]string { 67 labels["app"] = "helm" 68 return labels 69 } 70 71 func generateDeployment(namespace, image string) *extensions.Deployment { 72 labels := generateLabels(map[string]string{"name": "tiller"}) 73 d := &extensions.Deployment{ 74 ObjectMeta: api.ObjectMeta{ 75 Namespace: namespace, 76 Name: "tiller-deploy", 77 Labels: labels, 78 }, 79 Spec: extensions.DeploymentSpec{ 80 Replicas: 1, 81 Template: api.PodTemplateSpec{ 82 ObjectMeta: api.ObjectMeta{ 83 Labels: labels, 84 }, 85 Spec: api.PodSpec{ 86 Containers: []api.Container{ 87 { 88 Name: "tiller", 89 Image: image, 90 ImagePullPolicy: "IfNotPresent", 91 Ports: []api.ContainerPort{{ContainerPort: 44134, Name: "tiller"}}, 92 LivenessProbe: &api.Probe{ 93 Handler: api.Handler{ 94 HTTPGet: &api.HTTPGetAction{ 95 Path: "/liveness", 96 Port: intstr.FromInt(44135), 97 }, 98 }, 99 InitialDelaySeconds: 1, 100 TimeoutSeconds: 1, 101 }, 102 ReadinessProbe: &api.Probe{ 103 Handler: api.Handler{ 104 HTTPGet: &api.HTTPGetAction{ 105 Path: "/readiness", 106 Port: intstr.FromInt(44135), 107 }, 108 }, 109 InitialDelaySeconds: 1, 110 TimeoutSeconds: 1, 111 }, 112 }, 113 }, 114 }, 115 }, 116 }, 117 } 118 return d 119 }