Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move some packages #543

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/formancehq/operator/internal/modules/auth"
"os"
"path/filepath"
"runtime/debug"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handlers
package auth

import (
"bytes"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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(),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(),
),
Expand All @@ -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{})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handlers
package gateway

import (
"bytes"
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
),
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handlers
package ledger

import (
"strconv"
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
),
Expand Down Expand Up @@ -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(),
),
Expand All @@ -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{})
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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(),
),
Expand All @@ -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(),
),
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handlers
package payments

import (
"database/sql"
Expand All @@ -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 {
Expand All @@ -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(),
),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handlers
package search

import (
"bytes"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
),
Expand Down Expand Up @@ -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(),
),
Expand Down
Loading