-
Notifications
You must be signed in to change notification settings - Fork 7
/
hooks.go
86 lines (78 loc) · 2.31 KB
/
hooks.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
77
78
79
80
81
82
83
84
85
86
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package activity
import (
"context"
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
svcapitypes "github.com/aws-controllers-k8s/sfn-controller/apis/v1alpha1"
commonutil "github.com/aws-controllers-k8s/sfn-controller/pkg/util"
)
// setResourceAdditionalFields queries and adds the tags to an Activity resource
func (rm *resourceManager) setResourceAdditionalFields(
ctx context.Context,
ko *svcapitypes.Activity,
) (err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.setResourceAdditionalFields")
defer func() {
exit(err)
}()
// Set activity tags
ko.Spec.Tags, err = commonutil.GetResourceTags(
ctx,
rm.sdkapi,
rm.metrics,
string(*ko.Status.ACKResourceMetadata.ARN),
)
if err != nil {
return err
}
return nil
}
// customUpdateActivity patches each of the resource properties in the backend AWS
// service API and returns a new resource with updated fields.
func (rm *resourceManager) customUpdateActivity(
ctx context.Context,
desired *resource,
latest *resource,
delta *ackcompare.Delta,
) (*resource, error) {
if delta.DifferentAt("Spec.Tags") {
err := commonutil.SyncResourceTags(
ctx,
rm.sdkapi,
rm.metrics,
string(*desired.ko.Status.ACKResourceMetadata.ARN),
latest.ko.Spec.Tags,
desired.ko.Spec.Tags,
)
if err != nil {
return nil, err
}
}
return desired, nil
}
func customPreCompare(
delta *ackcompare.Delta,
a *resource,
b *resource,
) {
if len(a.ko.Spec.Tags) != len(b.ko.Spec.Tags) {
delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
} else if len(a.ko.Spec.Tags) > 0 {
if !commonutil.EqualTags(a.ko.Spec.Tags, b.ko.Spec.Tags) {
delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
}
}
}