Skip to content

chore: remove some infrastructure tests (moved to dedicated repository) #596

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

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
53 changes: 53 additions & 0 deletions .github/workflows/dataset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Generate dataset
on:
workflow_dispatch:
inputs:
ledger-version:
description: 'The version of the ledger to deploy'
required: true
preview:
description: 'Preview the changes'
required: false
type: boolean
rds-db-subnet-group-name:
description: 'The network to deploy the RDS instance to'
required: false
until-log-id:
description: 'The log id to stop at'
required: false
generator-version:
default: 'latest'
description: 'The version of the generator to use'
required: false
namespace:
default: 'default'
description: 'The namespace to deploy the dataset to'
required: false
create-snapshot:
default: 'false'
description: 'Create a snapshot of the dataset'
required: false
script:
required: true
description: 'The script to generate the dataset'

jobs:
GenerateDataset:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pulumi/actions@v6
with:
command: ${{ github.event.inputs.preview == 'true' && 'preview' || 'up' }}
stack-name: formancehq/${{ github.event.inputs.ledger-version }}
work-dir: './tools/dataset'
config-map:
ledger-version: ${{ github.event.inputs.ledger-version }}
rds-db-subnet-group-name: ${{ github.event.inputs.rds-db-subnet-group-name }}
until-log-id: ${{ github.event.inputs.until-log-id }}
generator-version: ${{ github.event.inputs.generator-version }}
namespace: ${{ github.event.inputs.namespace }}
create-snapshot: ${{ github.event.inputs.create-snapshot }}
script: ${{ github.event.inputs.script }}
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
1 change: 1 addition & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pre-commit:

