github.com/openshift/installer@v1.4.17/pkg/types/defaults/installconfig_test.go (about) 1 package defaults 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/openshift/installer/pkg/ipnet" 9 "github.com/openshift/installer/pkg/types" 10 "github.com/openshift/installer/pkg/types/aws" 11 awsdefaults "github.com/openshift/installer/pkg/types/aws/defaults" 12 "github.com/openshift/installer/pkg/types/azure" 13 azuredefaults "github.com/openshift/installer/pkg/types/azure/defaults" 14 "github.com/openshift/installer/pkg/types/none" 15 nonedefaults "github.com/openshift/installer/pkg/types/none/defaults" 16 "github.com/openshift/installer/pkg/types/openstack" 17 openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults" 18 "github.com/openshift/installer/pkg/types/ovirt" 19 ovirtdefaults "github.com/openshift/installer/pkg/types/ovirt/defaults" 20 ) 21 22 func defaultInstallConfig() *types.InstallConfig { 23 return &types.InstallConfig{ 24 AdditionalTrustBundlePolicy: defaultAdditionalTrustBundlePolicy(), 25 Networking: &types.Networking{ 26 MachineNetwork: []types.MachineNetworkEntry{ 27 {CIDR: *DefaultMachineCIDR}, 28 }, 29 NetworkType: defaultNetworkType, 30 ServiceNetwork: []ipnet.IPNet{*defaultServiceNetwork}, 31 ClusterNetwork: []types.ClusterNetworkEntry{ 32 { 33 CIDR: *defaultClusterNetwork, 34 HostPrefix: int32(defaultHostPrefix), 35 }, 36 }, 37 }, 38 ControlPlane: defaultMachinePool("master"), 39 Compute: []types.MachinePool{*defaultMachinePool("worker")}, 40 Publish: types.ExternalPublishingStrategy, 41 } 42 } 43 44 func defaultInstallConfigWithEdge() *types.InstallConfig { 45 c := defaultInstallConfig() 46 c.Compute = append(c.Compute, *defaultMachinePool("edge")) 47 return c 48 } 49 50 func defaultAWSInstallConfig() *types.InstallConfig { 51 c := defaultInstallConfig() 52 c.Platform.AWS = &aws.Platform{} 53 awsdefaults.SetPlatformDefaults(c.Platform.AWS) 54 return c 55 } 56 57 func defaultAzureInstallConfig() *types.InstallConfig { 58 c := defaultInstallConfig() 59 c.Platform.Azure = &azure.Platform{} 60 azuredefaults.SetPlatformDefaults(c.Platform.Azure) 61 return c 62 } 63 64 func defaultOpenStackInstallConfig() *types.InstallConfig { 65 c := defaultInstallConfig() 66 c.Platform.OpenStack = &openstack.Platform{} 67 openstackdefaults.SetPlatformDefaults(c.Platform.OpenStack, c.Networking) 68 return c 69 } 70 71 func defaultOvirtInstallConfig() *types.InstallConfig { 72 c := defaultInstallConfig() 73 c.Platform.Ovirt = &ovirt.Platform{} 74 ovirtdefaults.SetPlatformDefaults(c.Platform.Ovirt) 75 ovirtdefaults.SetControlPlaneDefaults(c.Platform.Ovirt, c.ControlPlane) 76 for i := range c.Compute { 77 ovirtdefaults.SetComputeDefaults(c.Platform.Ovirt, &c.Compute[i]) 78 } 79 return c 80 } 81 82 func defaultAdditionalTrustBundlePolicy() types.PolicyType { 83 return types.PolicyProxyOnly 84 } 85 86 func defaultNoneInstallConfig() *types.InstallConfig { 87 c := defaultInstallConfig() 88 c.Platform.None = &none.Platform{} 89 nonedefaults.SetPlatformDefaults(c.Platform.None) 90 return c 91 } 92 93 func TestSetInstallConfigDefaults(t *testing.T) { 94 cases := []struct { 95 name string 96 config *types.InstallConfig 97 expected *types.InstallConfig 98 }{ 99 { 100 name: "empty", 101 config: &types.InstallConfig{}, 102 expected: defaultInstallConfig(), 103 }, 104 { 105 name: "empty AWS", 106 config: &types.InstallConfig{ 107 Platform: types.Platform{ 108 AWS: &aws.Platform{}, 109 }, 110 }, 111 expected: defaultAWSInstallConfig(), 112 }, 113 { 114 name: "empty Azure", 115 config: &types.InstallConfig{ 116 Platform: types.Platform{ 117 Azure: &azure.Platform{}, 118 }, 119 }, 120 expected: defaultAzureInstallConfig(), 121 }, 122 { 123 name: "empty OpenStack", 124 config: &types.InstallConfig{ 125 Platform: types.Platform{ 126 OpenStack: &openstack.Platform{}, 127 }, 128 }, 129 expected: defaultOpenStackInstallConfig(), 130 }, 131 { 132 name: "empty oVirt", 133 config: &types.InstallConfig{ 134 Platform: types.Platform{ 135 Ovirt: &ovirt.Platform{}, 136 }, 137 }, 138 expected: defaultOvirtInstallConfig(), 139 }, 140 { 141 name: "Networking present", 142 config: &types.InstallConfig{ 143 Networking: &types.Networking{}, 144 }, 145 expected: defaultInstallConfig(), 146 }, 147 { 148 name: "Networking types present", 149 config: &types.InstallConfig{ 150 Networking: &types.Networking{ 151 NetworkType: "test-networking-type", 152 }, 153 }, 154 expected: func() *types.InstallConfig { 155 c := defaultInstallConfig() 156 c.Networking.NetworkType = "test-networking-type" 157 return c 158 }(), 159 }, 160 { 161 name: "Service network present", 162 config: &types.InstallConfig{ 163 Networking: &types.Networking{ 164 ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("1.2.3.4/8")}, 165 }, 166 }, 167 expected: func() *types.InstallConfig { 168 c := defaultInstallConfig() 169 c.Networking.ServiceNetwork[0] = *ipnet.MustParseCIDR("1.2.3.4/8") 170 return c 171 }(), 172 }, 173 { 174 name: "Cluster network present", 175 config: &types.InstallConfig{ 176 Networking: &types.Networking{ 177 ClusterNetwork: []types.ClusterNetworkEntry{ 178 { 179 CIDR: *ipnet.MustParseCIDR("8.8.0.0/18"), 180 HostPrefix: 22, 181 }, 182 }, 183 }, 184 }, 185 expected: func() *types.InstallConfig { 186 c := defaultInstallConfig() 187 c.Networking.ClusterNetwork = []types.ClusterNetworkEntry{ 188 { 189 CIDR: *ipnet.MustParseCIDR("8.8.0.0/18"), 190 HostPrefix: 22, 191 }, 192 } 193 return c 194 }(), 195 }, 196 { 197 name: "control plane present", 198 config: &types.InstallConfig{ 199 ControlPlane: &types.MachinePool{}, 200 }, 201 expected: defaultInstallConfig(), 202 }, 203 { 204 name: "Compute present", 205 config: &types.InstallConfig{ 206 Compute: []types.MachinePool{{Name: "worker"}}, 207 }, 208 expected: func() *types.InstallConfig { 209 c := defaultInstallConfig() 210 c.Compute = []types.MachinePool{*defaultMachinePool("worker")} 211 return c 212 }(), 213 }, 214 { 215 name: "Edge Compute present", 216 config: &types.InstallConfig{ 217 Compute: []types.MachinePool{{Name: "worker"}, {Name: "edge"}}, 218 }, 219 expected: func() *types.InstallConfig { 220 c := defaultInstallConfigWithEdge() 221 c.Compute = []types.MachinePool{ 222 *defaultMachinePool("worker"), 223 *defaultEdgeMachinePool("edge"), 224 } 225 return c 226 }(), 227 }, 228 { 229 name: "AWS platform present", 230 config: &types.InstallConfig{ 231 Platform: types.Platform{ 232 AWS: &aws.Platform{}, 233 }, 234 }, 235 expected: func() *types.InstallConfig { 236 c := defaultAWSInstallConfig() 237 return c 238 }(), 239 }, 240 { 241 name: "Azure platform present", 242 config: &types.InstallConfig{ 243 Platform: types.Platform{ 244 Azure: &azure.Platform{}, 245 }, 246 }, 247 expected: func() *types.InstallConfig { 248 c := defaultAzureInstallConfig() 249 return c 250 }(), 251 }, 252 { 253 name: "OpenStack platform present", 254 config: &types.InstallConfig{ 255 Platform: types.Platform{ 256 OpenStack: &openstack.Platform{}, 257 }, 258 }, 259 expected: func() *types.InstallConfig { 260 c := defaultOpenStackInstallConfig() 261 return c 262 }(), 263 }, 264 { 265 name: "None platform present", 266 config: &types.InstallConfig{ 267 Platform: types.Platform{ 268 None: &none.Platform{}, 269 }, 270 }, 271 expected: func() *types.InstallConfig { 272 c := defaultNoneInstallConfig() 273 return c 274 }(), 275 }, 276 } 277 for _, tc := range cases { 278 t.Run(tc.name, func(t *testing.T) { 279 SetInstallConfigDefaults(tc.config) 280 assert.Equal(t, tc.expected, tc.config, "unexpected install config") 281 }) 282 } 283 }