@@ -42,34 +42,44 @@ func ExtractNumOfClustersFromPolicySnapshot(policy fleetv1beta1.PolicySnapshotOb
4242 return numOfClusters , nil
4343}
4444
45- // ExtractObservedCRPGenerationFromPolicySnapshot extracts the observed CRP generation from policySnapshot .
46- func ExtractObservedCRPGenerationFromPolicySnapshot ( policy fleetv1beta1.PolicySnapshotObj ) (int64 , error ) {
47- crpGenerationStr , ok := policy .GetAnnotations ()[ fleetv1beta1 . CRPGenerationAnnotation ]
48- if ! ok {
49- return 0 , fmt . Errorf ( "cannot find annotation %s" , fleetv1beta1 . CRPGenerationAnnotation )
45+ // ExtractSubindexFromResourceSnapshot is a helper function to extract subindex from ResourceSnapshot objects .
46+ func ExtractSubindexFromResourceSnapshot ( snapshot fleetv1beta1.ResourceSnapshotObj ) (doesExist bool , subindex int , err error ) {
47+ annotations := snapshot .GetAnnotations ()
48+ if annotations == nil {
49+ return false , 0 , nil
5050 }
5151
52- // Cast the annotation to an integer; throw an error if the cast cannot be completed or the value is negative.
53- observedCRPGeneration , err := strconv .Atoi (crpGenerationStr )
54- if err != nil || observedCRPGeneration < 0 {
55- return 0 , fmt .Errorf ("invalid annotation %s: %s is not a valid value: %w" , fleetv1beta1 .CRPGenerationAnnotation , crpGenerationStr , err )
52+ subindexStr , exists := annotations [fleetv1beta1 .SubindexOfResourceSnapshotAnnotation ]
53+ if ! exists || subindexStr == "" {
54+ return false , 0 , nil
5655 }
5756
58- return int64 (observedCRPGeneration ), nil
57+ subindex , err = strconv .Atoi (subindexStr )
58+ if err != nil {
59+ return false , 0 , fmt .Errorf ("invalid subindex annotation value %q: %w" , subindexStr , err )
60+ }
61+
62+ if subindex < 0 {
63+ return false , 0 , fmt .Errorf ("subindex cannot be negative: %d" , subindex )
64+ }
65+
66+ return true , subindex , nil
5967}
6068
61- // ExtractSubindexFromClusterResourceSnapshot extracts the subindex value from the annotations of a clusterResourceSnapshot .
62- func ExtractSubindexFromClusterResourceSnapshot ( snapshot fleetv1beta1.ResourceSnapshotObj ) (doesExist bool , subindex int , err error ) {
63- subindexStr , ok := snapshot .GetAnnotations ()[fleetv1beta1 .SubindexOfResourceSnapshotAnnotation ]
69+ // ExtractObservedPlacementGenerationFromPolicySnapshot extracts the observed placement generation from policySnapshot .
70+ func ExtractObservedPlacementGenerationFromPolicySnapshot ( policy fleetv1beta1.PolicySnapshotObj ) (int64 , error ) {
71+ placementGenerationStr , ok := policy .GetAnnotations ()[fleetv1beta1 .CRPGenerationAnnotation ]
6472 if ! ok {
65- return false , - 1 , nil
73+ return 0 , fmt . Errorf ( "cannot find annotation %s" , fleetv1beta1 . CRPGenerationAnnotation )
6674 }
67- subindex , err = strconv .Atoi (subindexStr )
68- if err != nil || subindex < 0 {
69- return true , - 1 , fmt .Errorf ("invalid annotation %s: %s is invalid: %w" , fleetv1beta1 .SubindexOfResourceSnapshotAnnotation , subindexStr , err )
75+
76+ // Cast the annotation to an integer; throw an error if the cast cannot be completed or the value is negative.
77+ observedplacementGeneration , err := strconv .Atoi (placementGenerationStr )
78+ if err != nil || observedplacementGeneration < 0 {
79+ return 0 , fmt .Errorf ("invalid annotation %s: %s is not a valid value: %w" , fleetv1beta1 .CRPGenerationAnnotation , placementGenerationStr , err )
7080 }
7181
72- return true , subindex , nil
82+ return int64 ( observedplacementGeneration ) , nil
7383}
7484
7585// ExtractNumberOfResourceSnapshotsFromResourceSnapshot extracts the number of clusterResourceSnapshots in a group from the master clusterResourceSnapshot.
@@ -125,27 +135,3 @@ func ParseResourceGroupHashFromAnnotation(resourceSnapshot fleetv1beta1.Resource
125135 }
126136 return v , nil
127137}
128-
129- // ExtractSubindexFromResourceSnapshot is a helper function to extract subindex from ResourceSnapshot objects.
130- func ExtractSubindexFromResourceSnapshot (snapshot fleetv1beta1.ResourceSnapshotObj ) (doesExist bool , subindex int , err error ) {
131- annotations := snapshot .GetAnnotations ()
132- if annotations == nil {
133- return false , 0 , nil
134- }
135-
136- subindexStr , exists := annotations [fleetv1beta1 .SubindexOfResourceSnapshotAnnotation ]
137- if ! exists || subindexStr == "" {
138- return false , 0 , nil
139- }
140-
141- subindex , err = strconv .Atoi (subindexStr )
142- if err != nil {
143- return false , 0 , fmt .Errorf ("invalid subindex annotation value %q: %w" , subindexStr , err )
144- }
145-
146- if subindex < 0 {
147- return false , 0 , fmt .Errorf ("subindex cannot be negative: %d" , subindex )
148- }
149-
150- return true , subindex , nil
151- }
0 commit comments