From 30728a12d2c404dfa97ae64c44a5c71c31bc0e12 Mon Sep 17 00:00:00 2001 From: Xieshen Zhang Date: Wed, 18 Mar 2020 11:40:53 -0400 Subject: [PATCH] [KOGITO-1474] Fix issue Kogito service cannot be scaled to 0 (#220) --- bddframework/framework/kogitoapp.go | 2 +- bddframework/framework/kogitodataindex.go | 6 +++--- bddframework/framework/kogitojobsservice.go | 10 +++++----- bddframework/steps/kogitojobsservice.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bddframework/framework/kogitoapp.go b/bddframework/framework/kogitoapp.go index bec5df038..729c911f4 100644 --- a/bddframework/framework/kogitoapp.go +++ b/bddframework/framework/kogitoapp.go @@ -147,7 +147,7 @@ func SetKogitoAppReplicas(namespace, name string, nbPods int) error { return fmt.Errorf("No KogitoApp found with name %s in namespace %s", name, namespace) } replicas := int32(nbPods) - kogitoApp.Spec.KogitoServiceSpec.Replicas = replicas + kogitoApp.Spec.KogitoServiceSpec.Replicas = &replicas return kubernetes.ResourceC(kubeClient).Update(kogitoApp) } diff --git a/bddframework/framework/kogitodataindex.go b/bddframework/framework/kogitodataindex.go index 0e21395f4..cb7524434 100644 --- a/bddframework/framework/kogitodataindex.go +++ b/bddframework/framework/kogitodataindex.go @@ -34,13 +34,13 @@ func InstallKogitoDataIndexService(namespace string, installerType InstallerType case CLIInstallerType: return cliInstallKogitoDataIndex(namespace, replicas) case CRInstallerType: - return crInstallKogitoDataIndex(namespace, replicas) + return crInstallKogitoDataIndex(namespace, int32(replicas)) default: panic(fmt.Errorf("Unknown installer type %s", installerType)) } } -func crInstallKogitoDataIndex(namespace string, replicas int) error { +func crInstallKogitoDataIndex(namespace string, replicas int32) error { // Get correct image tag image := framework.ConvertImageTagToImage(infrastructure.DefaultDataIndexImageFullTag) image.Tag = GetConfigServicesImageVersion() @@ -52,7 +52,7 @@ func crInstallKogitoDataIndex(namespace string, replicas int) error { }, Spec: v1alpha1.KogitoDataIndexSpec{ KogitoServiceSpec: v1alpha1.KogitoServiceSpec{ - Replicas: int32(replicas), + Replicas: &replicas, Image: image, }, }, diff --git a/bddframework/framework/kogitojobsservice.go b/bddframework/framework/kogitojobsservice.go index 1171254f3..bbbe56438 100644 --- a/bddframework/framework/kogitojobsservice.go +++ b/bddframework/framework/kogitojobsservice.go @@ -42,7 +42,7 @@ func InstallKogitoJobsService(namespace string, installerType InstallerType, rep } func crInstallKogitoJobsService(namespace string, replicas int, persistence bool) error { - service := getJobsServiceStub(namespace, replicas, persistence) + service := getJobsServiceStub(namespace, int32(replicas), persistence) if _, err := kubernetes.ResourceC(kubeClient).CreateIfNotExists(service); err != nil { return fmt.Errorf("Error creating Kogito jobs service: %v", err) @@ -100,7 +100,7 @@ func WaitForKogitoJobsService(namespace string, replicas, timeoutInMin int) erro } // SetKogitoJobsServiceReplicas sets the number of replicas for the Kogito Jobs Service -func SetKogitoJobsServiceReplicas(namespace string, nbPods int) error { +func SetKogitoJobsServiceReplicas(namespace string, nbPods int32) error { GetLogger(namespace).Infof("Set Kogito jobs service replica number to %d", nbPods) kogitoJobsService, err := GetKogitoJobsService(namespace) if err != nil { @@ -108,11 +108,11 @@ func SetKogitoJobsServiceReplicas(namespace string, nbPods int) error { } else if kogitoJobsService == nil { return fmt.Errorf("No Kogito jobs service found in namespace %s", namespace) } - kogitoJobsService.Spec.Replicas = int32(nbPods) + kogitoJobsService.Spec.Replicas = &nbPods return kubernetes.ResourceC(kubeClient).Update(kogitoJobsService) } -func getJobsServiceStub(namespace string, replicas int, persistence bool) *v1alpha1.KogitoJobsService { +func getJobsServiceStub(namespace string, replicas int32, persistence bool) *v1alpha1.KogitoJobsService { // Get correct image for tests image := framework.ConvertImageTagToImage(infrastructure.DefaultJobsServiceImageFullTag) image.Tag = GetConfigServicesImageVersion() @@ -124,7 +124,7 @@ func getJobsServiceStub(namespace string, replicas int, persistence bool) *v1alp }, Spec: v1alpha1.KogitoJobsServiceSpec{ KogitoServiceSpec: v1alpha1.KogitoServiceSpec{ - Replicas: int32(replicas), + Replicas: &replicas, Image: image, }, }, diff --git a/bddframework/steps/kogitojobsservice.go b/bddframework/steps/kogitojobsservice.go index b300748ad..87761eed2 100644 --- a/bddframework/steps/kogitojobsservice.go +++ b/bddframework/steps/kogitojobsservice.go @@ -40,7 +40,7 @@ func (data *Data) kogitoJobsServiceHasPodsRunningWithinMinutes(pods, timeoutInMi } func (data *Data) scaleKogitoJobsServiceToPodsWithinMinutes(nbPods, timeoutInMin int) error { - err := framework.SetKogitoJobsServiceReplicas(data.Namespace, nbPods) + err := framework.SetKogitoJobsServiceReplicas(data.Namespace, int32(nbPods)) if err != nil { return err }