Skip to content

Commit

Permalink
feat(operator): Add Payments Connector Statefull & Replicas use for l…
Browse files Browse the repository at this point in the history
…edger (#1525)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
flemzord and coderabbitai[bot] committed May 23, 2024
1 parent eb4ceb2 commit e7ae568
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
uses: ./.github/actions/env
- run: >
earthly
--no-output
--no-output --auto-skip
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
Expand All @@ -72,7 +72,7 @@ jobs:
uses: ./.github/actions/env
- run: >
earthly
--no-output
--no-output --auto-skip
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: ./.github/actions/env
- run: >
earthly
--allow-privileged --auto-skip
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+pre-commit
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
- name: Publish Helm
run: >
earthly
--allow-privileged --auto-skip
--allow-privileged
--secret GITHUB_TOKEN=$GITHUB_TOKEN
+helm-publish
env:
Expand Down
4 changes: 3 additions & 1 deletion components/operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ Available settings:
| temporal.tls.key | string | | Temporal certificate key |
| broker.dsn | URI | | Broker URI |
| opentelemetry.traces.dsn | URI | | OpenTelemetry collector URI |
| clear-database | bool | true | Whether or not remove databases on stack deletion |
| clear-database | bool | true | Whether to remove databases on stack deletion |
| ledger.deployment-strategy | string | single | Ledger deployment type |
| payments.encryption-key | string | | Payments data encryption key |
| deployments.`<deployment-name>`.init-containers.`<container-name>`.resource-requirements | Map | cpu=X, mem=X | |
| deployments.`<deployment-name>`.containers.`<container-name>`.resource-requirements | Map | cpu=X, mem=X | |
| deployments.`<deployment-name>`.init-containers.`<container-name>`.run-as | Map | user=X, group=X | |
| deployments.`<deployment-name>`.containers.`<container-name>`.run-as | Map | user=X, group=X | |
| deployments.`<deployment-name>`.replicas | string | 2 | |
| caddy.image | string | | Caddy image |
| registries.`<name>`.endpoint | string | | Specify a custom endpoint for a specific docker repository |
| registries.`<name>`.images.`<path>`.rewrite | string | formancehq/example | Allow to rewrite the image path |
Expand Down
2 changes: 2 additions & 0 deletions components/operator/api/formance.com/v1beta1/ledger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type LedgerSpec struct {
StackDependency `json:",inline"`
// +optional
Auth *AuthConfig `json:"auth,omitempty"`
//+kubebuilder:Enum:={single, single-writer}
//+kubebuilder:default:=single
//+optional
DeploymentStrategy DeploymentStrategy `json:"deploymentStrategy,omitempty"`
// Locking is intended for ledger v1 only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ spec:
debug:
type: boolean
deploymentStrategy:
default: single
type: string
dev:
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion components/operator/docs/crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ _Appears in:_
| `version` _string_ | | | |
| `stack` _string_ | | | |
| `auth` _[AuthConfig](#authconfig)_ | | | |
| `deploymentStrategy` _[DeploymentStrategy](#deploymentstrategy)_ | | | |
| `deploymentStrategy` _[DeploymentStrategy](#deploymentstrategy)_ | | single | |
| `locking` _[LockingStrategy](#lockingstrategy)_ | Locking is intended for ledger v1 only | | |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ spec:
debug:
type: boolean
deploymentStrategy:
default: single
type: string
dev:
type: boolean
Expand Down
26 changes: 19 additions & 7 deletions components/operator/internal/resources/ledgers/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,30 @@ import (
func installLedger(ctx core.Context, stack *v1beta1.Stack,
ledger *v1beta1.Ledger, database *v1beta1.Database, image string, isV2 bool) error {

switch ledger.Spec.DeploymentStrategy {
case v1beta1.DeploymentStrategyMonoWriterMultipleReader:
if err := core.DeleteIfExists[*appsv1.Deployment](ctx, core.GetNamespacedResourceName(stack.Name, "ledger")); err != nil {
return err
}
return installLedgerMonoWriterMultipleReader(ctx, stack, ledger, database, image, isV2)
default:
deploymentStrategySettings, err := settings.GetStringOrDefault(ctx, stack.Name, v1beta1.DeploymentStrategySingle, "ledger", "deployment-strategy")
if err != nil {
return err
}

isSingle := true
if deploymentStrategySettings == v1beta1.DeploymentStrategyMonoWriterMultipleReader {
isSingle = false
}
if ledger.Spec.DeploymentStrategy == v1beta1.DeploymentStrategyMonoWriterMultipleReader {
isSingle = false
}

if isSingle {
if err := uninstallLedgerMonoWriterMultipleReader(ctx, stack); err != nil {
return err
}
return installLedgerSingleInstance(ctx, stack, ledger, database, image, isV2)
}

if err := core.DeleteIfExists[*appsv1.Deployment](ctx, core.GetNamespacedResourceName(stack.Name, "ledger")); err != nil {
return err
}
return installLedgerMonoWriterMultipleReader(ctx, stack, ledger, database, image, isV2)
}

func installLedgerSingleInstance(ctx core.Context, stack *v1beta1.Stack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func createConnectorsDeployment(ctx core.Context, stack *v1beta1.Stack, payments
},
},
}).
WithStateful(true).
Install(ctx)
if err != nil {
return err
Expand Down

0 comments on commit e7ae568

Please sign in to comment.