-
Notifications
You must be signed in to change notification settings - Fork 4
/
dapr_controlplane_controller_action_apply.go
69 lines (53 loc) · 2.01 KB
/
dapr_controlplane_controller_action_apply.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
package controlplane
import (
"context"
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/controller"
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/resources"
"github.com/dapr-sandbox/dapr-kubernetes-operator/internal/controller/operator/instance"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
daprApi "github.com/dapr-sandbox/dapr-kubernetes-operator/api/operator/v1alpha1"
daprAc "github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/client/operator/applyconfiguration/operator/v1alpha1"
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/controller/client"
"github.com/dapr-sandbox/dapr-kubernetes-operator/pkg/controller/predicates"
"github.com/go-logr/logr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
func NewApplyAction(l logr.Logger) Action {
return &ApplyAction{
l: l.WithName("action").WithName("apply"),
subscriptions: make(map[string]struct{}),
}
}
type ApplyAction struct {
l logr.Logger
subscriptions map[string]struct{}
}
func (a *ApplyAction) Configure(_ context.Context, _ *client.Client, b *builder.Builder) (*builder.Builder, error) {
b = b.Owns(&daprApi.DaprInstance{}, builder.WithPredicates(
predicate.Or(
predicate.GenerationChangedPredicate{},
predicates.StatusChanged{},
)))
return b, nil
}
func (a *ApplyAction) Run(ctx context.Context, rr *ReconciliationRequest) error {
spec := daprAc.DaprInstanceSpec()
if rr.Resource.Spec.Values != nil {
values := daprAc.JSON()
values.RawMessage = rr.Resource.Spec.Values.RawMessage
spec = spec.WithValues(values)
}
_, err := rr.Dapr.OperatorV1alpha1().DaprInstances(rr.Resource.Namespace).Apply(
ctx,
daprAc.DaprInstance(instance.DaprInstanceResourceName, rr.Resource.Namespace).
WithOwnerReferences(resources.WithOwnerReference(rr.Resource)).
WithSpec(spec),
metav1.ApplyOptions{
FieldManager: controller.FieldManager,
})
return err
}
func (a *ApplyAction) Cleanup(_ context.Context, _ *ReconciliationRequest) error {
return nil
}