Skip to content

Commit f48982d

Browse files
committed
compare only lastApplied annotation
1 parent bcaeb6c commit f48982d

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

internal/annotations/annotations.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package annotations
22

3-
import "strings"
4-
53
const (
64
PrimaryResourceStorageAnnotation = "ydb.tech/primary-resource-storage"
75
PrimaryResourceDatabaseAnnotation = "ydb.tech/primary-resource-database"
@@ -11,30 +9,17 @@ const (
119
LastAppliedAnnotation = "ydb.tech/last-applied"
1210
)
1311

14-
func GetYdbTechAnnotations(annotations map[string]string) map[string]string {
15-
result := make(map[string]string)
16-
for key, value := range annotations {
17-
if strings.HasPrefix(key, "ydb.tech/") {
18-
result[key] = value
19-
}
20-
}
21-
return result
12+
func CompareLastAppliedAnnotation(map1, map2 map[string]string) bool {
13+
value1 := getLastAppliedAnnotation(map1)
14+
value2 := getLastAppliedAnnotation(map2)
15+
return value1 == value2
2216
}
2317

24-
func CompareMaps(map1, map2 map[string]string) bool {
25-
if len(map1) != len(map2) {
26-
return false
27-
}
28-
for key1, value1 := range map1 {
29-
if value2, ok := map2[key1]; !ok || value2 != value1 {
30-
return false
18+
func getLastAppliedAnnotation(annotations map[string]string) string {
19+
for key, value := range annotations {
20+
if key == LastAppliedAnnotation {
21+
return value
3122
}
3223
}
33-
return true
34-
}
35-
36-
func CompareYdbTechAnnotations(map1, map2 map[string]string) bool {
37-
map1 = GetYdbTechAnnotations(map1)
38-
map2 = GetYdbTechAnnotations(map2)
39-
return CompareMaps(map1, map2)
24+
return ""
4025
}

internal/controllers/database/controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
7171
return ctrl.Result{RequeueAfter: DefaultRequeueDelay}, err
7272
}
7373

74-
return r.Sync(ctx, resource)
74+
result, err := r.Sync(ctx, resource)
75+
if err != nil {
76+
r.Log.Error(err, "unexpected Sync error")
77+
}
78+
79+
return result, err
7580
}
7681

7782
// Create FieldIndexer to usage for List requests in Reconcile

internal/controllers/storage/controller_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,11 @@ var _ = Describe("Storage controller medium tests", func() {
188188
))
189189

190190
By("check that delete StatefulSet event was detected...")
191-
Expect(k8sClient.List(ctx,
192-
&foundStatefulSets,
193-
client.InNamespace(testobjects.YdbNamespace),
194-
)).ShouldNot(HaveOccurred())
191+
Expect(k8sClient.List(ctx, &foundStatefulSets, client.InNamespace(testobjects.YdbNamespace))).ShouldNot(HaveOccurred())
195192
Expect(len(foundStatefulSets.Items)).Should(Equal(1))
196-
Expect(k8sClient.Delete(ctx,
197-
&foundStatefulSets.Items[0],
198-
)).ShouldNot(HaveOccurred())
193+
Expect(k8sClient.Delete(ctx, &foundStatefulSets.Items[0])).ShouldNot(HaveOccurred())
199194
Eventually(func() int {
200-
Expect(k8sClient.List(ctx, &foundStatefulSets,
201-
client.InNamespace(testobjects.YdbNamespace),
202-
))
195+
Expect(k8sClient.List(ctx, &foundStatefulSets, client.InNamespace(testobjects.YdbNamespace))).ShouldNot(HaveOccurred())
203196
return len(foundStatefulSets.Items)
204197
}, test.Timeout, test.Interval).Should(Equal(1))
205198
})

internal/resources/predicate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func LastAppliedAnnotationPredicate() predicate.Predicate {
1414
return predicate.Funcs{
1515
UpdateFunc: func(e event.UpdateEvent) bool {
16-
return !annotations.CompareYdbTechAnnotations(
16+
return !annotations.CompareLastAppliedAnnotation(
1717
e.ObjectOld.GetAnnotations(),
1818
e.ObjectNew.GetAnnotations(),
1919
)

0 commit comments

Comments
 (0)