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