|
| 1 | +package defaults |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + configv1 "github.com/openshift/api/config/v1" |
| 9 | + "github.com/openshift/installer/pkg/ipnet" |
| 10 | + "github.com/openshift/installer/pkg/types" |
| 11 | + "github.com/openshift/installer/pkg/types/openstack" |
| 12 | +) |
| 13 | + |
| 14 | +func validPlatform() *openstack.Platform { |
| 15 | + return &openstack.Platform{ |
| 16 | + Cloud: "test-cloud", |
| 17 | + ExternalNetwork: "test-network", |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func validNetworking() *types.Networking { |
| 22 | + return &types.Networking{ |
| 23 | + NetworkType: "OVNKubernetes", |
| 24 | + MachineNetwork: []types.MachineNetworkEntry{{ |
| 25 | + CIDR: *ipnet.MustParseCIDR("10.0.0.0/16"), |
| 26 | + }}, |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestSetPlatformDefaults(t *testing.T) { |
| 31 | + cases := []struct { |
| 32 | + name string |
| 33 | + platform *openstack.Platform |
| 34 | + config *types.InstallConfig |
| 35 | + networking *types.Networking |
| 36 | + expectedLB configv1.PlatformLoadBalancerType |
| 37 | + expectedAPIVIPs []string |
| 38 | + expectedIngressVIPs []string |
| 39 | + }{ |
| 40 | + { |
| 41 | + name: "No load balancer provided", |
| 42 | + platform: func() *openstack.Platform { |
| 43 | + p := validPlatform() |
| 44 | + return p |
| 45 | + }(), |
| 46 | + networking: validNetworking(), |
| 47 | + expectedAPIVIPs: []string{"10.0.0.5"}, |
| 48 | + expectedIngressVIPs: []string{"10.0.0.7"}, |
| 49 | + expectedLB: "OpenShiftManagedDefault", |
| 50 | + }, |
| 51 | + { |
| 52 | + name: "Default Openshift Managed load balancer VIPs provided", |
| 53 | + platform: func() *openstack.Platform { |
| 54 | + p := validPlatform() |
| 55 | + p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{ |
| 56 | + Type: configv1.LoadBalancerTypeOpenShiftManagedDefault, |
| 57 | + } |
| 58 | + p.APIVIPs = []string{"10.0.0.2"} |
| 59 | + p.IngressVIPs = []string{"10.0.0.3"} |
| 60 | + return p |
| 61 | + }(), |
| 62 | + networking: validNetworking(), |
| 63 | + expectedAPIVIPs: []string{"10.0.0.2"}, |
| 64 | + expectedIngressVIPs: []string{"10.0.0.3"}, |
| 65 | + expectedLB: "OpenShiftManagedDefault", |
| 66 | + }, |
| 67 | + { |
| 68 | + name: "Default Openshift Managed load balancer no VIPs provided", |
| 69 | + platform: func() *openstack.Platform { |
| 70 | + p := validPlatform() |
| 71 | + p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{ |
| 72 | + Type: configv1.LoadBalancerTypeOpenShiftManagedDefault, |
| 73 | + } |
| 74 | + return p |
| 75 | + }(), |
| 76 | + networking: validNetworking(), |
| 77 | + expectedAPIVIPs: []string{"10.0.0.5"}, |
| 78 | + expectedIngressVIPs: []string{"10.0.0.7"}, |
| 79 | + expectedLB: "OpenShiftManagedDefault", |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "User managed load balancer VIPs provided", |
| 83 | + platform: func() *openstack.Platform { |
| 84 | + p := validPlatform() |
| 85 | + p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{ |
| 86 | + Type: configv1.LoadBalancerTypeUserManaged, |
| 87 | + } |
| 88 | + p.APIVIPs = []string{"192.168.100.10"} |
| 89 | + p.IngressVIPs = []string{"192.168.100.11"} |
| 90 | + return p |
| 91 | + }(), |
| 92 | + networking: validNetworking(), |
| 93 | + expectedAPIVIPs: []string{"192.168.100.10"}, |
| 94 | + expectedIngressVIPs: []string{"192.168.100.11"}, |
| 95 | + expectedLB: "UserManaged", |
| 96 | + }, |
| 97 | + { |
| 98 | + name: "User managed load balancer no VIPs provided", |
| 99 | + platform: func() *openstack.Platform { |
| 100 | + p := validPlatform() |
| 101 | + p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{ |
| 102 | + Type: configv1.LoadBalancerTypeUserManaged, |
| 103 | + } |
| 104 | + return p |
| 105 | + }(), |
| 106 | + networking: validNetworking(), |
| 107 | + expectedAPIVIPs: []string(nil), |
| 108 | + expectedIngressVIPs: []string(nil), |
| 109 | + expectedLB: "UserManaged", |
| 110 | + }, |
| 111 | + } |
| 112 | + for _, tc := range cases { |
| 113 | + t.Run(tc.name, func(t *testing.T) { |
| 114 | + SetPlatformDefaults(tc.platform, tc.networking) |
| 115 | + assert.Equal(t, tc.expectedLB, tc.platform.LoadBalancer.Type, "unexpected loadbalancer") |
| 116 | + assert.Equal(t, tc.expectedAPIVIPs, tc.platform.APIVIPs, "unexpected APIVIPs") |
| 117 | + assert.Equal(t, tc.expectedIngressVIPs, tc.platform.IngressVIPs, "unexpected IngressVIPs") |
| 118 | + }) |
| 119 | + } |
| 120 | +} |
0 commit comments