@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"math"
12
12
"math/big"
13
+ "sort"
13
14
"strings"
14
15
"testing"
15
16
"time"
@@ -422,6 +423,15 @@ func withAnnotations(obj runtime.Object, annotations map[string]string) runtime.
422
423
return meta .(runtime.Object )
423
424
}
424
425
426
+ func withLabels (obj runtime.Object , labels map [string ]string ) runtime.Object {
427
+ meta , ok := obj .(metav1.Object )
428
+ if ! ok {
429
+ panic ("could not find metadata on object" )
430
+ }
431
+ meta .SetLabels (labels )
432
+ return meta .(runtime.Object )
433
+ }
434
+
425
435
func csvWithAnnotations (csv * v1alpha1.ClusterServiceVersion , annotations map [string ]string ) * v1alpha1.ClusterServiceVersion {
426
436
return withAnnotations (csv , annotations ).(* v1alpha1.ClusterServiceVersion )
427
437
}
@@ -3089,7 +3099,10 @@ func TestSyncOperatorGroups(t *testing.T) {
3089
3099
annotatedDeployment ,
3090
3100
},
3091
3101
targetNamespace : {
3092
- withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3102
+ withLabels (
3103
+ withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3104
+ map [string ]string {v1alpha1 .CopiedLabelKey : operatorNamespace },
3105
+ ),
3093
3106
& rbacv1.Role {
3094
3107
TypeMeta : metav1.TypeMeta {
3095
3108
Kind : "Role" ,
@@ -3099,8 +3112,9 @@ func TestSyncOperatorGroups(t *testing.T) {
3099
3112
Name : "csv-role" ,
3100
3113
Namespace : targetNamespace ,
3101
3114
Labels : map [string ]string {
3115
+ "olm.copiedFrom" : "operator-ns" ,
3102
3116
"olm.owner" : "csv1" ,
3103
- "olm.owner.namespace" : "operator -ns" ,
3117
+ "olm.owner.namespace" : "target -ns" ,
3104
3118
"olm.owner.kind" : "ClusterServiceVersion" ,
3105
3119
},
3106
3120
OwnerReferences : []metav1.OwnerReference {
@@ -3118,8 +3132,9 @@ func TestSyncOperatorGroups(t *testing.T) {
3118
3132
Name : "csv-rolebinding" ,
3119
3133
Namespace : targetNamespace ,
3120
3134
Labels : map [string ]string {
3135
+ "olm.copiedFrom" : "operator-ns" ,
3121
3136
"olm.owner" : "csv1" ,
3122
- "olm.owner.namespace" : "operator -ns" ,
3137
+ "olm.owner.namespace" : "target -ns" ,
3123
3138
"olm.owner.kind" : "ClusterServiceVersion" ,
3124
3139
},
3125
3140
OwnerReferences : []metav1.OwnerReference {
@@ -3184,7 +3199,10 @@ func TestSyncOperatorGroups(t *testing.T) {
3184
3199
annotatedDeployment ,
3185
3200
},
3186
3201
targetNamespace : {
3187
- withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3202
+ withLabels (
3203
+ withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3204
+ map [string ]string {v1alpha1 .CopiedLabelKey : operatorNamespace },
3205
+ ),
3188
3206
& rbacv1.Role {
3189
3207
TypeMeta : metav1.TypeMeta {
3190
3208
Kind : "Role" ,
@@ -3194,8 +3212,9 @@ func TestSyncOperatorGroups(t *testing.T) {
3194
3212
Name : "csv-role" ,
3195
3213
Namespace : targetNamespace ,
3196
3214
Labels : map [string ]string {
3215
+ "olm.copiedFrom" : "operator-ns" ,
3197
3216
"olm.owner" : "csv1" ,
3198
- "olm.owner.namespace" : "operator -ns" ,
3217
+ "olm.owner.namespace" : "target -ns" ,
3199
3218
"olm.owner.kind" : "ClusterServiceVersion" ,
3200
3219
},
3201
3220
OwnerReferences : []metav1.OwnerReference {
@@ -3213,8 +3232,9 @@ func TestSyncOperatorGroups(t *testing.T) {
3213
3232
Name : "csv-rolebinding" ,
3214
3233
Namespace : targetNamespace ,
3215
3234
Labels : map [string ]string {
3235
+ "olm.copiedFrom" : "operator-ns" ,
3216
3236
"olm.owner" : "csv1" ,
3217
- "olm.owner.namespace" : "operator -ns" ,
3237
+ "olm.owner.namespace" : "target -ns" ,
3218
3238
"olm.owner.kind" : "ClusterServiceVersion" ,
3219
3239
},
3220
3240
OwnerReferences : []metav1.OwnerReference {
@@ -3325,7 +3345,10 @@ func TestSyncOperatorGroups(t *testing.T) {
3325
3345
},
3326
3346
},
3327
3347
targetNamespace : {
3328
- withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3348
+ withLabels (
3349
+ withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3350
+ map [string ]string {v1alpha1 .CopiedLabelKey : operatorNamespace },
3351
+ ),
3329
3352
},
3330
3353
}},
3331
3354
},
@@ -3435,7 +3458,10 @@ func TestSyncOperatorGroups(t *testing.T) {
3435
3458
},
3436
3459
},
3437
3460
targetNamespace : {
3438
- withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3461
+ withLabels (
3462
+ withAnnotations (targetCSV .DeepCopy (), map [string ]string {v1alpha2 .OperatorGroupAnnotationKey : "operator-group-1" , v1alpha2 .OperatorGroupNamespaceAnnotationKey : operatorNamespace }),
3463
+ map [string ]string {v1alpha1 .CopiedLabelKey : operatorNamespace },
3464
+ ),
3439
3465
},
3440
3466
}},
3441
3467
},
@@ -3604,6 +3630,8 @@ func TestSyncOperatorGroups(t *testing.T) {
3604
3630
3605
3631
operatorGroup , err := op .GetClient ().OperatorsV1alpha2 ().OperatorGroups (tt .initial .operatorGroup .GetNamespace ()).Get (tt .initial .operatorGroup .GetName (), metav1.GetOptions {})
3606
3632
require .NoError (t , err )
3633
+ sort .Strings (tt .expectedStatus .Namespaces )
3634
+ sort .Strings (operatorGroup .Status .Namespaces )
3607
3635
assert .Equal (t , tt .expectedStatus , operatorGroup .Status )
3608
3636
3609
3637
for namespace , objects := range tt .final .objects {
0 commit comments