blob: 9f8a004bdde3b5061a1e50ce0cbf4b34c6e516a0 [file] [log] [blame]
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +04001package tasks
2
3import (
4 "context"
5 "fmt"
6 "net/http"
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +04007)
8
gio43b0f422024-08-21 10:40:13 +04009// TODO(gio): make reconciler address a flag
10const baseURL = "http://fluxcd-reconciler.dodo-fluxcd-reconciler.svc.cluster.local"
11
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040012type Reconciler interface {
gio43b0f422024-08-21 10:40:13 +040013 Reconcile(ctx context.Context, namespace, name string)
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040014}
15
gio43b0f422024-08-21 10:40:13 +040016type SequentialReconciler struct {
17 Reconcilers []Reconciler
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040018}
19
gio43b0f422024-08-21 10:40:13 +040020func (r *SequentialReconciler) Reconcile(ctx context.Context, namespace, name string) {
21 for _, rec := range r.Reconcilers {
22 rec.Reconcile(ctx, namespace, name)
Giorgi Lekveishvilid2f3dca2023-12-20 09:31:30 +040023 }
24}
25
gio43b0f422024-08-21 10:40:13 +040026type SourceGitReconciler struct{}
27
28func (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
33type KustomizationReconciler struct{}
34
35func (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
40type namespaceNamePair struct {
41 namespace string
42 name string
43}
44
45type FixedReconciler struct {
46 namespace string
47 name string
48 reconciler Reconciler
49}
50
51func 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 Lekveishvilid2f3dca2023-12-20 09:31:30 +040060 }
61}
gio43b0f422024-08-21 10:40:13 +040062
63func (r *FixedReconciler) Reconcile(ctx context.Context) {
64 r.reconciler.Reconcile(ctx, r.namespace, r.name)
65}