-
Notifications
You must be signed in to change notification settings - Fork 117
/
theme.go
68 lines (56 loc) · 1.53 KB
/
theme.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
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.ResourceKindTheme, newThemeReconciler)
}
type ThemeReconciler struct {
C *runtime.Controller
}
func newThemeReconciler(c *runtime.Controller) runtime.Reconciler {
return &ThemeReconciler{C: c}
}
func (r *ThemeReconciler) Close(ctx context.Context) error {
return nil
}
func (r *ThemeReconciler) AssignSpec(from, to *runtimev1.Resource) error {
a := from.GetTheme()
b := to.GetTheme()
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 *ThemeReconciler) AssignState(from, to *runtimev1.Resource) error {
a := from.GetTheme()
b := to.GetTheme()
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 *ThemeReconciler) ResetState(res *runtimev1.Resource) error {
return nil
}
func (r *ThemeReconciler) 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.GetTheme()
if t == nil {
return runtime.ReconcileResult{Err: errors.New("not a theme")}
}
// Exit early for deletion
if self.Meta.DeletedOn != nil {
return runtime.ReconcileResult{}
}
return runtime.ReconcileResult{}
}