this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(controller): rendered manifests pattern for apps

Khue Doan dcc6c5c5 735f4a31

+118 -5
+6 -3
Makefile
··· 1 1 .POSIX: 2 - .PHONY: default compose infra apps test update 2 + .PHONY: default compose infra platform apps test update 3 3 4 4 env ?= local 5 5 ··· 23 23 --input '{ "url": "https://github.com/khuedoan/cloudlab", "revision": "master", "registry": "registry.127.0.0.1.sslip.io", "cluster": "local" }' 24 24 25 25 apps: 26 - # TODO auto bootstrap 27 - kubectl apply --server-side=true --namespace argocd --filename apps/${env} 26 + # TODO multiple env 27 + temporal workflow start \ 28 + --task-queue cloudlab \ 29 + --type Apps \ 30 + --input '{ "url": "https://github.com/khuedoan/cloudlab", "revision": "master", "registry": "registry.127.0.0.1.sslip.io", "cluster": "local" }' 28 31 29 32 test: 30 33 cd controller && go test ./...
+48
controller/activities/oci.go
··· 4 4 "bytes" 5 5 "context" 6 6 "encoding/json" 7 + "fmt" 8 + "os" 7 9 "os/exec" 10 + "path" 11 + "path/filepath" 8 12 9 13 "go.temporal.io/sdk/activity" 10 14 ) ··· 41 45 42 46 return &result, nil 43 47 } 48 + 49 + func PushRenderedHelm(ctx context.Context, appsPath, namespace, app, cluster, registry string) (*PushResult, error) { 50 + logger := activity.GetLogger(ctx) 51 + 52 + tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", app, cluster)) 53 + if err != nil { 54 + logger.Error("failed to create temp dir", "error", err) 55 + return nil, err 56 + } 57 + defer os.RemoveAll(tmpDir) 58 + 59 + cmd := exec.CommandContext( 60 + ctx, 61 + "nix", "develop", "--command", 62 + "helm", "template", "--namespace", namespace, app, "oci://ghcr.io/bjw-s-labs/helm/app-template:4.1.1", "--values", path.Join(namespace, app, cluster+".yaml"), "--output-dir", tmpDir, 63 + ) 64 + cmd.Dir = appsPath 65 + 66 + var stdout, stderr bytes.Buffer 67 + cmd.Stdout = &stdout 68 + cmd.Stderr = &stderr 69 + 70 + logger.Info("running helm template", "cmd", cmd.String()) 71 + 72 + if err := cmd.Run(); err != nil { 73 + logger.Error("helm template failed", "error", err, "stderr", stderr.String()) 74 + return nil, err 75 + } 76 + 77 + outputPath, err := filepath.Abs(tmpDir) 78 + if err != nil { 79 + logger.Error("failed to get absolute path to rendered manifests", "error", err) 80 + return nil, err 81 + } 82 + 83 + imageRef := fmt.Sprintf("%s/%s/%s:%s", registry, namespace, app, cluster) 84 + result, err := PushManifests(ctx, outputPath, imageRef) 85 + if err != nil { 86 + logger.Error("failed to push manifests", "error", err) 87 + return nil, err 88 + } 89 + 90 + return result, nil 91 + }
+5 -2
controller/worker/main.go
··· 23 23 24 24 w := worker.New(temporalClient, "cloudlab", worker.Options{}) 25 25 26 - w.RegisterWorkflow(workflows.Infra) 27 - w.RegisterWorkflow(workflows.Platform) 28 26 w.RegisterActivity(activities.Clone) 29 27 w.RegisterActivity(activities.ChangedModules) 30 28 w.RegisterActivity(activities.TerragruntGraph) 31 29 w.RegisterActivity(activities.PruneGraph) 32 30 w.RegisterActivity(activities.TerragruntApply) 33 31 w.RegisterActivity(activities.PushManifests) 32 + w.RegisterActivity(activities.PushRenderedHelm) 33 + 34 + w.RegisterWorkflow(workflows.Infra) 35 + w.RegisterWorkflow(workflows.Platform) 36 + w.RegisterWorkflow(workflows.Apps) 34 37 35 38 err = w.Run(worker.InterruptCh()) 36 39 if err != nil {
+58
controller/workflows/apps.go
··· 1 + package workflows 2 + 3 + import ( 4 + "time" 5 + 6 + "cloudlab/controller/activities" 7 + 8 + "go.temporal.io/sdk/temporal" 9 + "go.temporal.io/sdk/workflow" 10 + ) 11 + 12 + type AppsInput struct { 13 + Url string 14 + Revision string 15 + Registry string 16 + Cluster string 17 + } 18 + 19 + func Apps(ctx workflow.Context, input PlatformInput) error { 20 + logger := workflow.GetLogger(ctx) 21 + logger.Info("Platform workflow started", "platform", input) 22 + 23 + var path string 24 + if err := workflow.ExecuteActivity( 25 + workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ 26 + StartToCloseTimeout: 1 * time.Minute, 27 + RetryPolicy: &temporal.RetryPolicy{ 28 + MaximumAttempts: 3, 29 + }, 30 + }), 31 + activities.Clone, 32 + input.Url, 33 + input.Revision, 34 + ).Get(ctx, &path); err != nil { 35 + return err 36 + } 37 + 38 + var pushResult *activities.PushResult 39 + if err := workflow.ExecuteActivity( 40 + workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ 41 + StartToCloseTimeout: 5 * time.Minute, 42 + RetryPolicy: &temporal.RetryPolicy{ 43 + MaximumAttempts: 2, 44 + }, 45 + }), 46 + activities.PushRenderedHelm, 47 + // TODO loop through this 48 + path+"/apps", 49 + "khuedoan", 50 + "blog", 51 + input.Cluster, 52 + input.Registry, 53 + ).Get(ctx, &pushResult); err != nil { 54 + return err 55 + } 56 + 57 + return nil 58 + }
+1
flake.nix
··· 27 27 go 28 28 k3d 29 29 kubectl 30 + kubernetes-helm 30 31 nixfmt-rfc-style 31 32 openssh 32 33 opentofu