@@ -404,6 +404,72 @@ func TestSyncRelatedObjects(t *testing.T) {
404
404
405
405
//////////////////////////////////////////////////////////////////////////////////////////////
406
406
407
+ {
408
+ name : "use cluster-related fields in label selector" ,
409
+ workspace : "sync-cluster-fields-selected-secret-up" ,
410
+ mainResource : crds.Crontab {
411
+ ObjectMeta : metav1.ObjectMeta {
412
+ Name : "my-crontab" ,
413
+ Namespace : "default" ,
414
+ },
415
+ Spec : crds.CrontabSpec {
416
+ CronSpec : "* * *" ,
417
+ Image : "ubuntu:latest" ,
418
+ },
419
+ },
420
+ relatedConfig : syncagentv1alpha1.RelatedResourceSpec {
421
+ Identifier : "credentials" ,
422
+ Origin : syncagentv1alpha1 .RelatedResourceOriginService ,
423
+ Kind : "Secret" ,
424
+ Object : syncagentv1alpha1.RelatedResourceObject {
425
+ RelatedResourceObjectSpec : syncagentv1alpha1.RelatedResourceObjectSpec {
426
+ Selector : & syncagentv1alpha1.RelatedResourceObjectSelector {
427
+ LabelSelector : metav1.LabelSelector {
428
+ MatchLabels : map [string ]string {
429
+ "find" : "foo-{{ .ClusterName | len }}" ,
430
+ },
431
+ },
432
+ Rewrite : syncagentv1alpha1.RelatedResourceSelectorRewrite {
433
+ Template : & syncagentv1alpha1.TemplateExpression {
434
+ // same fixed name on both sides
435
+ Template : "my-credentials" ,
436
+ },
437
+ },
438
+ },
439
+ },
440
+ },
441
+ },
442
+ sourceRelatedObject : corev1.Secret {
443
+ ObjectMeta : metav1.ObjectMeta {
444
+ Name : "unknown-name" ,
445
+ Namespace : "synced-default" ,
446
+ Labels : map [string ]string {
447
+ "find" : "foo-16" ,
448
+ },
449
+ },
450
+ Data : map [string ][]byte {
451
+ "password" : []byte ("hunter2" ),
452
+ },
453
+ Type : corev1 .SecretTypeOpaque ,
454
+ },
455
+
456
+ expectedSyncedRelatedObject : corev1.Secret {
457
+ ObjectMeta : metav1.ObjectMeta {
458
+ Name : "my-credentials" ,
459
+ Namespace : "default" ,
460
+ Labels : map [string ]string {
461
+ "find" : "foo-16" ,
462
+ },
463
+ },
464
+ Data : map [string ][]byte {
465
+ "password" : []byte ("hunter2" ),
466
+ },
467
+ Type : corev1 .SecretTypeOpaque ,
468
+ },
469
+ },
470
+
471
+ //////////////////////////////////////////////////////////////////////////////////////////////
472
+
407
473
{
408
474
name : "find Secret based on templated label selector" ,
409
475
workspace : "sync-templated-selected-secret-up" ,
0 commit comments