blob: f5978b3ba4e44f593cee4aa3d7da555ca46e3947 [file] [log] [blame]
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +04001package tasks
2
3import (
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +04004 "context"
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +04005 "fmt"
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +04006 "net"
7
8 "github.com/charmbracelet/keygen"
9
10 "github.com/giolekva/pcloud/core/installer"
11 "github.com/giolekva/pcloud/core/installer/soft"
12)
13
14type state struct {
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +040015 publicIPs []net.IP
16 nsCreator installer.NamespaceCreator
17 repo installer.RepoIO
18 ssAdminKeys *keygen.KeyPair
19 ssClient *soft.Client
20 fluxUserName string
21 keys *keygen.KeyPair
22 appManager *installer.AppManager
23 appsRepo installer.AppRepository[installer.App]
24 nsGen installer.NamespaceGenerator
25 emptySuffixGen installer.SuffixGenerator
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +040026}
27
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +040028type Env struct {
29 PCloudEnvName string
30 Name string
31 ContactEmail string
32 Domain string
33 AdminPublicKey string
34}
35
Giorgi Lekveishvilicd9e42c2023-12-13 09:49:44 +040036type DNSZoneRef struct {
37 Name string
38 Namespace string
39}
40
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +040041func NewCreateEnvTask(
42 env Env,
43 publicIPs []net.IP,
44 nsCreator installer.NamespaceCreator,
45 repo installer.RepoIO,
Giorgi Lekveishvilicd9e42c2023-12-13 09:49:44 +040046) (Task, DNSZoneRef) {
Giorgi Lekveishvili77ee2dc2023-12-11 16:51:10 +040047 st := state{
48 publicIPs: publicIPs,
49 nsCreator: nsCreator,
50 repo: repo,
Giorgi Lekveishvili46743d42023-12-10 15:47:23 +040051 }
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +040052 t := newSequentialParentTask(
Giorgi Lekveishvili77ee2dc2023-12-11 16:51:10 +040053 "Create env",
Giorgi Lekveishvili378ea882023-12-12 13:59:18 +040054 append(
55 []Task{
56 SetupConfigRepoTask(env, &st),
57 NewActivateEnvTask(env, &st),
58 SetupZoneTask(env, &st),
59 },
60 SetupInfra(env, &st)...,
61 )...,
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +040062 )
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040063 rctx, done := context.WithCancel(context.Background())
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +040064 t.OnDone(func(_ error) {
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040065 done()
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +040066 })
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040067 pr := NewFluxcdReconciler( // TODO(gio): make reconciler address a flag
68 "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local",
69 fmt.Sprintf("%s-flux", env.PCloudEnvName),
70 )
71 er := NewFluxcdReconciler(
72 "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local",
73 env.Name,
74 )
75 go pr.Reconcile(rctx)
76 go er.Reconcile(rctx)
Giorgi Lekveishvili2df23db2023-12-14 07:55:22 +040077 return t, DNSZoneRef{"dns-zone", env.Name}
78}