@@ -617,6 +617,170 @@ func TestMatchesSelector(t *testing.T) {
617617 },
618618 match : true ,
619619 },
620+ {
621+ name : "Match all MD BootstrapTemplate" ,
622+ req : & runtimehooksv1.GeneratePatchesRequestItem {
623+ Object : runtime.RawExtension {
624+ Object : & unstructured.Unstructured {
625+ Object : map [string ]interface {}{
626+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1" ,
627+ "kind" : "BootstrapTemplate" ,
628+ },
629+ },
630+ },
631+ HolderReference : runtimehooksv1.HolderReference {
632+ APIVersion : clusterv1 .GroupVersion .String (),
633+ Kind : "MachineDeployment" ,
634+ Name : "my-md-0" ,
635+ Namespace : "default" ,
636+ FieldPath : "spec.template.spec.bootstrap.configRef" ,
637+ },
638+ },
639+ templateVariables : map [string ]apiextensionsv1.JSON {
640+ "builtin" : {Raw : []byte (`{"machineDeployment":{"class":"classA"}}` )},
641+ },
642+ selector : clusterv1.PatchSelector {
643+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
644+ Kind : "BootstrapTemplate" ,
645+ MatchResources : clusterv1.PatchSelectorMatch {
646+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
647+ Names : []string {"*" },
648+ },
649+ },
650+ },
651+ match : true ,
652+ },
653+ {
654+ name : "Glob match MD BootstrapTemplate with <string>-*" ,
655+ req : & runtimehooksv1.GeneratePatchesRequestItem {
656+ Object : runtime.RawExtension {
657+ Object : & unstructured.Unstructured {
658+ Object : map [string ]interface {}{
659+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1" ,
660+ "kind" : "BootstrapTemplate" ,
661+ },
662+ },
663+ },
664+ HolderReference : runtimehooksv1.HolderReference {
665+ APIVersion : clusterv1 .GroupVersion .String (),
666+ Kind : "MachineDeployment" ,
667+ Name : "my-md-0" ,
668+ Namespace : "default" ,
669+ FieldPath : "spec.template.spec.bootstrap.configRef" ,
670+ },
671+ },
672+ templateVariables : map [string ]apiextensionsv1.JSON {
673+ "builtin" : {Raw : []byte (`{"machineDeployment":{"class":"class-A"}}` )},
674+ },
675+ selector : clusterv1.PatchSelector {
676+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
677+ Kind : "BootstrapTemplate" ,
678+ MatchResources : clusterv1.PatchSelectorMatch {
679+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
680+ Names : []string {"class-*" },
681+ },
682+ },
683+ },
684+ match : true ,
685+ },
686+ {
687+ name : "Glob match MD BootstrapTemplate with *-<string>" ,
688+ req : & runtimehooksv1.GeneratePatchesRequestItem {
689+ Object : runtime.RawExtension {
690+ Object : & unstructured.Unstructured {
691+ Object : map [string ]interface {}{
692+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1" ,
693+ "kind" : "BootstrapTemplate" ,
694+ },
695+ },
696+ },
697+ HolderReference : runtimehooksv1.HolderReference {
698+ APIVersion : clusterv1 .GroupVersion .String (),
699+ Kind : "MachineDeployment" ,
700+ Name : "my-md-0" ,
701+ Namespace : "default" ,
702+ FieldPath : "spec.template.spec.bootstrap.configRef" ,
703+ },
704+ },
705+ templateVariables : map [string ]apiextensionsv1.JSON {
706+ "builtin" : {Raw : []byte (`{"machineDeployment":{"class":"class-A"}}` )},
707+ },
708+ selector : clusterv1.PatchSelector {
709+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
710+ Kind : "BootstrapTemplate" ,
711+ MatchResources : clusterv1.PatchSelectorMatch {
712+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
713+ Names : []string {"*-A" },
714+ },
715+ },
716+ },
717+ match : true ,
718+ },
719+
720+ {
721+ name : "Don't match BootstrapTemplate, .matchResources.machineDeploymentClass.names is empty" ,
722+ req : & runtimehooksv1.GeneratePatchesRequestItem {
723+ Object : runtime.RawExtension {
724+ Object : & unstructured.Unstructured {
725+ Object : map [string ]interface {}{
726+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1" ,
727+ "kind" : "BootstrapTemplate" ,
728+ },
729+ },
730+ },
731+ HolderReference : runtimehooksv1.HolderReference {
732+ APIVersion : clusterv1 .GroupVersion .String (),
733+ Kind : "MachineDeployment" ,
734+ Name : "my-md-0" ,
735+ Namespace : "default" ,
736+ FieldPath : "spec.template.spec.bootstrap.configRef" ,
737+ },
738+ },
739+ templateVariables : map [string ]apiextensionsv1.JSON {
740+ "builtin" : {Raw : []byte (`{"machineDeployment":{"class":"classA"}}` )},
741+ },
742+ selector : clusterv1.PatchSelector {
743+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
744+ Kind : "BootstrapTemplate" ,
745+ MatchResources : clusterv1.PatchSelectorMatch {
746+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
747+ Names : []string {},
748+ },
749+ },
750+ },
751+ match : false ,
752+ },
753+ {
754+ name : "Do not match BootstrapTemplate, .matchResources.machineDeploymentClass is set to nil" ,
755+ req : & runtimehooksv1.GeneratePatchesRequestItem {
756+ Object : runtime.RawExtension {
757+ Object : & unstructured.Unstructured {
758+ Object : map [string ]interface {}{
759+ "apiVersion" : "bootstrap.cluster.x-k8s.io/v1beta1" ,
760+ "kind" : "BootstrapTemplate" ,
761+ },
762+ },
763+ },
764+ HolderReference : runtimehooksv1.HolderReference {
765+ APIVersion : clusterv1 .GroupVersion .String (),
766+ Kind : "MachineDeployment" ,
767+ Name : "my-md-0" ,
768+ Namespace : "default" ,
769+ FieldPath : "spec.template.spec.bootstrap.configRef" ,
770+ },
771+ },
772+ templateVariables : map [string ]apiextensionsv1.JSON {
773+ "builtin" : {Raw : []byte (`{"machineDeployment":{"class":"classA"}}` )},
774+ },
775+ selector : clusterv1.PatchSelector {
776+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
777+ Kind : "BootstrapTemplate" ,
778+ MatchResources : clusterv1.PatchSelectorMatch {
779+ MachineDeploymentClass : nil ,
780+ },
781+ },
782+ match : false ,
783+ },
620784 {
621785 name : "Don't match BootstrapTemplate, .matchResources.machineDeploymentClass not set" ,
622786 req : & runtimehooksv1.GeneratePatchesRequestItem {
0 commit comments