@@ -61,6 +61,20 @@ type ExpirableLock struct {
6161// to prevent races of multiple bindings or CRDs owning the same resource.
6262type ResourceBindingsAnnotation map [string ]ExpirableLock
6363
64+ // UnmarshalResourceBindingsAnnotation unmarshals JSON-formatted string
65+ // into ResourceBindingsAnnotation map.
66+ func UnmarshalResourceBindingsAnnotation (ann string ) (ResourceBindingsAnnotation , error ) {
67+ rbs := make (ResourceBindingsAnnotation )
68+ if err := json .Unmarshal ([]byte (ann ), & rbs ); err != nil {
69+ return nil , fmt .Errorf ("failed to unmarshal ResourceBindings annotation: %w" , err )
70+ }
71+ if rbs == nil {
72+ rbs = make (ResourceBindingsAnnotation )
73+ }
74+
75+ return rbs , nil
76+ }
77+
6478// WithLockedResources tries to lock the resources for the given binding. It
6579// returns those resources that got successfully locked. If a resource is already
6680// locked by another binding, it is skipped and returned in the second return
@@ -73,12 +87,9 @@ func WithLockedResources(crds []*apiextensionsv1.CustomResourceDefinition, now t
7387 return nil , nil , nil , fmt .Errorf ("%s annotation not found, migration has to happen first" , ResourceBindingsAnnotationKey )
7488 }
7589
76- rbs := make (ResourceBindingsAnnotation )
77- if err := json .Unmarshal ([]byte (v ), & rbs ); err != nil {
78- return nil , nil , nil , fmt .Errorf ("failed to unmarshal ResourceBindings annotation: %w" , err )
79- }
80- if rbs == nil {
81- rbs = make (ResourceBindingsAnnotation )
90+ rbs , err := UnmarshalResourceBindingsAnnotation (v )
91+ if err != nil {
92+ return nil , nil , nil , err
8293 }
8394
8495 crdNames := make (map [string ]bool , len (crds ))
0 commit comments