-
Notifications
You must be signed in to change notification settings - Fork 117
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
Changes from 1 commit
f0c054e
165c764
6421ffb
497cb24
e28a9b9
b2b240e
8298be8
bdf9a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 | ||
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") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package pulumi_ledger | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
type LedgerComponent struct { | ||
pulumi.ResourceState | ||
|
||
ServiceName pulumi.StringPtrOutput | ||
ServiceNamespace pulumi.StringPtrOutput | ||
ServicePort pulumi.IntPtrOutput | ||
ServiceInternalURL pulumi.StringOutput | ||
} | ||
|
||
type LedgerComponentArgs struct { | ||
Namespace pulumi.StringInput | ||
Timeout pulumi.IntInput | ||
Tag pulumi.StringInput | ||
ImagePullPolicy pulumi.StringInput | ||
PostgresURI pulumi.StringInput | ||
Debug pulumi.BoolInput | ||
ReplicaCount pulumi.IntInput | ||
ExperimentalFeatures pulumi.BoolInput | ||
} | ||
|
||
func NewLedgerComponent(ctx *pulumi.Context, name string, args *LedgerComponentArgs, opts ...pulumi.ResourceOption) (*LedgerComponent, error) { | ||
cmp := &LedgerComponent{} | ||
err := ctx.RegisterComponentResource("Formance:Ledger:Deployment", name, cmp, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rel, err := helm.NewRelease(ctx, "ledger", &helm.ReleaseArgs{ | ||
Chart: pulumi.String("../../../helm"), | ||
Namespace: args.Namespace, | ||
CreateNamespace: pulumi.BoolPtr(true), | ||
Timeout: 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 = rel.Status.Name() | ||
cmp.ServiceNamespace = rel.Status.Namespace() | ||
cmp.ServicePort = pulumi.IntPtr(8080).ToIntPtrOutput() | ||
cmp.ServiceInternalURL = pulumi.Sprintf( | ||
"http://%s.%s.svc.cluster.local:%d", | ||
cmp.ServiceName.Elem(), | ||
cmp.ServiceNamespace.Elem(), | ||
cmp.ServicePort.Elem(), | ||
) | ||
|
||
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 | ||
} |
This file was deleted.
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 |
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 |
There was a problem hiding this comment.
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: