From cadc134b8efb437cc6da0caa387eb50b4a9bfd58 Mon Sep 17 00:00:00 2001 From: Ishan Arya Date: Tue, 25 Jul 2023 10:54:29 +0530 Subject: [PATCH] refactor: public ScaleParams & StartParams (#47) * refactor: public ScaleParams & StartParams * chore: update config.go --- modules/firehose/config.go | 8 ++++++++ modules/firehose/driver_plan.go | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/firehose/config.go b/modules/firehose/config.go index 9f17e939..8e1a0a29 100644 --- a/modules/firehose/config.go +++ b/modules/firehose/config.go @@ -28,6 +28,14 @@ var ( validateConfig = validator.FromJSONSchema(configSchemaRaw) ) +type ScaleParams struct { + Replicas int `json:"replicas"` +} + +type StartParams struct { + StopTime *time.Time `json:"stop_time"` +} + type Config struct { // Stopped flag when set forces the firehose to be stopped on next sync. Stopped bool `json:"stopped"` diff --git a/modules/firehose/driver_plan.go b/modules/firehose/driver_plan.go index 70e1363d..b2b160a8 100644 --- a/modules/firehose/driver_plan.go +++ b/modules/firehose/driver_plan.go @@ -3,7 +3,6 @@ package firehose import ( "context" "encoding/json" - "time" "github.com/goto/entropy/core/module" "github.com/goto/entropy/core/resource" @@ -51,9 +50,7 @@ func (fd *firehoseDriver) planChange(exr module.ExpandedResource, act module.Act curConf = newConf case ScaleAction: - var scaleParams struct { - Replicas int `json:"replicas"` - } + var scaleParams ScaleParams if err := json.Unmarshal(act.Params, &scaleParams); err != nil { return nil, errors.ErrInvalid.WithMsgf("invalid params for scale action").WithCausef(err.Error()) } else if scaleParams.Replicas < 1 { @@ -63,9 +60,7 @@ func (fd *firehoseDriver) planChange(exr module.ExpandedResource, act module.Act curConf.Replicas = scaleParams.Replicas case StartAction: - var startParams struct { - StopTime *time.Time `json:"stop_time"` - } + var startParams StartParams if err := json.Unmarshal(act.Params, &startParams); err != nil { return nil, errors.ErrInvalid.WithMsgf("invalid params for start action").WithCausef(err.Error()) }