Skip to content

Commit

Permalink
feat: add first draft of reconciliation service (account based) (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Dec 6, 2023
1 parent 4330cf4 commit c57bfb1
Show file tree
Hide file tree
Showing 49 changed files with 2,073 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ spec:
host: postgres-postgresql.formance.svc.cluster.local
port: 5432
disableSSLMode: true
reconciliation:
debug: true
payments:
postgres:
credentialsFromSecret: postgres
Expand Down
1 change: 1 addition & 0 deletions components/operator/.earthly/k8s-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ spec:
ledger: local
orchestration: local
payments: local
reconciliation: local
search: local
wallets: local
webhooks: local
Expand Down
17 changes: 9 additions & 8 deletions components/operator/apis/stack/v1beta3/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ import (
// Fields order is important.
// For example, auth must be defined later as other services create static auth clients which must be used by auth.
type ConfigurationServicesSpec struct {
Control ControlSpec `json:"control,omitempty"`
Ledger LedgerSpec `json:"ledger,omitempty"`
Payments PaymentsSpec `json:"payments,omitempty"`
Webhooks WebhooksSpec `json:"webhooks,omitempty"`
Wallets WalletsSpec `json:"wallets,omitempty"`
Orchestration OrchestrationSpec `json:"orchestration,omitempty"`
Search SearchSpec `json:"search,omitempty"`
Auth AuthSpec `json:"auth,omitempty"`
Control ControlSpec `json:"control,omitempty"`
Ledger LedgerSpec `json:"ledger,omitempty"`
Payments PaymentsSpec `json:"payments,omitempty"`
Reconciliation ReconciliationSpec `json:"reconciliation,omitempty"`
Webhooks WebhooksSpec `json:"webhooks,omitempty"`
Wallets WalletsSpec `json:"wallets,omitempty"`
Orchestration OrchestrationSpec `json:"orchestration,omitempty"`
Search SearchSpec `json:"search,omitempty"`
Auth AuthSpec `json:"auth,omitempty"`

// +optional
Gateway GatewaySpec `json:"gateway,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1beta3

type ReconciliationSpec struct {
CommonServiceProperties `json:",inline"`

// +optional
ResourceProperties *ResourceProperties `json:"resourceProperties,omitempty"`
Annotations AnnotationsServicesSpec `json:"annotations,omitempty"`
}
13 changes: 7 additions & 6 deletions components/operator/apis/stack/v1beta3/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ type StackStargateConfig struct {

type StackServicesSpec struct {
// +optional
Ledger StackServicePropertiesSpec `json:"ledger,omitempty"`
Orchestration StackServicePropertiesSpec `json:"orchestration,omitempty"`
Payments StackServicePropertiesSpec `json:"payments,omitempty"`
Wallets StackServicePropertiesSpec `json:"wallets,omitempty"`
Webhooks StackServicePropertiesSpec `json:"webhooks,omitempty"`
Control StackServicePropertiesSpec `json:"control,omitempty"`
Ledger StackServicePropertiesSpec `json:"ledger,omitempty"`
Orchestration StackServicePropertiesSpec `json:"orchestration,omitempty"`
Reconciliation StackServicePropertiesSpec `json:"reconciliation,omitempty"`
Payments StackServicePropertiesSpec `json:"payments,omitempty"`
Wallets StackServicePropertiesSpec `json:"wallets,omitempty"`
Webhooks StackServicePropertiesSpec `json:"webhooks,omitempty"`
Control StackServicePropertiesSpec `json:"control,omitempty"`
}

type StackServicePropertiesSpec struct {
Expand Down
2 changes: 2 additions & 0 deletions components/operator/apis/stack/v1beta3/versions_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type VersionsSpec struct {
Gateway string `json:"gateway"`
// +optional
Stargate string `json:"stargate"`
// +optional
Reconciliation string `json:"reconciliation"`
}

// VersionsStatus defines the observed state of Versions
Expand Down
24 changes: 24 additions & 0 deletions components/operator/apis/stack/v1beta3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4573,6 +4573,39 @@ spec:
- encryptionKey
- postgres
type: object
reconciliation:
properties:
annotations:
properties:
service:
additionalProperties:
type: string
type: object
type: object
debug:
type: boolean
dev:
type: boolean
disabled:
type: boolean
resourceProperties:
properties:
limits:
properties:
cpu:
type: string
memory:
type: string
type: object
request:
properties:
cpu:
type: string
memory:
type: string
type: object
type: object
type: object
search:
properties:
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,11 @@ spec:
disabled:
type: boolean
type: object
reconciliation:
properties:
disabled:
type: boolean
type: object
wallets:
properties:
disabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ spec:
type: string
payments:
type: string
reconciliation:
type: string
search:
type: string
stargate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,39 @@ spec:
- encryptionKey
- postgres
type: object
reconciliation:
properties:
annotations:
properties:
service:
additionalProperties:
type: string
type: object
type: object
debug:
type: boolean
dev:
type: boolean
disabled:
type: boolean
resourceProperties:
properties:
limits:
properties:
cpu:
type: string
memory:
type: string
type: object
request:
properties:
cpu:
type: string
memory:
type: string
type: object
type: object
type: object
search:
properties:
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,11 @@ spec:
disabled:
type: boolean
type: object
reconciliation:
properties:
disabled:
type: boolean
type: object
wallets:
properties:
disabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ spec:
type: string
payments:
type: string
reconciliation:
type: string
search:
type: string
stargate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "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/reconciliation"
_ "github.com/formancehq/operator/internal/modules/search"
_ "github.com/formancehq/operator/internal/modules/stargate"
_ "github.com/formancehq/operator/internal/modules/wallets"
Expand Down
1 change: 1 addition & 0 deletions components/operator/internal/modules/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "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/reconciliation"
_ "github.com/formancehq/operator/internal/modules/search"
_ "github.com/formancehq/operator/internal/modules/stargate"
_ "github.com/formancehq/operator/internal/modules/wallets"
Expand Down
2 changes: 2 additions & 0 deletions components/operator/internal/modules/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/formancehq/operator/internal/modules/control"
"github.com/formancehq/operator/internal/modules/orchestration"
"github.com/formancehq/operator/internal/modules/reconciliation"
"github.com/formancehq/operator/internal/modules/wallets"

stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3"
Expand All @@ -25,6 +26,7 @@ func (a module) DependsOn() []modules.Module {
control.Module,
orchestration.Module,
wallets.Module,
reconciliation.Module,
}
}

Expand Down
2 changes: 2 additions & 0 deletions components/operator/internal/modules/gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"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/reconciliation"
"github.com/formancehq/operator/internal/modules/search"
"github.com/formancehq/operator/internal/modules/wallets"
"github.com/formancehq/operator/internal/modules/webhooks"
Expand All @@ -36,6 +37,7 @@ func (g module) DependsOn() []modules.Module {
control.Module,
ledger.Module,
orchestration.Module,
reconciliation.Module,
payments.Module,
search.Module,
wallets.Module,
Expand Down
64 changes: 64 additions & 0 deletions components/operator/internal/modules/reconciliation/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package reconciliation

import (
stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3"
"github.com/formancehq/operator/internal/modules"
)

type module struct{}

func (o module) Name() string {
return "reconciliation"
}

func (o module) IsEE() bool {
return true
}

func (o module) Versions() map[string]modules.Version {
return map[string]modules.Version{
"v0.0.0": {
Services: func(ctx modules.ReconciliationConfig) modules.Services {
return modules.Services{
{
InjectPostgresVariables: false,
AuthConfiguration: func(config modules.ReconciliationConfig) stackv1beta3.ClientConfiguration {
return stackv1beta3.NewClientConfiguration()
},
HasVersionEndpoint: true,
ListenEnvVar: "LISTEN",
ExposeHTTP: modules.DefaultExposeHTTP,
Annotations: ctx.Configuration.Spec.Services.Reconciliation.Annotations.Service,
Container: func(resolveContext modules.ContainerResolutionConfiguration) modules.Container {
return modules.Container{
Env: reconciliationEnvVars(resolveContext),
Image: modules.GetImage("reconciliation", resolveContext.Versions.Spec.Reconciliation),
Resources: modules.GetResourcesWithDefault(
resolveContext.Configuration.Spec.Services.Reconciliation.ResourceProperties,
modules.ResourceSizeSmall(),
),
}
},
},
}
},
},
}
}

func reconciliationEnvVars(resolveContext modules.ContainerResolutionConfiguration) modules.ContainerEnv {
env := modules.NewEnv().Append(
modules.Env("STACK_CLIENT_ID", resolveContext.Stack.Status.StaticAuthClients["reconciliation"].ID),
modules.Env("STACK_CLIENT_SECRET", resolveContext.Stack.Status.StaticAuthClients["reconciliation"].Secrets[0]),
)

return env
}

var Module = &module{}

var _ modules.Module = Module

func init() {
modules.Register(Module)
}
2 changes: 1 addition & 1 deletion components/payments/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ components:
content:
application/json:
schema:
$ref: '#/components/schemas/PoolBalance'
$ref: '#/components/schemas/PoolBalancesResponse'
TransferInitiations:
description: OK
content:
Expand Down
10 changes: 10 additions & 0 deletions components/reconciliation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
.idea
vendor
.cloud/ressources/.terraform
.cloud/ressources/.terraform.lock.hcl
/.cloud/helm/charts/
coverage.out
dist/
.env
payments
Loading

1 comment on commit c57bfb1

@vercel
Copy link

@vercel vercel bot commented on c57bfb1 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.