Skip to content

Commit

Permalink
Add --replicas option for HA fixes #2334
Browse files Browse the repository at this point in the history
  • Loading branch information
onorua committed Mar 6, 2018
1 parent b49a396 commit 2f252e9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/helm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type initCmd struct {
kubeClient kubernetes.Interface
serviceAccount string
maxHistory int
replicas int
wait bool
}

Expand Down Expand Up @@ -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.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.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.VarP(&i.opts.Output, "output", "o", "skip installation and output Tiller's manifest in specified format (json or yaml)")
Expand Down Expand Up @@ -175,6 +177,7 @@ func (i *initCmd) run() error {
i.opts.ForceUpgrade = i.forceUpgrade
i.opts.ServiceAccount = i.serviceAccount
i.opts.MaxHistory = i.maxHistory
i.opts.Replicas = i.replicas

writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error {
w := i.out
Expand Down
1 change: 1 addition & 0 deletions cmd/helm/installer/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func generateDeployment(opts *Options) (*v1beta1.Deployment, error) {
Labels: labels,
},
Spec: v1beta1.DeploymentSpec{
Replicas: opts.getReplicas(),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Expand Down
27 changes: 27 additions & 0 deletions cmd/helm/installer/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func TestInstall(t *testing.T) {
if ports != 2 {
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
})
fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) {
Expand All @@ -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) {
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
name := "tiller-secret"
Expand Down
13 changes: 13 additions & 0 deletions cmd/helm/installer/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ type Options struct {
// Less than or equal to zero means no limit.
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 string

Expand Down Expand Up @@ -109,6 +114,14 @@ func (opts *Options) pullPolicy() v1.PullPolicy {
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 }

// valuesMap returns user set values in map format
Expand Down
3 changes: 2 additions & 1 deletion docs/helm/helm_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ helm init
--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)
--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
--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")
Expand All @@ -69,4 +70,4 @@ helm init
### SEE ALSO
* [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

0 comments on commit 2f252e9

Please sign in to comment.