This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
/
handler.go
74 lines (59 loc) · 1.65 KB
/
handler.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
package upgrading
import (
"context"
"github.com/giantswarm/conditions/pkg/conditions"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/giantswarm/conditions-handler/pkg/internal"
"github.com/giantswarm/conditions-handler/pkg/key"
)
type HandlerConfig struct {
CtrlClient ctrl.Client
Logger micrologger.Logger
Name string
UpdateStatus bool
}
type Handler struct {
ctrlClient ctrl.Client
internalHandler *internal.Handler
logger micrologger.Logger
name string
}
func NewHandler(config HandlerConfig) (*Handler, error) {
h := &Handler{
ctrlClient: config.CtrlClient,
logger: config.Logger,
name: config.Name,
}
internalHandlerConfig := internal.HandlerConfig{
CtrlClient: config.CtrlClient,
Logger: config.Logger,
UpdateStatus: config.UpdateStatus,
ConditionType: conditions.Upgrading,
EnsureCreatedFunc: h.ensureCreated,
}
internalHandler, err := internal.NewHandler(internalHandlerConfig)
if err != nil {
return nil, microerror.Mask(err)
}
h.internalHandler = internalHandler
return h, nil
}
func (h *Handler) EnsureCreated(ctx context.Context, object interface{}) error {
obj, err := key.ToObjectWithConditions(object)
if err != nil {
return microerror.Mask(err)
}
return h.internalHandler.EnsureCreated(ctx, obj)
}
func (h *Handler) EnsureDeleted(_ context.Context, _ interface{}) error {
return nil
}
func (h *Handler) Name() string {
return h.name
}
func (h *Handler) ensureCreated(_ context.Context, object conditions.Object) error {
update(object)
return nil
}