-
Notifications
You must be signed in to change notification settings - Fork 100
/
dashboard.go
71 lines (58 loc) · 1.7 KB
/
dashboard.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
package reconcilers
import (
"context"
"errors"
"fmt"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime"
)
func init() {
runtime.RegisterReconcilerInitializer(runtime.ResourceKindDashboard, newDashboardReconciler)
}
type DashboardReconciler struct {
C *runtime.Controller
}
func newDashboardReconciler(c *runtime.Controller) runtime.Reconciler {
return &DashboardReconciler{C: c}
}
func (r *DashboardReconciler) Close(ctx context.Context) error {
return nil
}
func (r *DashboardReconciler) AssignSpec(from, to *runtimev1.Resource) error {
a := from.GetDashboard()
b := to.GetDashboard()
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 *DashboardReconciler) AssignState(from, to *runtimev1.Resource) error {
a := from.GetDashboard()
b := to.GetDashboard()
if a == nil || b == nil {
return fmt.Errorf("cannot assign state from %T to %T", from.Resource, to.Resource)
}
b.State = a.State
return nil
}
func (r *DashboardReconciler) ResetState(res *runtimev1.Resource) error {
res.GetDashboard().State = &runtimev1.DashboardState{}
return nil
}
func (r *DashboardReconciler) 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}
}
t := self.GetDashboard()
if t == nil {
return runtime.ReconcileResult{Err: errors.New("not a dashboard")}
}
// Exit early for deletion
if self.Meta.DeletedOn != nil {
return runtime.ReconcileResult{}
}
err = checkRefs(ctx, r.C, self.Meta.Refs)
return runtime.ReconcileResult{Err: err}
}