@@ -910,3 +910,206 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
910910 })
911911 }
912912}
913+
914+ func TestBastionDefault (t * testing.T ) {
915+ cases := map [string ]struct {
916+ cluster * AzureCluster
917+ output * AzureCluster
918+ }{
919+ "no bastion set" : {
920+ cluster : & AzureCluster {
921+ ObjectMeta : metav1.ObjectMeta {
922+ Name : "foo" ,
923+ },
924+ Spec : AzureClusterSpec {},
925+ },
926+ output : & AzureCluster {
927+ ObjectMeta : metav1.ObjectMeta {
928+ Name : "foo" ,
929+ },
930+ Spec : AzureClusterSpec {},
931+ },
932+ },
933+ "azure bastion enabled with no settings" : {
934+ cluster : & AzureCluster {
935+ ObjectMeta : metav1.ObjectMeta {
936+ Name : "foo" ,
937+ },
938+ Spec : AzureClusterSpec {
939+ BastionSpec : BastionSpec {
940+ AzureBastion : & AzureBastion {},
941+ },
942+ },
943+ },
944+ output : & AzureCluster {
945+ ObjectMeta : metav1.ObjectMeta {
946+ Name : "foo" ,
947+ },
948+ Spec : AzureClusterSpec {
949+ BastionSpec : BastionSpec {
950+ AzureBastion : & AzureBastion {
951+ Name : "foo-azure-bastion" ,
952+ Subnet : SubnetSpec {
953+ Name : "AzureBastionSubnet" ,
954+ CIDRBlocks : []string {DefaultAzureBastionSubnetCIDR },
955+ },
956+ PublicIP : PublicIPSpec {
957+ Name : "foo-azure-bastion-pip" ,
958+ },
959+ },
960+ },
961+ },
962+ },
963+ },
964+ "azure bastion enabled with name set" : {
965+ cluster : & AzureCluster {
966+ ObjectMeta : metav1.ObjectMeta {
967+ Name : "foo" ,
968+ },
969+ Spec : AzureClusterSpec {
970+ BastionSpec : BastionSpec {
971+ AzureBastion : & AzureBastion {
972+ Name : "my-fancy-name" ,
973+ },
974+ },
975+ },
976+ },
977+ output : & AzureCluster {
978+ ObjectMeta : metav1.ObjectMeta {
979+ Name : "foo" ,
980+ },
981+ Spec : AzureClusterSpec {
982+ BastionSpec : BastionSpec {
983+ AzureBastion : & AzureBastion {
984+ Name : "my-fancy-name" ,
985+ Subnet : SubnetSpec {
986+ Name : "AzureBastionSubnet" ,
987+ CIDRBlocks : []string {DefaultAzureBastionSubnetCIDR },
988+ },
989+ PublicIP : PublicIPSpec {
990+ Name : "foo-azure-bastion-pip" ,
991+ },
992+ },
993+ },
994+ },
995+ },
996+ },
997+ "azure bastion enabled with subnet partially set" : {
998+ cluster : & AzureCluster {
999+ ObjectMeta : metav1.ObjectMeta {
1000+ Name : "foo" ,
1001+ },
1002+ Spec : AzureClusterSpec {
1003+ BastionSpec : BastionSpec {
1004+ AzureBastion : & AzureBastion {
1005+ Subnet : SubnetSpec {},
1006+ },
1007+ },
1008+ },
1009+ },
1010+ output : & AzureCluster {
1011+ ObjectMeta : metav1.ObjectMeta {
1012+ Name : "foo" ,
1013+ },
1014+ Spec : AzureClusterSpec {
1015+ BastionSpec : BastionSpec {
1016+ AzureBastion : & AzureBastion {
1017+ Name : "foo-azure-bastion" ,
1018+ Subnet : SubnetSpec {
1019+ Name : "AzureBastionSubnet" ,
1020+ CIDRBlocks : []string {DefaultAzureBastionSubnetCIDR },
1021+ },
1022+ PublicIP : PublicIPSpec {
1023+ Name : "foo-azure-bastion-pip" ,
1024+ },
1025+ },
1026+ },
1027+ },
1028+ },
1029+ },
1030+ "azure bastion enabled with subnet fully set" : {
1031+ cluster : & AzureCluster {
1032+ ObjectMeta : metav1.ObjectMeta {
1033+ Name : "foo" ,
1034+ },
1035+ Spec : AzureClusterSpec {
1036+ BastionSpec : BastionSpec {
1037+ AzureBastion : & AzureBastion {
1038+ Subnet : SubnetSpec {
1039+ Name : "my-superfancy-name" ,
1040+ CIDRBlocks : []string {"10.10.0.0/16" },
1041+ },
1042+ },
1043+ },
1044+ },
1045+ },
1046+ output : & AzureCluster {
1047+ ObjectMeta : metav1.ObjectMeta {
1048+ Name : "foo" ,
1049+ },
1050+ Spec : AzureClusterSpec {
1051+ BastionSpec : BastionSpec {
1052+ AzureBastion : & AzureBastion {
1053+ Name : "foo-azure-bastion" ,
1054+ Subnet : SubnetSpec {
1055+ Name : "my-superfancy-name" ,
1056+ CIDRBlocks : []string {"10.10.0.0/16" },
1057+ },
1058+ PublicIP : PublicIPSpec {
1059+ Name : "foo-azure-bastion-pip" ,
1060+ },
1061+ },
1062+ },
1063+ },
1064+ },
1065+ },
1066+ "azure bastion enabled with public IP name set" : {
1067+ cluster : & AzureCluster {
1068+ ObjectMeta : metav1.ObjectMeta {
1069+ Name : "foo" ,
1070+ },
1071+ Spec : AzureClusterSpec {
1072+ BastionSpec : BastionSpec {
1073+ AzureBastion : & AzureBastion {
1074+ PublicIP : PublicIPSpec {
1075+ Name : "my-ultrafancy-pip-name" ,
1076+ },
1077+ },
1078+ },
1079+ },
1080+ },
1081+ output : & AzureCluster {
1082+ ObjectMeta : metav1.ObjectMeta {
1083+ Name : "foo" ,
1084+ },
1085+ Spec : AzureClusterSpec {
1086+ BastionSpec : BastionSpec {
1087+ AzureBastion : & AzureBastion {
1088+ Name : "foo-azure-bastion" ,
1089+ Subnet : SubnetSpec {
1090+ Name : "AzureBastionSubnet" ,
1091+ CIDRBlocks : []string {DefaultAzureBastionSubnetCIDR },
1092+ },
1093+ PublicIP : PublicIPSpec {
1094+ Name : "my-ultrafancy-pip-name" ,
1095+ },
1096+ },
1097+ },
1098+ },
1099+ },
1100+ },
1101+ }
1102+
1103+ for name := range cases {
1104+ c := cases [name ]
1105+ t .Run (name , func (t * testing.T ) {
1106+ t .Parallel ()
1107+ c .cluster .setBastionDefaults ()
1108+ if ! reflect .DeepEqual (c .cluster , c .output ) {
1109+ expected , _ := json .MarshalIndent (c .output , "" , "\t " )
1110+ actual , _ := json .MarshalIndent (c .cluster , "" , "\t " )
1111+ t .Errorf ("Expected %s, got %s" , string (expected ), string (actual ))
1112+ }
1113+ })
1114+ }
1115+ }
0 commit comments