From 8154135e8d45e9e4f440ef9a15418a7c353b94f4 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Thu, 28 Sep 2023 10:34:42 +0200 Subject: [PATCH] feat: move some packages --- .../controllers/stack/stack_reconciler.go | 11 ++++++++++- .../controllers/stack/stack_reconciler_test.go | 4 ++-- .../auth/handler.go} | 16 ++++++++-------- .../control/handler.go} | 13 ++++++------- .../gateway/handler.go} | 12 ++++++------ .../ledger/handler.go} | 18 +++++++++--------- .../orchestration/handler.go} | 18 +++++++++--------- .../payments/handler.go} | 18 +++++++++--------- .../{handlers => modules/search}/benthos/fs.go | 0 .../search}/benthos/global/config.yaml | 0 .../search/handler.go} | 16 ++++++++-------- .../stargate/handler.go} | 12 ++++++------ .../handler_utils.go => modules/utils.go} | 4 ++-- .../wallets/handler.go} | 12 ++++++------ .../webhooks/handler.go} | 18 +++++++++--------- 15 files changed, 90 insertions(+), 82 deletions(-) rename components/operator/internal/{handlers/handler_auth.go => modules/auth/handler.go} (89%) rename components/operator/internal/{handlers/handler_control.go => modules/control/handler.go} (89%) rename components/operator/internal/{handlers/handler_gateway.go => modules/gateway/handler.go} (95%) rename components/operator/internal/{handlers/handler_ledger.go => modules/ledger/handler.go} (89%) rename components/operator/internal/{handlers/handler_orchestration.go => modules/orchestration/handler.go} (84%) rename components/operator/internal/{handlers/handler_payments.go => modules/payments/handler.go} (94%) rename components/operator/internal/{handlers => modules/search}/benthos/fs.go (100%) rename components/operator/internal/{handlers => modules/search}/benthos/global/config.yaml (100%) rename components/operator/internal/{handlers/handler_search.go => modules/search/handler.go} (97%) rename components/operator/internal/{handlers/handler_stargate.go => modules/stargate/handler.go} (90%) rename components/operator/internal/{handlers/handler_utils.go => modules/utils.go} (96%) rename components/operator/internal/{handlers/handler_wallets.go => modules/wallets/handler.go} (95%) rename components/operator/internal/{handlers/handler_webhooks.go => modules/webhooks/handler.go} (83%) diff --git a/components/operator/internal/controllers/stack/stack_reconciler.go b/components/operator/internal/controllers/stack/stack_reconciler.go index 2fba28813b..2add2300f7 100644 --- a/components/operator/internal/controllers/stack/stack_reconciler.go +++ b/components/operator/internal/controllers/stack/stack_reconciler.go @@ -28,7 +28,16 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - _ "github.com/formancehq/operator/internal/handlers" + _ "github.com/formancehq/operator/internal/modules/auth" + _ "github.com/formancehq/operator/internal/modules/control" + _ "github.com/formancehq/operator/internal/modules/gateway" + _ "github.com/formancehq/operator/internal/modules/ledger" + _ "github.com/formancehq/operator/internal/modules/orchestration" + _ "github.com/formancehq/operator/internal/modules/payments" + _ "github.com/formancehq/operator/internal/modules/search" + _ "github.com/formancehq/operator/internal/modules/stargate" + _ "github.com/formancehq/operator/internal/modules/wallets" + _ "github.com/formancehq/operator/internal/modules/webhooks" ) const ( diff --git a/components/operator/internal/controllers/stack/stack_reconciler_test.go b/components/operator/internal/controllers/stack/stack_reconciler_test.go index ad188c1f40..6a6dbf51b2 100644 --- a/components/operator/internal/controllers/stack/stack_reconciler_test.go +++ b/components/operator/internal/controllers/stack/stack_reconciler_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/formancehq/operator/internal/modules/auth" "os" "path/filepath" "runtime/debug" @@ -12,7 +13,6 @@ import ( "github.com/davecgh/go-spew/spew" stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" - "github.com/formancehq/operator/internal/handlers" "github.com/formancehq/operator/internal/modules" "github.com/google/go-cmp/cmp" . "github.com/onsi/ginkgo/v2" @@ -31,7 +31,7 @@ func init() { stackv1beta3.ClientSecretGenerator = func() string { return "mocked-secret" } - handlers.RSAKeyGenerator = func() string { + auth.RSAKeyGenerator = func() string { return "fake-rsa-key" } modules.CreatePostgresDatabase = func(ctx context.Context, dsn, dbName string) error { diff --git a/components/operator/internal/handlers/handler_auth.go b/components/operator/internal/modules/auth/handler.go similarity index 89% rename from components/operator/internal/handlers/handler_auth.go rename to components/operator/internal/modules/auth/handler.go index fbdcd29c96..addcdd83c6 100644 --- a/components/operator/internal/handlers/handler_auth.go +++ b/components/operator/internal/modules/auth/handler.go @@ -1,4 +1,4 @@ -package handlers +package auth import ( "bytes" @@ -14,13 +14,13 @@ import ( "gopkg.in/yaml.v3" ) -type authModule struct{} +type module struct{} -func (a authModule) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { +func (a module) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { return ctx.Configuration.Spec.Services.Auth.Postgres } -func (a authModule) Versions() map[string]modules.Version { +func (a module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -40,11 +40,11 @@ func (a authModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*authModule)(nil) -var _ modules.PostgresAwareModule = (*authModule)(nil) +var _ modules.Module = (*module)(nil) +var _ modules.PostgresAwareModule = (*module)(nil) func init() { - modules.Register("auth", &authModule{}) + modules.Register("auth", &module{}) } func resolveAuthContainer(resolveContext modules.ContainerResolutionContext) modules.Container { @@ -63,7 +63,7 @@ func resolveAuthContainer(resolveContext modules.ContainerResolutionContext) mod Args: []string{"serve"}, Env: env, Image: modules.GetImage("auth", resolveContext.Versions.Spec.Auth), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Auth.ResourceProperties, modules.ResourceSizeSmall(), ), diff --git a/components/operator/internal/handlers/handler_control.go b/components/operator/internal/modules/control/handler.go similarity index 89% rename from components/operator/internal/handlers/handler_control.go rename to components/operator/internal/modules/control/handler.go index 5681d4477d..c2405cb52f 100644 --- a/components/operator/internal/handlers/handler_control.go +++ b/components/operator/internal/modules/control/handler.go @@ -1,15 +1,14 @@ -package handlers +package control import ( "fmt" - stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" "github.com/formancehq/operator/internal/modules" ) -type controlModule struct{} +type module struct{} -func (c controlModule) Versions() map[string]modules.Version { +func (c module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -43,7 +42,7 @@ func (c controlModule) Versions() map[string]modules.Version { Name: "control", Image: modules.GetImage("control", resolveContext.Versions.Spec.Control), Env: env, - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Control.ResourceProperties, modules.ResourceSizeMedium(), ), @@ -55,8 +54,8 @@ func (c controlModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*controlModule)(nil) +var _ modules.Module = (*module)(nil) func init() { - modules.Register("control", &controlModule{}) + modules.Register("control", &module{}) } diff --git a/components/operator/internal/handlers/handler_gateway.go b/components/operator/internal/modules/gateway/handler.go similarity index 95% rename from components/operator/internal/handlers/handler_gateway.go rename to components/operator/internal/modules/gateway/handler.go index e693da7087..fd29272f3e 100644 --- a/components/operator/internal/handlers/handler_gateway.go +++ b/components/operator/internal/modules/gateway/handler.go @@ -1,4 +1,4 @@ -package handlers +package gateway import ( "bytes" @@ -13,9 +13,9 @@ const ( gatewayPort = 8000 ) -type gatewayModule struct{} +type module struct{} -func (g gatewayModule) Versions() map[string]modules.Version { +func (g module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -45,7 +45,7 @@ func (g gatewayModule) Versions() map[string]modules.Version { }, Image: modules.GetImage("gateway", resolveContext.Versions.Spec.Gateway), Env: modules.NewEnv(), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Gateway.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -57,10 +57,10 @@ func (g gatewayModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*gatewayModule)(nil) +var _ modules.Module = (*module)(nil) func init() { - modules.Register("gateway", &gatewayModule{}) + modules.Register("gateway", &module{}) } func createCaddyfile(context modules.ServiceInstallContext) string { diff --git a/components/operator/internal/handlers/handler_ledger.go b/components/operator/internal/modules/ledger/handler.go similarity index 89% rename from components/operator/internal/handlers/handler_ledger.go rename to components/operator/internal/modules/ledger/handler.go index d2a39d1c39..db72132553 100644 --- a/components/operator/internal/handlers/handler_ledger.go +++ b/components/operator/internal/modules/ledger/handler.go @@ -1,4 +1,4 @@ -package handlers +package ledger import ( "strconv" @@ -7,13 +7,13 @@ import ( "github.com/formancehq/operator/internal/modules" ) -type ledgerModule struct{} +type module struct{} -func (l ledgerModule) Postgres(ctx modules.Context) v1beta3.PostgresConfig { +func (l module) Postgres(ctx modules.Context) v1beta3.PostgresConfig { return ctx.Configuration.Spec.Services.Ledger.Postgres } -func (l ledgerModule) Versions() map[string]modules.Version { +func (l module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -59,7 +59,7 @@ func (l ledgerModule) Versions() map[string]modules.Version { } return modules.Container{ - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Ledger.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -87,7 +87,7 @@ func (l ledgerModule) Versions() map[string]modules.Version { ).Append(modules.BrokerEnvVars(resolveContext.Configuration.Spec.Broker, "ledger")...) return modules.Container{ - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Ledger.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -103,9 +103,9 @@ func (l ledgerModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*ledgerModule)(nil) -var _ modules.PostgresAwareModule = (*ledgerModule)(nil) +var _ modules.Module = (*module)(nil) +var _ modules.PostgresAwareModule = (*module)(nil) func init() { - modules.Register("ledger", &ledgerModule{}) + modules.Register("ledger", &module{}) } diff --git a/components/operator/internal/handlers/handler_orchestration.go b/components/operator/internal/modules/orchestration/handler.go similarity index 84% rename from components/operator/internal/handlers/handler_orchestration.go rename to components/operator/internal/modules/orchestration/handler.go index 9519a11582..fd48a00966 100644 --- a/components/operator/internal/handlers/handler_orchestration.go +++ b/components/operator/internal/modules/orchestration/handler.go @@ -1,17 +1,17 @@ -package handlers +package orchestration import ( stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" "github.com/formancehq/operator/internal/modules" ) -type orchestrationModule struct{} +type module struct{} -func (o orchestrationModule) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { +func (o module) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { return ctx.Configuration.Spec.Services.Orchestration.Postgres } -func (o orchestrationModule) Versions() map[string]modules.Version { +func (o module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -29,7 +29,7 @@ func (o orchestrationModule) Versions() map[string]modules.Version { return modules.Container{ Env: orchestrationEnvVars(resolveContext), Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -45,7 +45,7 @@ func (o orchestrationModule) Versions() map[string]modules.Version { Env: orchestrationEnvVars(resolveContext), Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration), Args: []string{"worker"}, - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -58,11 +58,11 @@ func (o orchestrationModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*orchestrationModule)(nil) -var _ modules.PostgresAwareModule = (*orchestrationModule)(nil) +var _ modules.Module = (*module)(nil) +var _ modules.PostgresAwareModule = (*module)(nil) func init() { - modules.Register("orchestration", &orchestrationModule{}) + modules.Register("orchestration", &module{}) } func orchestrationEnvVars(resolveContext modules.ContainerResolutionContext) modules.ContainerEnv { diff --git a/components/operator/internal/handlers/handler_payments.go b/components/operator/internal/modules/payments/handler.go similarity index 94% rename from components/operator/internal/handlers/handler_payments.go rename to components/operator/internal/modules/payments/handler.go index 1b75410aad..fa6044d1aa 100644 --- a/components/operator/internal/handlers/handler_payments.go +++ b/components/operator/internal/modules/payments/handler.go @@ -1,4 +1,4 @@ -package handlers +package payments import ( "database/sql" @@ -13,13 +13,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" ) -type paymentsModule struct{} +type module struct{} -func (p paymentsModule) Postgres(ctx modules.Context) v1beta3.PostgresConfig { +func (p module) Postgres(ctx modules.Context) v1beta3.PostgresConfig { return ctx.Configuration.Spec.Services.Payments.Postgres } -func (p paymentsModule) Versions() map[string]modules.Version { +func (p module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -39,7 +39,7 @@ func (p paymentsModule) Versions() map[string]modules.Version { return modules.Container{ Env: paymentsEnvVars(resolveContext), Image: modules.GetImage("payments", resolveContext.Versions.Spec.Payments), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Payments.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -153,11 +153,11 @@ func (p paymentsModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*paymentsModule)(nil) -var _ modules.PostgresAwareModule = (*paymentsModule)(nil) +var _ modules.Module = (*module)(nil) +var _ modules.PostgresAwareModule = (*module)(nil) func init() { - modules.Register("payments", &paymentsModule{}) + modules.Register("payments", &module{}) } func paymentsEnvVars(resolveContext modules.ContainerResolutionContext) modules.ContainerEnv { @@ -205,7 +205,7 @@ func paymentsServices( return modules.Container{ Env: env(resolveContext), Image: modules.GetImage("payments", resolveContext.Versions.Spec.Payments), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Payments.ResourceProperties, modules.ResourceSizeSmall(), ), diff --git a/components/operator/internal/handlers/benthos/fs.go b/components/operator/internal/modules/search/benthos/fs.go similarity index 100% rename from components/operator/internal/handlers/benthos/fs.go rename to components/operator/internal/modules/search/benthos/fs.go diff --git a/components/operator/internal/handlers/benthos/global/config.yaml b/components/operator/internal/modules/search/benthos/global/config.yaml similarity index 100% rename from components/operator/internal/handlers/benthos/global/config.yaml rename to components/operator/internal/modules/search/benthos/global/config.yaml diff --git a/components/operator/internal/handlers/handler_search.go b/components/operator/internal/modules/search/handler.go similarity index 97% rename from components/operator/internal/handlers/handler_search.go rename to components/operator/internal/modules/search/handler.go index 326a9aadad..3814a6f19f 100644 --- a/components/operator/internal/handlers/handler_search.go +++ b/components/operator/internal/modules/search/handler.go @@ -1,4 +1,4 @@ -package handlers +package search import ( "bytes" @@ -11,8 +11,8 @@ import ( stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" "github.com/formancehq/operator/internal/controllerutils" - benthosOperator "github.com/formancehq/operator/internal/handlers/benthos" "github.com/formancehq/operator/internal/modules" + benthosOperator "github.com/formancehq/operator/internal/modules/search/benthos" "github.com/formancehq/search/benthos" "github.com/formancehq/search/pkg/searchengine" "github.com/opensearch-project/opensearch-go" @@ -22,9 +22,9 @@ const ( benthosImage = "public.ecr.aws/h9j1u6h3/jeffail/benthos:4.12.1" ) -type searchModule struct{} +type module struct{} -func (s searchModule) Versions() map[string]modules.Version { +func (s module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -74,14 +74,14 @@ func (s searchModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*searchModule)(nil) +var _ modules.Module = (*module)(nil) var CreateOpenSearchClient = func(cfg opensearch.Config) (*opensearch.Client, error) { return opensearch.NewClient(cfg) } func init() { - modules.Register("search", &searchModule{}) + modules.Register("search", &module{}) } func reindexCron(ctx modules.Context) []modules.Cron { @@ -171,7 +171,7 @@ func searchService(ctx modules.ModuleContext) *modules.Service { return modules.Container{ Env: env, Image: modules.GetImage("search", resolveContext.Versions.Spec.Search), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Search.SearchResourceProperties, modules.ResourceSizeSmall(), ), @@ -259,7 +259,7 @@ func benthosService(ctx modules.ModuleContext) *modules.Service { Image: benthosImage, Command: cmd, DisableRollingUpdate: true, - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Search.BenthosResourceProperties, modules.ResourceSizeSmall(), ), diff --git a/components/operator/internal/handlers/handler_stargate.go b/components/operator/internal/modules/stargate/handler.go similarity index 90% rename from components/operator/internal/handlers/handler_stargate.go rename to components/operator/internal/modules/stargate/handler.go index 6a9b0ff189..573d5b9a07 100644 --- a/components/operator/internal/handlers/handler_stargate.go +++ b/components/operator/internal/modules/stargate/handler.go @@ -1,4 +1,4 @@ -package handlers +package stargate import ( "strconv" @@ -8,9 +8,9 @@ import ( "github.com/formancehq/operator/internal/modules" ) -type stargateModule struct{} +type module struct{} -func (s stargateModule) Versions() map[string]modules.Version { +func (s module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -32,7 +32,7 @@ func (s stargateModule) Versions() map[string]modules.Version { return modules.Container{ Env: stargateClientEnvVars(resolveContext), Image: modules.GetImage("stargate", resolveContext.Versions.Spec.Stargate), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Stargate.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -45,7 +45,7 @@ func (s stargateModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*stargateModule)(nil) +var _ modules.Module = (*module)(nil) func stargateClientEnvVars(resolveContext modules.ContainerResolutionContext) modules.ContainerEnv { l := strings.Split(resolveContext.Stack.ObjectMeta.Name, "-") @@ -65,5 +65,5 @@ func stargateClientEnvVars(resolveContext modules.ContainerResolutionContext) mo } func init() { - modules.Register("stargate", &stargateModule{}) + modules.Register("stargate", &module{}) } diff --git a/components/operator/internal/handlers/handler_utils.go b/components/operator/internal/modules/utils.go similarity index 96% rename from components/operator/internal/handlers/handler_utils.go rename to components/operator/internal/modules/utils.go index 1d09dc9516..9779ee9348 100644 --- a/components/operator/internal/handlers/handler_utils.go +++ b/components/operator/internal/modules/utils.go @@ -1,4 +1,4 @@ -package handlers +package modules import ( stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" @@ -6,7 +6,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) -func getResourcesWithDefault( +func GetResourcesWithDefault( resourceProperties *stackv1beta3.ResourceProperties, defaultResources v1.ResourceRequirements, ) v1.ResourceRequirements { diff --git a/components/operator/internal/handlers/handler_wallets.go b/components/operator/internal/modules/wallets/handler.go similarity index 95% rename from components/operator/internal/handlers/handler_wallets.go rename to components/operator/internal/modules/wallets/handler.go index de8d4cec23..3be7550817 100644 --- a/components/operator/internal/handlers/handler_wallets.go +++ b/components/operator/internal/modules/wallets/handler.go @@ -1,4 +1,4 @@ -package handlers +package wallets import ( "bytes" @@ -15,9 +15,9 @@ import ( "github.com/pkg/errors" ) -type walletsModule struct{} +type module struct{} -func (w walletsModule) Versions() map[string]modules.Version { +func (w module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: service, @@ -108,10 +108,10 @@ func (w walletsModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*walletsModule)(nil) +var _ modules.Module = (*module)(nil) func init() { - modules.Register("wallets", &walletsModule{}) + modules.Register("wallets", &module{}) } func service(ctx modules.ModuleContext) modules.Services { @@ -131,7 +131,7 @@ func service(ctx modules.ModuleContext) modules.Services { modules.Env("STACK_CLIENT_SECRET", resolveContext.Stack.Status.StaticAuthClients["wallets"].Secrets[0]), }, Image: modules.GetImage("wallets", resolveContext.Versions.Spec.Wallets), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Wallets.ResourceProperties, modules.ResourceSizeSmall(), ), diff --git a/components/operator/internal/handlers/handler_webhooks.go b/components/operator/internal/modules/webhooks/handler.go similarity index 83% rename from components/operator/internal/handlers/handler_webhooks.go rename to components/operator/internal/modules/webhooks/handler.go index 77527804e4..86c7b174a3 100644 --- a/components/operator/internal/handlers/handler_webhooks.go +++ b/components/operator/internal/modules/webhooks/handler.go @@ -1,4 +1,4 @@ -package handlers +package webhooks import ( "strings" @@ -7,13 +7,13 @@ import ( "github.com/formancehq/operator/internal/modules" ) -type webhooksModule struct{} +type module struct{} -func (w webhooksModule) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { +func (w module) Postgres(ctx modules.Context) stackv1beta3.PostgresConfig { return ctx.Configuration.Spec.Services.Webhooks.Postgres } -func (w webhooksModule) Versions() map[string]modules.Version { +func (w module) Versions() map[string]modules.Version { return map[string]modules.Version{ "v0.0.0": { Services: func(ctx modules.ModuleContext) modules.Services { @@ -28,7 +28,7 @@ func (w webhooksModule) Versions() map[string]modules.Version { return modules.Container{ Image: modules.GetImage("webhooks", resolveContext.Versions.Spec.Webhooks), Env: webhooksEnvVars(resolveContext.Configuration), - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Webhooks.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -51,7 +51,7 @@ func (w webhooksModule) Versions() map[string]modules.Version { }, " ")), ), Args: []string{"worker"}, - Resources: getResourcesWithDefault( + Resources: modules.GetResourcesWithDefault( resolveContext.Configuration.Spec.Services.Webhooks.ResourceProperties, modules.ResourceSizeSmall(), ), @@ -64,11 +64,11 @@ func (w webhooksModule) Versions() map[string]modules.Version { } } -var _ modules.Module = (*webhooksModule)(nil) -var _ modules.PostgresAwareModule = (*webhooksModule)(nil) +var _ modules.Module = (*module)(nil) +var _ modules.PostgresAwareModule = (*module)(nil) func init() { - modules.Register("webhooks", &webhooksModule{}) + modules.Register("webhooks", &module{}) } func webhooksEnvVars(configuration *stackv1beta3.Configuration) modules.ContainerEnv {