@@ -792,11 +792,11 @@ func copyableCSVHash(original *v1alpha1.ClusterServiceVersion) (string, string,
792
792
}
793
793
794
794
const (
795
- nonStatusCopyHashAnnotation = "olm.operatorframework.io/nonStatusCopyHash"
796
- statusCopyHashAnnotation = "olm.operatorframework.io/statusCopyHash"
797
- // annotations for metadata drift guard
798
- observedGenerationAnnotation = "olm.operatorframework.io/observedGeneration"
799
- observedResourceVersionAnnotation = "olm.operatorframework.io/observedResourceVersion"
795
+ nonStatusCopyHashAnnotation = "olm.operatorframework.io/nonStatusCopyHash"
796
+ statusCopyHashAnnotation = "olm.operatorframework.io/statusCopyHash"
797
+ // annotations for metadata drift guard
798
+ observedGenerationAnnotation = "olm.operatorframework.io/observedGeneration"
799
+ observedResourceVersionAnnotation = "olm.operatorframework.io/observedResourceVersion"
800
800
)
801
801
802
802
// If returned error is not nil, the returned ClusterServiceVersion
@@ -832,43 +832,43 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
832
832
UID : created .UID ,
833
833
},
834
834
}, nil
835
- } else if err != nil {
836
- return nil , err
837
- }
838
- // metadata drift guard: detect manual modifications to spec or status
839
- if og , orv := existing .Annotations [observedGenerationAnnotation ], existing .Annotations [observedResourceVersionAnnotation ]; (og != "" && og != fmt .Sprint (existing .GetGeneration ())) || (orv != "" && orv != existing .ResourceVersion ) {
840
- // full resync for metadata drift
841
- // prepare prototype for update
842
- prototype .Namespace = existing .Namespace
843
- prototype .ResourceVersion = existing .ResourceVersion
844
- prototype .UID = existing .UID
845
- // sync hash annotations
846
- prototype .Annotations [nonStatusCopyHashAnnotation ] = nonstatus
847
- prototype .Annotations [statusCopyHashAnnotation ] = status
848
- // update spec and annotations
849
- updated , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).Update (context .TODO (), prototype , metav1.UpdateOptions {})
850
- if err != nil {
851
- return nil , fmt .Errorf ("failed to resync spec for metadata drift guard: %w" , err )
852
- }
853
- // update status subresource
854
- updated .Status = prototype .Status
855
- if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).UpdateStatus (context .TODO (), updated , metav1.UpdateOptions {}); err != nil {
856
- return nil , fmt .Errorf ("failed to resync status for metadata drift guard: %w" , err )
857
- }
858
- // record observed generation and resourceVersion
859
- updated .Annotations [observedGenerationAnnotation ] = fmt .Sprint (updated .GetGeneration ())
860
- updated .Annotations [observedResourceVersionAnnotation ] = updated .ResourceVersion
861
- if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).Update (context .TODO (), updated , metav1.UpdateOptions {}); err != nil {
862
- return nil , fmt .Errorf ("failed to update metadata guard annotations: %w" , err )
863
- }
864
- return & v1alpha1.ClusterServiceVersion {
865
- ObjectMeta : metav1.ObjectMeta {
866
- Name : updated .Name ,
867
- Namespace : updated .Namespace ,
868
- UID : updated .UID ,
869
- },
870
- }, nil
871
- }
835
+ } else if err != nil {
836
+ return nil , err
837
+ }
838
+ // metadata drift guard: detect manual modifications to spec or status
839
+ if og , orv := existing .Annotations [observedGenerationAnnotation ], existing .Annotations [observedResourceVersionAnnotation ]; (og != "" && og != fmt .Sprint (existing .GetGeneration ())) || (orv != "" && orv != existing .ResourceVersion ) {
840
+ // full resync for metadata drift
841
+ // prepare prototype for update
842
+ prototype .Namespace = existing .Namespace
843
+ prototype .ResourceVersion = existing .ResourceVersion
844
+ prototype .UID = existing .UID
845
+ // sync hash annotations
846
+ prototype .Annotations [nonStatusCopyHashAnnotation ] = nonstatus
847
+ prototype .Annotations [statusCopyHashAnnotation ] = status
848
+ // update spec and annotations
849
+ updated , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).Update (context .TODO (), prototype , metav1.UpdateOptions {})
850
+ if err != nil {
851
+ return nil , fmt .Errorf ("failed to resync spec for metadata drift guard: %w" , err )
852
+ }
853
+ // update status subresource
854
+ updated .Status = prototype .Status
855
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).UpdateStatus (context .TODO (), updated , metav1.UpdateOptions {}); err != nil {
856
+ return nil , fmt .Errorf ("failed to resync status for metadata drift guard: %w" , err )
857
+ }
858
+ // record observed generation and resourceVersion
859
+ updated .Annotations [observedGenerationAnnotation ] = fmt .Sprint (updated .GetGeneration ())
860
+ updated .Annotations [observedResourceVersionAnnotation ] = updated .ResourceVersion
861
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (nsTo ).Update (context .TODO (), updated , metav1.UpdateOptions {}); err != nil {
862
+ return nil , fmt .Errorf ("failed to update metadata guard annotations: %w" , err )
863
+ }
864
+ return & v1alpha1.ClusterServiceVersion {
865
+ ObjectMeta : metav1.ObjectMeta {
866
+ Name : updated .Name ,
867
+ Namespace : updated .Namespace ,
868
+ UID : updated .UID ,
869
+ },
870
+ }, nil
871
+ }
872
872
873
873
prototype .Namespace = existing .Namespace
874
874
prototype .ResourceVersion = existing .ResourceVersion
0 commit comments