-
Notifications
You must be signed in to change notification settings - Fork 111
/
pull_trigger.go
76 lines (62 loc) · 1.97 KB
/
pull_trigger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package reconcilers
import (
"context"
"fmt"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime"
)
func init() {
runtime.RegisterReconcilerInitializer(runtime.ResourceKindPullTrigger, newPullTriggerReconciler)
}
// PullTriggerReconciler reconciles a PullTrigger.
// When a PullTrigger is created, the reconciler will retrigger the global project parser resource, causing it to pull and reparse the project.
// It will then delete the PullTrigger resource.
type PullTriggerReconciler struct {
C *runtime.Controller
}
func newPullTriggerReconciler(c *runtime.Controller) runtime.Reconciler {
return &PullTriggerReconciler{C: c}
}
func (r *PullTriggerReconciler) Close(ctx context.Context) error {
return nil
}
func (r *PullTriggerReconciler) AssignSpec(from, to *runtimev1.Resource) error {
a := from.GetPullTrigger()
b := to.GetPullTrigger()
if a == nil || b == nil {
return fmt.Errorf("cannot assign spec from %T to %T", from.Resource, to.Resource)
}
b.Spec = a.Spec
return nil
}
func (r *PullTriggerReconciler) AssignState(from, to *runtimev1.Resource) error {
a := from.GetPullTrigger()
b := to.GetPullTrigger()
if a == nil || b == nil {
return fmt.Errorf("cannot assign state from %T to %T", from.Resource, to.Resource)
}
b.Spec = a.Spec
return nil
}
func (r *PullTriggerReconciler) ResetState(res *runtimev1.Resource) error {
res.GetPullTrigger().State = &runtimev1.PullTriggerState{}
return nil
}
func (r *PullTriggerReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceName) runtime.ReconcileResult {
self, err := r.C.Get(ctx, n, true)
if err != nil {
return runtime.ReconcileResult{Err: err}
}
if self.Meta.DeletedOn != nil {
return runtime.ReconcileResult{}
}
err = r.C.Reconcile(ctx, GlobalProjectParserName)
if err != nil {
return runtime.ReconcileResult{Err: err}
}
err = r.C.Delete(ctx, n)
if err != nil {
return runtime.ReconcileResult{Err: err}
}
return runtime.ReconcileResult{}
}