| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 1 | package tasks |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "net/http" |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 7 | ) |
| 8 | |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 9 | // TODO(gio): make reconciler address a flag |
| 10 | const baseURL = "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local" |
| 11 | |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 12 | type Reconciler interface { |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 13 | Reconcile(ctx context.Context, namespace, name string) |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 14 | } |
| 15 | |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 16 | type SequentialReconciler struct { |
| 17 | Reconcilers []Reconciler |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 18 | } |
| 19 | |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 20 | func (r *SequentialReconciler) Reconcile(ctx context.Context, namespace, name string) { |
| 21 | for _, rec := range r.Reconcilers { |
| 22 | rec.Reconcile(ctx, namespace, name) |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 26 | type SourceGitReconciler struct{} |
| 27 | |
| 28 | func (c SourceGitReconciler) Reconcile(ctx context.Context, namespace, name string) { |
| 29 | addr := fmt.Sprintf("%s/source/git/%s/%s/reconcile", baseURL, namespace, name) |
| 30 | http.Get(addr) |
| 31 | } |
| 32 | |
| 33 | type KustomizationReconciler struct{} |
| 34 | |
| 35 | func (c KustomizationReconciler) Reconcile(ctx context.Context, namespace, name string) { |
| 36 | addr := fmt.Sprintf("%s/kustomization/%s/%s/reconcile", baseURL, namespace, name) |
| 37 | http.Get(addr) |
| 38 | } |
| 39 | |
| 40 | type namespaceNamePair struct { |
| 41 | namespace string |
| 42 | name string |
| 43 | } |
| 44 | |
| 45 | type FixedReconciler struct { |
| 46 | namespace string |
| 47 | name string |
| 48 | reconciler Reconciler |
| 49 | } |
| 50 | |
| 51 | func NewFixedReconciler(namespace, name string) *FixedReconciler { |
| 52 | return &FixedReconciler{ |
| 53 | namespace, |
| 54 | name, |
| 55 | &SequentialReconciler{[]Reconciler{ |
| 56 | SourceGitReconciler{}, |
| 57 | // NOTE(gio): synchronizing git repository auto-syncs root kustomization as well |
| 58 | // KustomizationReconciler{}, |
| 59 | }}, |
| Giorgi Lekveishvili | d2f3dca | 2023-12-20 09:31:30 +0400 | [diff] [blame] | 60 | } |
| 61 | } |
| gio | 43b0f42 | 2024-08-21 10:40:13 +0400 | [diff] [blame] | 62 | |
| 63 | func (r *FixedReconciler) Reconcile(ctx context.Context) { |
| 64 | r.reconciler.Reconcile(ctx, r.namespace, r.name) |
| 65 | } |