@@ -480,6 +480,129 @@ func TestApply(t *testing.T) {
480
480
},
481
481
},
482
482
},
483
+ {
484
+ name : "Should correctly apply patches with builtin variables" ,
485
+ patches : []clusterv1.ClusterClassPatch {
486
+ {
487
+ Name : "fake-patch1" ,
488
+ Definitions : []clusterv1.PatchDefinition {
489
+ {
490
+ Selector : clusterv1.PatchSelector {
491
+ APIVersion : builder .InfrastructureGroupVersion .String (),
492
+ Kind : builder .GenericInfrastructureClusterTemplateKind ,
493
+ MatchResources : clusterv1.PatchSelectorMatch {
494
+ InfrastructureCluster : true ,
495
+ },
496
+ },
497
+ JSONPatches : []clusterv1.JSONPatch {
498
+ {
499
+ Op : "add" ,
500
+ Path : "/spec/template/spec/clusterName" ,
501
+ ValueFrom : & clusterv1.JSONPatchValue {
502
+ Variable : pointer .String ("builtin.cluster.name" ),
503
+ },
504
+ },
505
+ },
506
+ },
507
+ {
508
+ Selector : clusterv1.PatchSelector {
509
+ APIVersion : builder .ControlPlaneGroupVersion .String (),
510
+ Kind : builder .GenericControlPlaneTemplateKind ,
511
+ MatchResources : clusterv1.PatchSelectorMatch {
512
+ ControlPlane : true ,
513
+ },
514
+ },
515
+ JSONPatches : []clusterv1.JSONPatch {
516
+ {
517
+ Op : "add" ,
518
+ Path : "/spec/template/spec/controlPlaneName" ,
519
+ ValueFrom : & clusterv1.JSONPatchValue {
520
+ Variable : pointer .String ("builtin.controlPlane.name" ),
521
+ },
522
+ },
523
+ },
524
+ },
525
+ {
526
+ Selector : clusterv1.PatchSelector {
527
+ APIVersion : builder .InfrastructureGroupVersion .String (),
528
+ Kind : builder .GenericInfrastructureMachineTemplateKind ,
529
+ MatchResources : clusterv1.PatchSelectorMatch {
530
+ ControlPlane : true ,
531
+ },
532
+ },
533
+ JSONPatches : []clusterv1.JSONPatch {
534
+ {
535
+ Op : "add" ,
536
+ Path : "/spec/template/spec/controlPlaneName" ,
537
+ ValueFrom : & clusterv1.JSONPatchValue {
538
+ Variable : pointer .String ("builtin.controlPlane.name" ),
539
+ },
540
+ },
541
+ },
542
+ },
543
+ {
544
+ Selector : clusterv1.PatchSelector {
545
+ APIVersion : builder .BootstrapGroupVersion .String (),
546
+ Kind : builder .GenericBootstrapConfigTemplateKind ,
547
+ MatchResources : clusterv1.PatchSelectorMatch {
548
+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
549
+ Names : []string {"default-worker" },
550
+ },
551
+ },
552
+ },
553
+ JSONPatches : []clusterv1.JSONPatch {
554
+ {
555
+ Op : "add" ,
556
+ Path : "/spec/template/spec/machineDeploymentTopologyName" ,
557
+ ValueFrom : & clusterv1.JSONPatchValue {
558
+ Variable : pointer .String ("builtin.machineDeployment.topologyName" ),
559
+ },
560
+ },
561
+ },
562
+ },
563
+ {
564
+ Selector : clusterv1.PatchSelector {
565
+ APIVersion : builder .InfrastructureGroupVersion .String (),
566
+ Kind : builder .GenericInfrastructureMachineTemplateKind ,
567
+ MatchResources : clusterv1.PatchSelectorMatch {
568
+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
569
+ Names : []string {"default-worker" },
570
+ },
571
+ },
572
+ },
573
+ JSONPatches : []clusterv1.JSONPatch {
574
+ {
575
+ Op : "add" ,
576
+ Path : "/spec/template/spec/machineDeploymentTopologyName" ,
577
+ ValueFrom : & clusterv1.JSONPatchValue {
578
+ Variable : pointer .String ("builtin.machineDeployment.topologyName" ),
579
+ },
580
+ },
581
+ },
582
+ },
583
+ },
584
+ },
585
+ },
586
+ expectedFields : expectedFields {
587
+ infrastructureCluster : map [string ]interface {}{
588
+ "spec.clusterName" : "cluster1" ,
589
+ },
590
+ controlPlane : map [string ]interface {}{
591
+ "spec.controlPlaneName" : "controlPlane1" ,
592
+ },
593
+ controlPlaneInfrastructureMachineTemplate : map [string ]interface {}{
594
+ "spec.template.spec.controlPlaneName" : "controlPlane1" ,
595
+ },
596
+ machineDeploymentInfrastructureMachineTemplate : map [string ]map [string ]interface {}{
597
+ "default-worker-topo1" : {"spec.template.spec.machineDeploymentTopologyName" : "default-worker-topo1" },
598
+ "default-worker-topo2" : {"spec.template.spec.machineDeploymentTopologyName" : "default-worker-topo2" },
599
+ },
600
+ machineDeploymentBootstrapTemplate : map [string ]map [string ]interface {}{
601
+ "default-worker-topo1" : {"spec.template.spec.machineDeploymentTopologyName" : "default-worker-topo1" },
602
+ "default-worker-topo2" : {"spec.template.spec.machineDeploymentTopologyName" : "default-worker-topo2" },
603
+ },
604
+ },
605
+ },
483
606
{
484
607
name : "Should correctly apply variables for a given patch definitionFrom" ,
485
608
varDefinitions : []clusterv1.ClusterClassStatusVariable {
0 commit comments