Skip to content

Commit

Permalink
Merge pull request #211 from formancehq/feat/payments-v3-worker-split
Browse files Browse the repository at this point in the history
feat: (worker) spawn payments-worker in v3 beta
  • Loading branch information
laouji authored Dec 24, 2024
2 parents 5ca2214 + 3702997 commit 6727093
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
54 changes: 53 additions & 1 deletion internal/resources/payments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,16 @@ func createFullDeployment(ctx core.Context, stack *v1beta1.Stack,
return err
}

containerName := "api"
appOpts := applications.WithProbePath("/_health")
if v3 {
containerName = "payments-api"
appOpts = applications.WithProbePath("/_healthcheck")

err := createWorkerDeployment(ctx, stack, payments, database, image, env, appOpts)
if err != nil {
return err
}
}

err = applications.
Expand All @@ -208,7 +215,7 @@ func createFullDeployment(ctx core.Context, stack *v1beta1.Stack,
Spec: v1.PodSpec{
ServiceAccountName: serviceAccountName,
Containers: []v1.Container{{
Name: "api",
Name: containerName,
Args: []string{"serve"},
Env: env,
Image: image,
Expand All @@ -229,6 +236,51 @@ func createFullDeployment(ctx core.Context, stack *v1beta1.Stack,
return nil
}

func createWorkerDeployment(
ctx core.Context,
stack *v1beta1.Stack,
payments *v1beta1.Payments,
database *v1beta1.Database,
image string,
env []v1.EnvVar,
appOpts applications.ProbeOpts,
) error {
serviceAccountName, err := settings.GetAWSServiceAccount(ctx, stack.Name)
if err != nil {
return err
}

err = applications.
New(payments, &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "payments-worker",
},
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
ServiceAccountName: serviceAccountName,
Containers: []v1.Container{{
Name: "payments-worker",
Args: []string{"worker"},
Env: env,
Image: image,
LivenessProbe: applications.DefaultLiveness("http", appOpts),
Ports: []v1.ContainerPort{applications.StandardHTTPPort()},
}},
// Ensure empty
InitContainers: []v1.Container{},
},
},
},
}).
Install(ctx)
if err != nil {
return err
}

return nil
}

func createReadDeployment(ctx core.Context, stack *v1beta1.Stack, payments *v1beta1.Payments, database *v1beta1.Database, image string) error {

env, err := commonEnvVars(ctx, stack, payments, database)
Expand Down
9 changes: 8 additions & 1 deletion internal/tests/payments_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ var _ = Describe("PaymentsController", func() {
return reference
}).Should(BeTrue())
})
By("Should create a deployment", func() {
By("Should create a worker deployment", func() {
deployment := &appsv1.Deployment{}
Eventually(func() error {
return LoadResource(stack.Name, "payments-worker", deployment)
}).Should(Succeed())
Expect(deployment).To(BeControlledBy(payments))
})
By("Should create an api deployment", func() {
deployment := &appsv1.Deployment{}
Eventually(func() error {
return LoadResource(stack.Name, "payments", deployment)
Expand Down

0 comments on commit 6727093

Please sign in to comment.