Commit 2f252e95 authored by Yaroslav Molochko's avatar Yaroslav Molochko

Add --replicas option for HA fixes #2334

parent b49a3960
...@@ -86,6 +86,7 @@ type initCmd struct { ...@@ -86,6 +86,7 @@ type initCmd struct {
kubeClient kubernetes.Interface kubeClient kubernetes.Interface
serviceAccount string serviceAccount string
maxHistory int maxHistory int
replicas int
wait bool wait bool
} }
...@@ -130,6 +131,7 @@ func newInitCmd(out io.Writer) *cobra.Command { ...@@ -130,6 +131,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
f.BoolVar(&i.opts.EnableHostNetwork, "net-host", false, "install Tiller with net=host") f.BoolVar(&i.opts.EnableHostNetwork, "net-host", false, "install Tiller with net=host")
f.StringVar(&i.serviceAccount, "service-account", "", "name of service account") f.StringVar(&i.serviceAccount, "service-account", "", "name of service account")
f.IntVar(&i.maxHistory, "history-max", 0, "limit the maximum number of revisions saved per release. Use 0 for no limit.") f.IntVar(&i.maxHistory, "history-max", 0, "limit the maximum number of revisions saved per release. Use 0 for no limit.")
f.IntVar(&i.replicas, "replicas", 1, "amount of tiller instances to run on the cluster")
f.StringVar(&i.opts.NodeSelectors, "node-selectors", "", "labels to specify the node on which Tiller is installed (app=tiller,helm=rocks)") f.StringVar(&i.opts.NodeSelectors, "node-selectors", "", "labels to specify the node on which Tiller is installed (app=tiller,helm=rocks)")
f.VarP(&i.opts.Output, "output", "o", "skip installation and output Tiller's manifest in specified format (json or yaml)") f.VarP(&i.opts.Output, "output", "o", "skip installation and output Tiller's manifest in specified format (json or yaml)")
...@@ -175,6 +177,7 @@ func (i *initCmd) run() error { ...@@ -175,6 +177,7 @@ func (i *initCmd) run() error {
i.opts.ForceUpgrade = i.forceUpgrade i.opts.ForceUpgrade = i.forceUpgrade
i.opts.ServiceAccount = i.serviceAccount i.opts.ServiceAccount = i.serviceAccount
i.opts.MaxHistory = i.maxHistory i.opts.MaxHistory = i.maxHistory
i.opts.Replicas = i.replicas
writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error { writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error {
w := i.out w := i.out
......
...@@ -183,6 +183,7 @@ func generateDeployment(opts *Options) (*v1beta1.Deployment, error) { ...@@ -183,6 +183,7 @@ func generateDeployment(opts *Options) (*v1beta1.Deployment, error) {
Labels: labels, Labels: labels,
}, },
Spec: v1beta1.DeploymentSpec{ Spec: v1beta1.DeploymentSpec{
Replicas: opts.getReplicas(),
Template: v1.PodTemplateSpec{ Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Labels: labels, Labels: labels,
......
...@@ -211,6 +211,10 @@ func TestInstall(t *testing.T) { ...@@ -211,6 +211,10 @@ func TestInstall(t *testing.T) {
if ports != 2 { if ports != 2 {
t.Errorf("expected ports = 2, got '%d'", ports) t.Errorf("expected ports = 2, got '%d'", ports)
} }
replicas := obj.Spec.Replicas
if int(*replicas) != 1 {
t.Errorf("expected replicas = 1, got '%d'", replicas)
}
return true, obj, nil return true, obj, nil
}) })
fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) { fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) {
...@@ -236,6 +240,29 @@ func TestInstall(t *testing.T) { ...@@ -236,6 +240,29 @@ func TestInstall(t *testing.T) {
} }
} }
func TestInstallHA(t *testing.T) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
fc := &fake.Clientset{}
fc.AddReactor("create", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
obj := action.(testcore.CreateAction).GetObject().(*v1beta1.Deployment)
replicas := obj.Spec.Replicas
if int(*replicas) != 2 {
t.Errorf("expected replicas = 2, got '%d'", replicas)
}
return true, obj, nil
})
opts := &Options{
Namespace: v1.NamespaceDefault,
ImageSpec: image,
Replicas: 2,
}
if err := Install(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err)
}
}
func TestInstall_WithTLS(t *testing.T) { func TestInstall_WithTLS(t *testing.T) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0" image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
name := "tiller-secret" name := "tiller-secret"
......
...@@ -81,6 +81,11 @@ type Options struct { ...@@ -81,6 +81,11 @@ type Options struct {
// Less than or equal to zero means no limit. // Less than or equal to zero means no limit.
MaxHistory int MaxHistory int
// Replicas sets the amount of Tiller replicas to start
//
// Less than or equals to 1 means 1.
Replicas int
// NodeSelectors determine which nodes Tiller can land on. // NodeSelectors determine which nodes Tiller can land on.
NodeSelectors string NodeSelectors string
...@@ -109,6 +114,14 @@ func (opts *Options) pullPolicy() v1.PullPolicy { ...@@ -109,6 +114,14 @@ func (opts *Options) pullPolicy() v1.PullPolicy {
return v1.PullIfNotPresent return v1.PullIfNotPresent
} }
func (opts *Options) getReplicas() *int32 {
replicas := int32(1)
if opts.Replicas > 1 {
replicas = int32(opts.Replicas)
}
return &replicas
}
func (opts *Options) tls() bool { return opts.EnableTLS || opts.VerifyTLS } func (opts *Options) tls() bool { return opts.EnableTLS || opts.VerifyTLS }
// valuesMap returns user set values in map format // valuesMap returns user set values in map format
......
...@@ -43,6 +43,7 @@ helm init ...@@ -43,6 +43,7 @@ helm init
--node-selectors string labels to specify the node on which Tiller is installed (app=tiller,helm=rocks) --node-selectors string labels to specify the node on which Tiller is installed (app=tiller,helm=rocks)
-o, --output OutputFormat skip installation and output Tiller's manifest in specified format (json or yaml) -o, --output OutputFormat skip installation and output Tiller's manifest in specified format (json or yaml)
--override stringArray override values for the Tiller Deployment manifest (can specify multiple or separate values with commas: key1=val1,key2=val2) --override stringArray override values for the Tiller Deployment manifest (can specify multiple or separate values with commas: key1=val1,key2=val2)
--replicas int amount of tiller instances to run on the cluster (default 1)
--service-account string name of service account --service-account string name of service account
--skip-refresh do not refresh (download) the local repository cache --skip-refresh do not refresh (download) the local repository cache
--stable-repo-url string URL for stable repository (default "https://kubernetes-charts.storage.googleapis.com") --stable-repo-url string URL for stable repository (default "https://kubernetes-charts.storage.googleapis.com")
...@@ -69,4 +70,4 @@ helm init ...@@ -69,4 +70,4 @@ helm init
### SEE ALSO ### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 25-Jan-2018 ###### Auto generated by spf13/cobra on 6-Mar-2018
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