BUILD ./test/*+pre-commit
BUILD ./tools/*+pre-commit
BUILD ./deployments/pulumi/*+pre-commit

openapi:
FROM node:20-alpine
Expand Down
11 changes: 0 additions & 11 deletions deployments/pulumi/Earthfile

This file was deleted.

41 changes: 41 additions & 0 deletions deployments/pulumi/ledger/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
VERSION 0.8
PROJECT FormanceHQ/ledger

IMPORT github.com/formancehq/earthly:tags/v0.19.0 AS core

FROM core+base-image

CACHE --sharing=shared --id go-mod-cache /go/pkg/mod
CACHE --sharing=shared --id go-cache /root/.cache/go-build
CACHE --sharing=shared --id golangci-cache /root/.cache/golangci-lint

sources:
FROM core+builder-image
WORKDIR /src
COPY *.go go.* Pulumi.yaml .
COPY --dir pkg .
SAVE ARTIFACT /src

tidy:
FROM +sources
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
RUN go mod tidy

SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

lint:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
CACHE --id golangci-cache /root/.cache/golangci-lint

RUN golangci-lint run --fix --build-tags it --timeout 5m

SAVE ARTIFACT main.go AS LOCAL main.go
SAVE ARTIFACT pkg AS LOCAL pkg

pre-commit:
BUILD +tidy
BUILD +lint
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider enhancing pre-commit checks

The pre-commit target could benefit from additional validation steps:

  1. Running tests (if applicable)
  2. Validating Pulumi configuration
  3. Security scanning for infrastructure code
 pre-commit:
     BUILD +tidy
     BUILD +lint
+    # Add test target if applicable
+    BUILD +test
+    # Validate Pulumi configuration
+    RUN pulumi preview --stack dev --non-interactive

Committable suggestion skipped: line range outside the PR's diff.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/formancehq/ledger/deployments/pulumi
module github.com/formancehq/ledger/deployments/pulumi/ledger

go 1.22

Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions deployments/pulumi/ledger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"errors"
"fmt"
"github.com/formancehq/ledger/deployments/pulumi/ledger/pkg"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
conf := config.New(ctx, "")
postgresURI := conf.Require("postgres.uri")

namespace, err := conf.Try("namespace")
if err != nil {
namespace = "default"
}

version, err := conf.Try("version")
if err != nil {
version = "latest"
}

timeout, err := conf.TryInt("timeout")
if err != nil {
if errors.Is(err, config.ErrMissingVar) {
timeout = 60
} else {
return fmt.Errorf("error reading timeout: %w", err)
}
}

debug, _ := conf.TryBool("debug")
imagePullPolicy, _ := conf.Try("image.pullPolicy")

replicaCount, _ := conf.TryInt("replicaCount")
experimentalFeatures, _ := conf.TryBool("experimentalFeatures")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling consistency for optional configurations.

The error handling is inconsistent across optional configurations. Some errors are silently ignored which could lead to unexpected behavior.

Consider validating and logging when using default values:

-		debug, _ := conf.TryBool("debug")
-		imagePullPolicy, _ := conf.Try("image.pullPolicy")
-		replicaCount, _ := conf.TryInt("replicaCount")
-		experimentalFeatures, _ := conf.TryBool("experimentalFeatures")
+		debug, err := conf.TryBool("debug")
+		if err != nil && !errors.Is(err, config.ErrMissingVar) {
+			return fmt.Errorf("invalid debug configuration: %w", err)
+		}
+
+		imagePullPolicy, err := conf.Try("image.pullPolicy")
+		if err != nil && !errors.Is(err, config.ErrMissingVar) {
+			return fmt.Errorf("invalid imagePullPolicy configuration: %w", err)
+		}
+
+		replicaCount, err := conf.TryInt("replicaCount")
+		if err != nil && !errors.Is(err, config.ErrMissingVar) {
+			return fmt.Errorf("invalid replicaCount configuration: %w", err)
+		}
+		if replicaCount < 0 {
+			return fmt.Errorf("replicaCount must be non-negative")
+		}
+
+		experimentalFeatures, err := conf.TryBool("experimentalFeatures")
+		if err != nil && !errors.Is(err, config.ErrMissingVar) {
+			return fmt.Errorf("invalid experimentalFeatures configuration: %w", err)
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
debug, _ := conf.TryBool("debug")
imagePullPolicy, _ := conf.Try("image.pullPolicy")
replicaCount, _ := conf.TryInt("replicaCount")
experimentalFeatures, _ := conf.TryBool("experimentalFeatures")
debug, err := conf.TryBool("debug")
if err != nil && !errors.Is(err, config.ErrMissingVar) {
return fmt.Errorf("invalid debug configuration: %w", err)
}
imagePullPolicy, err := conf.Try("image.pullPolicy")
if err != nil && !errors.Is(err, config.ErrMissingVar) {
return fmt.Errorf("invalid imagePullPolicy configuration: %w", err)
}
replicaCount, err := conf.TryInt("replicaCount")
if err != nil && !errors.Is(err, config.ErrMissingVar) {
return fmt.Errorf("invalid replicaCount configuration: %w", err)
}
if replicaCount < 0 {
return fmt.Errorf("replicaCount must be non-negative")
}
experimentalFeatures, err := conf.TryBool("experimentalFeatures")
if err != nil && !errors.Is(err, config.ErrMissingVar) {
return fmt.Errorf("invalid experimentalFeatures configuration: %w", err)
}


_, err = pulumi_ledger.NewLedgerComponent(ctx, "ledger", &pulumi_ledger.LedgerComponentArgs{
Namespace: pulumi.String(namespace),
Timeout: pulumi.Int(timeout),
Tag: pulumi.String(version),
ImagePullPolicy: pulumi.String(imagePullPolicy),
PostgresURI: pulumi.String(postgresURI),
Debug: pulumi.Bool(debug),
ReplicaCount: pulumi.Int(replicaCount),
ExperimentalFeatures: pulumi.Bool(experimentalFeatures),
})

return err
})
}
86 changes: 86 additions & 0 deletions deployments/pulumi/ledger/pkg/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package pulumi_ledger

import (
"fmt"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
)

type LedgerComponent struct {
pulumi.ResourceState

ServiceName pulumix.Output[string]
ServiceNamespace pulumix.Output[string]
ServicePort pulumix.Output[int]
ServiceInternalURL pulumix.Output[string]
}

type LedgerComponentArgs struct {
Namespace pulumix.Input[string]
Timeout pulumix.Input[int]
Tag pulumix.Input[string]
ImagePullPolicy pulumix.Input[string]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Include 'ImagePullPolicy' in Container specification

The ImagePullPolicy parameter is defined in LedgerComponentArgs but is not used in the container configuration. Specifying ImagePullPolicy controls how images are pulled and can be important in different deployment environments.

Apply this diff to include ImagePullPolicy in the container:

v3.ContainerArgs{
     Name:  pulumi.String("ledger"),
     Image: pulumi.Sprintf("ghcr.io/formancehq/ledger:%s", tag),
+    ImagePullPolicy: args.ImagePullPolicy.ToStringPtrOutput(),

Ensure that args.ImagePullPolicy is provided and valid.

Also applies to: 102-102

PostgresURI pulumix.Input[string]
Debug pulumix.Input[bool]
ReplicaCount pulumix.Input[int]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use the 'ReplicaCount' argument in Deployment specification

The ReplicaCount parameter is defined in LedgerComponentArgs but is not used when setting the number of replicas in the deployment. Currently, the replicas are hardcoded to 1.

Apply this diff to utilize ReplicaCount in the deployment:

v1.DeploymentSpecArgs{
-    Replicas: pulumi.Int(1),
+    Replicas: args.ReplicaCount.ToIntPtrOutput(),
     Selector: &v2.LabelSelectorArgs{

Ensure that args.ReplicaCount is properly set and has a default value if necessary.

Also applies to: 86-86

ExperimentalFeatures pulumix.Input[bool]
}

func NewLedgerComponent(ctx *pulumi.Context, name string, args *LedgerComponentArgs, opts ...pulumi.ResourceOption) (*LedgerComponent, error) {
cmp := &LedgerComponent{}
err := ctx.RegisterComponentResource("Formance:Ledger", name, cmp, opts...)
if err != nil {
return nil, err
}

rel, err := helm.NewRelease(ctx, "ledger", &helm.ReleaseArgs{
Chart: pulumi.String("../../../helm"),
Namespace: pulumix.Cast[pulumi.StringOutput](args.Namespace),
CreateNamespace: pulumi.BoolPtr(true),
Timeout: pulumix.Cast[pulumi.IntOutput](args.Timeout),
Values: pulumi.Map(map[string]pulumi.Input{
"image": pulumi.Map{
"repository": pulumi.String("ghcr.io/formancehq/ledger"),
"tag": args.Tag,
"pullPolicy": args.ImagePullPolicy,
},
"postgres": pulumi.Map{
"uri": args.PostgresURI,
},
"debug": args.Debug,
"replicaCount": args.ReplicaCount,
"experimentalFeatures": args.ExperimentalFeatures,
}),
}, pulumi.Parent(cmp))
if err != nil {
return nil, fmt.Errorf("installing release: %w", err)
}

cmp.ServiceName = pulumix.Apply(rel.Status.Name().ToStringPtrOutput(), func(a1 *string) string {
return *a1
})
cmp.ServiceNamespace = pulumix.Apply(rel.Status.Namespace().ToStringPtrOutput(), func(a1 *string) string {
return *a1
})
cmp.ServicePort = pulumix.Val(8080)
cmp.ServiceInternalURL = pulumix.Apply(pulumi.Sprintf(
"http://%s.%s.svc.cluster.local:%d",
cmp.ServiceName,
cmp.ServiceNamespace,
cmp.ServicePort,
), func(a1 string) string {
return a1
})

if err := ctx.RegisterResourceOutputs(cmp, pulumi.Map{
"service-name": cmp.ServiceName,
"service-namespace": cmp.ServiceNamespace,
"service-port": cmp.ServicePort,
"service-internal-url": cmp.ServiceInternalURL,
}); err != nil {
return nil, fmt.Errorf("registering resource outputs: %w", err)
}

return cmp, nil
}
73 changes: 0 additions & 73 deletions deployments/pulumi/main.go

This file was deleted.

41 changes: 41 additions & 0 deletions deployments/pulumi/postgres/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
VERSION 0.8
PROJECT FormanceHQ/ledger

IMPORT github.com/formancehq/earthly:tags/v0.19.0 AS core

FROM core+base-image

CACHE --sharing=shared --id go-mod-cache /go/pkg/mod
CACHE --sharing=shared --id go-cache /root/.cache/go-build
CACHE --sharing=shared --id golangci-cache /root/.cache/golangci-lint

sources:
FROM core+builder-image
WORKDIR /src
COPY *.go go.* Pulumi.yaml .
COPY --dir pkg .
SAVE ARTIFACT /src

tidy:
FROM +sources
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
RUN go mod tidy

SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

lint:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
CACHE --id golangci-cache /root/.cache/golangci-lint

RUN golangci-lint run --fix --build-tags it --timeout 5m

SAVE ARTIFACT main.go AS LOCAL main.go
SAVE ARTIFACT pkg AS LOCAL pkg

pre-commit:
BUILD +tidy
BUILD +lint
7 changes: 7 additions & 0 deletions deployments/pulumi/postgres/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: postgres
description: A minimal Kubernetes Go Pulumi program
runtime: go
config:
pulumi:tags:
value:
pulumi:template: kubernetes-go
Loading
Loading