@@ -57,7 +57,7 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {
57
57
return err
58
58
}
59
59
60
- if err := a .copyCsvToTargetNamespace (csv , op , targetedNamespaces ); err != nil {
60
+ if err := a .copyCsvToTargetNamespace (csv , op , targetedNamespaces ); err != nil {
61
61
return err
62
62
}
63
63
}
@@ -109,35 +109,41 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {
109
109
}
110
110
111
111
func (a * Operator ) copyCsvToTargetNamespace (csv * v1alpha1.ClusterServiceVersion , operatorGroup * v1alpha2.OperatorGroup , targetNamespaces []* corev1.Namespace ) error {
112
- var nsList []string
113
- for _ , ns := range targetNamespaces {
114
- nsList = append (nsList , ns .Name )
115
- }
116
- nsListJoined := strings .Join (nsList , "," )
117
-
118
-
119
112
for _ , ns := range targetNamespaces {
120
113
if ns .Name == operatorGroup .GetNamespace () {
121
114
continue
122
115
}
116
+ // create new CSV instead of DeepCopy as namespace and resource version (and status) will be different
123
117
newCSV := v1alpha1.ClusterServiceVersion {
124
118
ObjectMeta : metav1.ObjectMeta {
125
- Name : csv .Name ,
119
+ Name : csv .Name ,
120
+ Annotations : csv .Annotations ,
126
121
},
127
122
Spec : * csv .Spec .DeepCopy (),
128
- Status : v1alpha1.ClusterServiceVersionStatus {
123
+ }
124
+ newCSV .SetNamespace (ns .Name )
125
+
126
+ log .Debugf ("Copying/updating CSV %v to/in namespace %v" , csv .GetName (), ns .Name )
127
+ createdCSV , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Create (& newCSV )
128
+ if err == nil {
129
+ createdCSV .Status = v1alpha1.ClusterServiceVersionStatus {
129
130
Message : "CSV copied to target namespace" ,
130
131
Reason : v1alpha1 .CSVReasonCopied ,
131
132
LastUpdateTime : timeNow (),
132
- },
133
+ }
134
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).UpdateStatus (createdCSV ); err != nil {
135
+ log .Errorf ("Status update for CSV failed: %v" , err )
136
+ return err
137
+ }
133
138
}
134
- a .addAnnotationsToCSV (& newCSV , operatorGroup , nsListJoined )
135
- newCSV .SetNamespace (ns .Name )
136
-
137
- log .Debugf ("Copying CSV %v to namespace %v" , csv .GetName (), ns .Name )
138
- _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Create (& newCSV )
139
139
if k8serrors .IsAlreadyExists (err ) {
140
- if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Update (& newCSV ); err != nil {
140
+ fetchedCSV , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Get (csv .GetName (), metav1.GetOptions {})
141
+ if err != nil {
142
+ log .Errorf ("Create failed, yet get failed: %v" , err )
143
+ }
144
+ // update the potentially different annotations
145
+ fetchedCSV .Annotations = csv .Annotations
146
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns .Name ).Update (fetchedCSV ); err != nil {
141
147
log .Errorf ("Update CSV in target namespace failed: %v" , err )
142
148
return err
143
149
}
0 commit comments