@@ -1538,7 +1538,7 @@ func Test_validateSelectors(t *testing.T) {
1538
1538
wantErr bool
1539
1539
}{
1540
1540
{
1541
- name : "error if no selectors are all set to false or empty" ,
1541
+ name : "error if selectors are all set to false or empty" ,
1542
1542
selector : clusterv1.PatchSelector {
1543
1543
APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1544
1544
Kind : "InfrastructureClusterTemplate" ,
@@ -1787,6 +1787,65 @@ func Test_validateSelectors(t *testing.T) {
1787
1787
Build (),
1788
1788
wantErr : true ,
1789
1789
},
1790
+ {
1791
+ name : "fail if selector targets ControlPlane Machine Infrastructure but does not have MatchResources.ControlPlane enabled" ,
1792
+ selector : clusterv1.PatchSelector {
1793
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1794
+ Kind : "InfrastructureMachineTemplate" ,
1795
+ MatchResources : clusterv1.PatchSelectorMatch {
1796
+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
1797
+ Names : []string {"bb" },
1798
+ },
1799
+ ControlPlane : false ,
1800
+ },
1801
+ },
1802
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
1803
+ WithControlPlaneInfrastructureMachineTemplate (
1804
+ refToUnstructured (
1805
+ & corev1.ObjectReference {
1806
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1807
+ Kind : "InfrastructureMachineTemplate" ,
1808
+ }),
1809
+ ).
1810
+ Build (),
1811
+ wantErr : true ,
1812
+ },
1813
+ // The following tests have selectors which match multiple resources at the same time.
1814
+ {
1815
+ name : "fail if selector targets a matching infrastructureCluster reference and a not matching control plane" ,
1816
+ selector : clusterv1.PatchSelector {
1817
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1818
+ Kind : "InfrastructureClusterTemplate" ,
1819
+ MatchResources : clusterv1.PatchSelectorMatch {
1820
+ InfrastructureCluster : true ,
1821
+ ControlPlane : true ,
1822
+ },
1823
+ },
1824
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
1825
+ WithInfrastructureClusterTemplate (
1826
+ refToUnstructured (
1827
+ & corev1.ObjectReference {
1828
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1829
+ Kind : "InfrastructureClusterTemplate" ,
1830
+ }),
1831
+ ).
1832
+ WithControlPlaneTemplate (
1833
+ refToUnstructured (
1834
+ & corev1.ObjectReference {
1835
+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta1" ,
1836
+ Kind : "NonMatchingControlPlaneTemplate" ,
1837
+ }),
1838
+ ).
1839
+ WithControlPlaneInfrastructureMachineTemplate (
1840
+ refToUnstructured (
1841
+ & corev1.ObjectReference {
1842
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1843
+ Kind : "NonMatchingInfrastructureMachineTemplate" ,
1844
+ }),
1845
+ ).
1846
+ Build (),
1847
+ wantErr : true ,
1848
+ },
1790
1849
{
1791
1850
name : "pass if selector targets BOTH an existing ControlPlane MachineInfrastructureTemplate and an existing MachineDeploymentClass InfrastructureTemplate" ,
1792
1851
selector : clusterv1.PatchSelector {
@@ -1837,25 +1896,154 @@ func Test_validateSelectors(t *testing.T) {
1837
1896
wantErr : false ,
1838
1897
},
1839
1898
{
1840
- name : "fail if selector targets ControlPlane Machine Infrastructure but does not have MatchResources.ControlPlane enabled" ,
1899
+ name : "fail if selector targets BOTH an existing ControlPlane MachineInfrastructureTemplate and an existing MachineDeploymentClass InfrastructureTemplate but does not match all MachineDeployment classes" ,
1900
+ selector : clusterv1.PatchSelector {
1901
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1902
+ Kind : "InfrastructureMachineTemplate" ,
1903
+ MatchResources : clusterv1.PatchSelectorMatch {
1904
+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
1905
+ Names : []string {"aa" , "bb" },
1906
+ },
1907
+ ControlPlane : true ,
1908
+ },
1909
+ },
1910
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
1911
+ WithControlPlaneTemplate (
1912
+ refToUnstructured (
1913
+ & corev1.ObjectReference {
1914
+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta1" ,
1915
+ Kind : "NonMatchingControlPlaneTemplate" ,
1916
+ }),
1917
+ ).
1918
+ WithControlPlaneInfrastructureMachineTemplate (
1919
+ refToUnstructured (
1920
+ & corev1.ObjectReference {
1921
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1922
+ Kind : "InfrastructureMachineTemplate" ,
1923
+ }),
1924
+ ).
1925
+ WithWorkerMachineDeploymentClasses (
1926
+ * builder .MachineDeploymentClass ("aa" ).
1927
+ WithInfrastructureTemplate (
1928
+ refToUnstructured (& corev1.ObjectReference {
1929
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1930
+ Kind : "NonMatchingInfrastructureMachineTemplate" ,
1931
+ })).
1932
+ WithBootstrapTemplate (
1933
+ refToUnstructured (& corev1.ObjectReference {
1934
+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
1935
+ Kind : "BootstrapTemplate" ,
1936
+ })).
1937
+ Build (),
1938
+ * builder .MachineDeploymentClass ("bb" ).
1939
+ WithInfrastructureTemplate (
1940
+ refToUnstructured (& corev1.ObjectReference {
1941
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1942
+ Kind : "InfrastructureMachineTemplate" ,
1943
+ })).
1944
+ WithBootstrapTemplate (
1945
+ refToUnstructured (& corev1.ObjectReference {
1946
+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
1947
+ Kind : "BootstrapTemplate" ,
1948
+ })).
1949
+ Build (),
1950
+ ).
1951
+ Build (),
1952
+ wantErr : true ,
1953
+ },
1954
+ {
1955
+ name : "fail if selector targets BOTH an existing ControlPlane MachineInfrastructureTemplate and an existing MachineDeploymentClass InfrastructureTemplate but matches only one" ,
1841
1956
selector : clusterv1.PatchSelector {
1842
1957
APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1843
1958
Kind : "InfrastructureMachineTemplate" ,
1844
1959
MatchResources : clusterv1.PatchSelectorMatch {
1845
1960
MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
1846
1961
Names : []string {"bb" },
1847
1962
},
1848
- ControlPlane : false ,
1963
+ ControlPlane : true ,
1964
+ },
1965
+ },
1966
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
1967
+ WithControlPlaneTemplate (
1968
+ refToUnstructured (
1969
+ & corev1.ObjectReference {
1970
+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta1" ,
1971
+ Kind : "NonMatchingControlPlaneTemplate" ,
1972
+ }),
1973
+ ).
1974
+ WithControlPlaneInfrastructureMachineTemplate (
1975
+ refToUnstructured (
1976
+ & corev1.ObjectReference {
1977
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1978
+ Kind : "InfrastructureMachineTemplate" ,
1979
+ }),
1980
+ ).
1981
+ WithWorkerMachineDeploymentClasses (
1982
+ * builder .MachineDeploymentClass ("bb" ).
1983
+ WithInfrastructureTemplate (
1984
+ refToUnstructured (& corev1.ObjectReference {
1985
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1986
+ Kind : "OtherInfrastructureMachineTemplate" ,
1987
+ })).
1988
+ WithBootstrapTemplate (
1989
+ refToUnstructured (& corev1.ObjectReference {
1990
+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
1991
+ Kind : "BootstrapTemplate" ,
1992
+ })).
1993
+ Build (),
1994
+ ).
1995
+ Build (),
1996
+ wantErr : true ,
1997
+ },
1998
+ {
1999
+ name : "fail if selector targets everything but nothing matches" ,
2000
+ selector : clusterv1.PatchSelector {
2001
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
2002
+ Kind : "NotMatchingInfrastructureMachineTemplate" ,
2003
+ MatchResources : clusterv1.PatchSelectorMatch {
2004
+ ControlPlane : true ,
2005
+ InfrastructureCluster : true ,
2006
+ MachineDeploymentClass : & clusterv1.PatchSelectorMatchMachineDeploymentClass {
2007
+ Names : []string {"bb" },
2008
+ },
1849
2009
},
1850
2010
},
1851
2011
clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
2012
+ WithInfrastructureClusterTemplate (
2013
+ refToUnstructured (
2014
+ & corev1.ObjectReference {
2015
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
2016
+ Kind : "InfrastructureClusterTemplate" ,
2017
+ }),
2018
+ ).
2019
+ WithControlPlaneTemplate (
2020
+ refToUnstructured (
2021
+ & corev1.ObjectReference {
2022
+ APIVersion : "controlplane.cluster.x-k8s.io/v1beta1" ,
2023
+ Kind : "NonMatchingControlPlaneTemplate" ,
2024
+ }),
2025
+ ).
1852
2026
WithControlPlaneInfrastructureMachineTemplate (
1853
2027
refToUnstructured (
1854
2028
& corev1.ObjectReference {
1855
2029
APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
1856
2030
Kind : "InfrastructureMachineTemplate" ,
1857
2031
}),
1858
2032
).
2033
+ WithWorkerMachineDeploymentClasses (
2034
+ * builder .MachineDeploymentClass ("bb" ).
2035
+ WithInfrastructureTemplate (
2036
+ refToUnstructured (& corev1.ObjectReference {
2037
+ APIVersion : "infrastructure.cluster.x-k8s.io/v1beta1" ,
2038
+ Kind : "OtherInfrastructureMachineTemplate" ,
2039
+ })).
2040
+ WithBootstrapTemplate (
2041
+ refToUnstructured (& corev1.ObjectReference {
2042
+ APIVersion : "bootstrap.cluster.x-k8s.io/v1beta1" ,
2043
+ Kind : "BootstrapTemplate" ,
2044
+ })).
2045
+ Build (),
2046
+ ).
1859
2047
Build (),
1860
2048
wantErr : true ,
1861
2049
},
0 commit comments