@@ -76,19 +76,36 @@ func (a *Operator) copyCsvToTargetNamespace(csv *v1alpha1.ClusterServiceVersion,
76
76
if ns .Name == operatorGroup .GetNamespace () {
77
77
continue
78
78
}
79
- // create new CSV instead of DeepCopy as namespace and resource version (and status) will be different
80
- newCSV := v1alpha1.ClusterServiceVersion {
81
- ObjectMeta : metav1.ObjectMeta {
82
- Name : csv .Name ,
83
- Annotations : csv .Annotations ,
84
- },
85
- Spec : * csv .Spec .DeepCopy (),
86
- }
87
- newCSV .SetNamespace (ns .Name )
79
+ fetchedCSV , err := a .csvLister [ns .GetName ()].ClusterServiceVersions (ns .GetName ()).Get (csv .GetName ())
80
+ if k8serrors .IsAlreadyExists (err ) {
81
+ log .Debugf ("Found existing CSV (%v), checking annotations" , fetchedCSV .GetName ())
82
+ if reflect .DeepEqual (fetchedCSV .Annotations , csv .Annotations ) == false {
83
+ fetchedCSV .Annotations = csv .Annotations
84
+ // CRDs don't support strategic merge patching, but in the future if they do this should be updated to patch
85
+ log .Debugf ("Updating CSV %v in namespace %v" , fetchedCSV .GetName (), ns .GetName ())
86
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Update (fetchedCSV ); err != nil {
87
+ log .Errorf ("Update CSV in target namespace failed: %v" , err )
88
+ return err
89
+ }
90
+ }
91
+ continue
92
+ } else if k8serrors .IsNotFound (err ) {
93
+ // create new CSV instead of DeepCopy as namespace and resource version (and status) will be different
94
+ newCSV := v1alpha1.ClusterServiceVersion {
95
+ ObjectMeta : metav1.ObjectMeta {
96
+ Name : csv .Name ,
97
+ Annotations : csv .Annotations ,
98
+ },
99
+ Spec : * csv .Spec .DeepCopy (),
100
+ }
101
+ newCSV .SetNamespace (ns .Name )
88
102
89
- log .Debugf ("Copying/updating CSV %v to/in namespace %v" , csv .GetName (), ns .Name )
90
- createdCSV , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Create (& newCSV )
91
- if err == nil {
103
+ log .Debugf ("Copying CSV %v to namespace %v" , csv .GetName (), ns .GetName ())
104
+ createdCSV , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Create (& newCSV )
105
+ if err != nil {
106
+ log .Errorf ("Create for new CSV failed: %v" , err )
107
+ return err
108
+ }
92
109
createdCSV .Status = v1alpha1.ClusterServiceVersionStatus {
93
110
Message : "CSV copied to target namespace" ,
94
111
Reason : v1alpha1 .CSVReasonCopied ,
@@ -98,21 +115,8 @@ func (a *Operator) copyCsvToTargetNamespace(csv *v1alpha1.ClusterServiceVersion,
98
115
log .Errorf ("Status update for CSV failed: %v" , err )
99
116
return err
100
117
}
101
- }
102
- if k8serrors .IsAlreadyExists (err ) {
103
- fetchedCSV , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Get (csv .GetName (), metav1.GetOptions {})
104
- if err != nil {
105
- log .Errorf ("Create failed, yet get failed: %v" , err )
106
- }
107
- if reflect .DeepEqual (fetchedCSV .Annotations , csv .Annotations ) == false {
108
- // CRDs don't support strategic merge patching, but in the future if they do this should be updated to patch
109
- if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Update (fetchedCSV ); err != nil {
110
- log .Errorf ("Update CSV in target namespace failed: %v" , err )
111
- return err
112
- }
113
- }
114
118
} else if err != nil {
115
- log .Errorf ("Create for new CSV failed: %v" , err )
119
+ log .Errorf ("CSV fetch for %v failed: %v" , csv . GetName () , err )
116
120
return err
117
121
}
118
122
}
0 commit comments