From 220f918d084d5624d348049c415b40e7ff7e9a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Moreno?= Date: Wed, 28 Nov 2018 17:31:21 +0100 Subject: [PATCH] Ability to scale Pravega Controller (#99) Signed-off-by: Adrian Moreno --- pkg/pravega/sync.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/pravega/sync.go b/pkg/pravega/sync.go index bd8f69481..e1b532f3d 100644 --- a/pkg/pravega/sync.go +++ b/pkg/pravega/sync.go @@ -55,6 +55,11 @@ func syncClusterSize(pravegaCluster *api.PravegaCluster) (err error) { return err } + err = syncControllerSize(pravegaCluster) + if err != nil { + return err + } + return nil } @@ -112,3 +117,30 @@ func syncSegmentStoreSize(pravegaCluster *api.PravegaCluster) (err error) { } return nil } + +func syncControllerSize(pravegaCluster *api.PravegaCluster) (err error) { + deploy := &appsv1.Deployment{ + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: "apps/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: k8sutil.DeploymentNameForController(pravegaCluster.Name), + Namespace: pravegaCluster.Namespace, + }, + } + + err = sdk.Get(deploy) + if err != nil { + return fmt.Errorf("failed to get deployment (%s): %v", deploy.Name, err) + } + + if *deploy.Spec.Replicas != pravegaCluster.Spec.Pravega.ControllerReplicas { + deploy.Spec.Replicas = &(pravegaCluster.Spec.Pravega.ControllerReplicas) + err = sdk.Update(deploy) + if err != nil { + return fmt.Errorf("failed to update size of deployment (%s): %v", deploy.Name, err) + } + } + return nil +}