From 728fc8786cb81fff5c71e029f8f6f32c042a3345 Mon Sep 17 00:00:00 2001 From: Crimson Thompson Date: Fri, 20 Dec 2024 18:33:45 +0100 Subject: [PATCH 1/2] feat: (worker) spawn payments-worker in v3 beta --- internal/resources/payments/deployments.go | 50 ++++++++++++++++++++++ internal/tests/payments_controller_test.go | 9 +++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/internal/resources/payments/deployments.go b/internal/resources/payments/deployments.go index c465e938..331091eb 100644 --- a/internal/resources/payments/deployments.go +++ b/internal/resources/payments/deployments.go @@ -196,6 +196,11 @@ func createFullDeployment(ctx core.Context, stack *v1beta1.Stack, appOpts := applications.WithProbePath("/_health") if v3 { appOpts = applications.WithProbePath("/_healthcheck") + + err := createWorkerDeployment(ctx, stack, payments, database, image, env, appOpts) + if err != nil { + return err + } } err = applications. @@ -229,6 +234,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: "api", + 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) diff --git a/internal/tests/payments_controller_test.go b/internal/tests/payments_controller_test.go index 90d28f9c..4b365fa7 100644 --- a/internal/tests/payments_controller_test.go +++ b/internal/tests/payments_controller_test.go @@ -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) From 3702997504381c8cb7039d26a4a33309e9a496f3 Mon Sep 17 00:00:00 2001 From: Crimson Thompson Date: Mon, 23 Dec 2024 17:35:05 +0100 Subject: [PATCH 2/2] feat: (payments-worker) update payments v3 container names --- internal/resources/payments/deployments.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/resources/payments/deployments.go b/internal/resources/payments/deployments.go index 331091eb..425c9bc6 100644 --- a/internal/resources/payments/deployments.go +++ b/internal/resources/payments/deployments.go @@ -193,8 +193,10 @@ 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) @@ -213,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, @@ -258,7 +260,7 @@ func createWorkerDeployment( Spec: v1.PodSpec{ ServiceAccountName: serviceAccountName, Containers: []v1.Container{{ - Name: "api", + Name: "payments-worker", Args: []string{"worker"}, Env: env, Image: image,