...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package resourceactuation
16
17 import (
18 "fmt"
19
20 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/reconciliationinterval"
21 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
22
23 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24 )
25
26
27
28 func ShouldSkip(u *unstructured.Unstructured) (bool, error) {
29 generation, found, err := unstructured.NestedInt64(u.Object, "metadata", "generation")
30 if err != nil {
31 return false, fmt.Errorf("error getting the value for 'metadata.generation' %v", err)
32 }
33 if !found {
34 return false, nil
35 }
36 observedGeneration, found, err := unstructured.NestedInt64(u.Object, "status", "observedGeneration")
37 if err != nil {
38 return false, fmt.Errorf("error getting the value for 'status.observedGeneration': %v", err)
39 }
40 if !found {
41 return false, nil
42 }
43 if observedGeneration != generation {
44 return false, nil
45 }
46
47 if val, ok := k8s.GetAnnotation(k8s.ReconcileIntervalInSecondsAnnotation, u); ok {
48 reconcileInterval, err := reconciliationinterval.MeanReconcileReenqueuePeriodFromAnnotation(val)
49 if err != nil {
50 return false, err
51 }
52 if reconcileInterval == 0 {
53 conditions, found, err := unstructured.NestedSlice(u.Object, "status", "conditions")
54 if err != nil {
55 return false, fmt.Errorf("error getting object conditions: %v", err)
56 }
57 if !found {
58 return false, nil
59 }
60 for _, condition := range conditions {
61 conditionMap, ok := condition.(map[string]interface{})
62 if !ok {
63 return false, fmt.Errorf("error coverting condition %v to map", condition)
64 }
65 if status, foundStatus := conditionMap["status"].(string); foundStatus && status == "True" {
66 if reason, foundCondition := conditionMap["reason"].(string); foundCondition && reason == k8s.UpToDate {
67 return true, nil
68 }
69 }
70 }
71 }
72 }
73 return false, nil
74 }
75
View as plain text