| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 1 | package tasks |
| 2 | |
| 3 | import ( |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 4 | "context" |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 5 | "fmt" |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 6 | "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 | |
| 14 | type state struct { |
| Giorgi Lekveishvili | 378ea88 | 2023-12-12 13:59:18 +0400 | [diff] [blame] | 15 | 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 |
| Giorgi Lekveishvili | 08af67a | 2024-01-18 08:53:05 +0400 | [diff] [blame] | 23 | appsRepo installer.AppRepository |
| Giorgi Lekveishvili | 378ea88 | 2023-12-12 13:59:18 +0400 | [diff] [blame] | 24 | nsGen installer.NamespaceGenerator |
| 25 | emptySuffixGen installer.SuffixGenerator |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 26 | } |
| 27 | |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 28 | type Env struct { |
| 29 | PCloudEnvName string |
| 30 | Name string |
| 31 | ContactEmail string |
| 32 | Domain string |
| 33 | AdminPublicKey string |
| 34 | } |
| 35 | |
| Giorgi Lekveishvili | cd9e42c | 2023-12-13 09:49:44 +0400 | [diff] [blame] | 36 | type DNSZoneRef struct { |
| 37 | Name string |
| 38 | Namespace string |
| 39 | } |
| 40 | |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 41 | func NewCreateEnvTask( |
| 42 | env Env, |
| 43 | publicIPs []net.IP, |
| Giorgi Lekveishvili | 9d5e3f5 | 2024-03-13 15:02:50 +0400 | [diff] [blame] | 44 | startIP net.IP, |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 45 | nsCreator installer.NamespaceCreator, |
| 46 | repo installer.RepoIO, |
| Giorgi Lekveishvili | cd9e42c | 2023-12-13 09:49:44 +0400 | [diff] [blame] | 47 | ) (Task, DNSZoneRef) { |
| Giorgi Lekveishvili | 77ee2dc | 2023-12-11 16:51:10 +0400 | [diff] [blame] | 48 | st := state{ |
| 49 | publicIPs: publicIPs, |
| 50 | nsCreator: nsCreator, |
| 51 | repo: repo, |
| Giorgi Lekveishvili | 46743d4 | 2023-12-10 15:47:23 +0400 | [diff] [blame] | 52 | } |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 53 | t := newSequentialParentTask( |
| Giorgi Lekveishvili | 77ee2dc | 2023-12-11 16:51:10 +0400 | [diff] [blame] | 54 | "Create env", |
| Giorgi Lekveishvili | 5c1b06e | 2024-03-28 15:19:44 +0400 | [diff] [blame] | 55 | true, |
| 56 | SetupConfigRepoTask(env, &st), |
| 57 | SetupZoneTask(env, startIP, &st), |
| 58 | SetupInfra(env, startIP, &st), |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 59 | ) |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 60 | rctx, done := context.WithCancel(context.Background()) |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 61 | t.OnDone(func(_ error) { |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 62 | done() |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 63 | }) |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 64 | pr := NewFluxcdReconciler( // TODO(gio): make reconciler address a flag |
| 65 | "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local", |
| 66 | fmt.Sprintf("%s-flux", env.PCloudEnvName), |
| 67 | ) |
| 68 | er := NewFluxcdReconciler( |
| 69 | "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local", |
| 70 | env.Name, |
| 71 | ) |
| 72 | go pr.Reconcile(rctx) |
| 73 | go er.Reconcile(rctx) |
| Giorgi Lekveishvili | 2df23db | 2023-12-14 07:55:22 +0400 | [diff] [blame] | 74 | return t, DNSZoneRef{"dns-zone", env.Name} |
| 75 | } |