mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Add unit tests for feature "Support sharing one IP address for multiple services"
This commit is contained in:
parent
058b4d60a3
commit
6958db632b
@ -514,6 +514,42 @@ func TestServiceOwnsPublicIP(t *testing.T) {
|
|||||||
serviceName: "nginx",
|
serviceName: "nginx",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "false should be returned when the tag is empty",
|
||||||
|
pip: &network.PublicIPAddress{
|
||||||
|
Tags: map[string]*string{
|
||||||
|
serviceTagKey: to.StringPtr(""),
|
||||||
|
clusterNameKey: to.StringPtr("kubernetes"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
clusterName: "kubernetes",
|
||||||
|
serviceName: "nginx",
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "true should be returned if there is a match among a multi-service tag",
|
||||||
|
pip: &network.PublicIPAddress{
|
||||||
|
Tags: map[string]*string{
|
||||||
|
serviceTagKey: to.StringPtr("nginx1,nginx2"),
|
||||||
|
clusterNameKey: to.StringPtr("kubernetes"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
clusterName: "kubernetes",
|
||||||
|
serviceName: "nginx1",
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "false should be returned if there is not a match among a multi-service tag",
|
||||||
|
pip: &network.PublicIPAddress{
|
||||||
|
Tags: map[string]*string{
|
||||||
|
serviceTagKey: to.StringPtr("default/nginx1,default/nginx2"),
|
||||||
|
clusterNameKey: to.StringPtr("kubernetes"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
clusterName: "kubernetes",
|
||||||
|
serviceName: "nginx3",
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range tests {
|
for i, c := range tests {
|
||||||
@ -537,12 +573,12 @@ func TestGetPublicIPAddressResourceGroup(t *testing.T) {
|
|||||||
expected: "rg",
|
expected: "rg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "annoation with empty string resource group",
|
desc: "annotation with empty string resource group",
|
||||||
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: ""},
|
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: ""},
|
||||||
expected: "rg",
|
expected: "rg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "annoation with non-empty resource group ",
|
desc: "annotation with non-empty resource group ",
|
||||||
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: "rg2"},
|
annotations: map[string]string{ServiceAnnotationLoadBalancerResourceGroup: "rg2"},
|
||||||
expected: "rg2",
|
expected: "rg2",
|
||||||
},
|
},
|
||||||
@ -560,7 +596,6 @@ func TestShouldReleaseExistingOwnedPublicIP(t *testing.T) {
|
|||||||
existingPipWithTag := network.PublicIPAddress{
|
existingPipWithTag := network.PublicIPAddress{
|
||||||
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
||||||
Name: to.StringPtr("testPIP"),
|
Name: to.StringPtr("testPIP"),
|
||||||
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
|
||||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
PublicIPAddressVersion: network.IPv4,
|
PublicIPAddressVersion: network.IPv4,
|
||||||
PublicIPAllocationMethod: network.Static,
|
PublicIPAllocationMethod: network.Static,
|
||||||
@ -576,7 +611,7 @@ func TestShouldReleaseExistingOwnedPublicIP(t *testing.T) {
|
|||||||
existingPipWithNoPublicIPAddressFormatProperties := network.PublicIPAddress{
|
existingPipWithNoPublicIPAddressFormatProperties := network.PublicIPAddress{
|
||||||
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
||||||
Name: to.StringPtr("testPIP"),
|
Name: to.StringPtr("testPIP"),
|
||||||
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
Tags: map[string]*string{"service": to.StringPtr("default/test2")},
|
||||||
PublicIPAddressPropertiesFormat: nil,
|
PublicIPAddressPropertiesFormat: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,7 +717,7 @@ func TestShouldReleaseExistingOwnedPublicIP(t *testing.T) {
|
|||||||
|
|
||||||
for i, c := range tests {
|
for i, c := range tests {
|
||||||
|
|
||||||
actualShouldRelease := shouldReleaseExistingOwnedPublicIP(&c.existingPip, c.lbShouldExist, c.lbIsInternal, c.desiredPipName, c.ipTagRequest)
|
actualShouldRelease := shouldReleaseExistingOwnedPublicIP(&c.existingPip, c.lbShouldExist, c.lbIsInternal, c.desiredPipName, "default/test1", c.ipTagRequest)
|
||||||
assert.Equal(t, c.expectedShouldRelease, actualShouldRelease, "TestCase[%d]: %s", i, c.desc)
|
assert.Equal(t, c.expectedShouldRelease, actualShouldRelease, "TestCase[%d]: %s", i, c.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1357,7 +1392,9 @@ func TestIsFrontendIPChanged(t *testing.T) {
|
|||||||
config: network.FrontendIPConfiguration{
|
config: network.FrontendIPConfiguration{
|
||||||
Name: to.StringPtr("btest1-name"),
|
Name: to.StringPtr("btest1-name"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: nil,
|
PublicIPAddress: &network.PublicIPAddress{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lbFrontendIPConfigName: "btest1-name",
|
lbFrontendIPConfigName: "btest1-name",
|
||||||
@ -1366,6 +1403,7 @@ func TestIsFrontendIPChanged(t *testing.T) {
|
|||||||
existingPIPs: []network.PublicIPAddress{
|
existingPIPs: []network.PublicIPAddress{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("pipName"),
|
Name: to.StringPtr("pipName"),
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
IPAddress: to.StringPtr("1.1.1.1"),
|
IPAddress: to.StringPtr("1.1.1.1"),
|
||||||
},
|
},
|
||||||
@ -1404,8 +1442,10 @@ func TestIsFrontendIPChanged(t *testing.T) {
|
|||||||
config: network.FrontendIPConfiguration{
|
config: network.FrontendIPConfiguration{
|
||||||
Name: to.StringPtr("btest1-name"),
|
Name: to.StringPtr("btest1-name"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("/subscriptions/subscription" +
|
PublicIPAddress: &network.PublicIPAddress{
|
||||||
"/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/pipName1")},
|
ID: to.StringPtr("/subscriptions/subscription" +
|
||||||
|
"/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/pipName1"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lbFrontendIPConfigName: "btest1-name",
|
lbFrontendIPConfigName: "btest1-name",
|
||||||
@ -1414,6 +1454,8 @@ func TestIsFrontendIPChanged(t *testing.T) {
|
|||||||
existingPIPs: []network.PublicIPAddress{
|
existingPIPs: []network.PublicIPAddress{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("pipName"),
|
Name: to.StringPtr("pipName"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription" +
|
||||||
|
"/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/pipName2"),
|
||||||
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
IPAddress: to.StringPtr("1.1.1.1"),
|
IPAddress: to.StringPtr("1.1.1.1"),
|
||||||
},
|
},
|
||||||
@ -1448,6 +1490,9 @@ func TestIsFrontendIPChanged(t *testing.T) {
|
|||||||
test.service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = test.annotations
|
test.service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = test.annotations
|
||||||
flag, rerr := az.isFrontendIPChanged("testCluster", test.config,
|
flag, rerr := az.isFrontendIPChanged("testCluster", test.config,
|
||||||
&test.service, test.lbFrontendIPConfigName)
|
&test.service, test.lbFrontendIPConfigName)
|
||||||
|
if rerr != nil {
|
||||||
|
fmt.Println(rerr.Error())
|
||||||
|
}
|
||||||
assert.Equal(t, test.expectedFlag, flag, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedFlag, flag, "TestCase[%d]: %s", i, test.desc)
|
||||||
assert.Equal(t, test.expectedError, rerr != nil, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedError, rerr != nil, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
@ -1684,6 +1729,7 @@ func getTestLoadBalancer(name, rgName, clusterName, identifier *string, service
|
|||||||
FrontendIPConfigurations: &[]network.FrontendIPConfiguration{
|
FrontendIPConfigurations: &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: identifier,
|
Name: identifier,
|
||||||
|
ID: identifier,
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
@ -1745,6 +1791,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
basicLb2.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
basicLb2.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1756,12 +1803,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
modifiedLb1.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
modifiedLb1.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1789,12 +1838,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedLb1.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedLb1.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1806,12 +1857,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
existingSLB.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
existingSLB.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1840,12 +1893,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedSLb.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedSLb.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1857,12 +1912,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
slb5.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
slb5.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1893,12 +1950,14 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedSLb5.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedSLb5.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("bservice1"),
|
Name: to.StringPtr("bservice1"),
|
||||||
|
ID: to.StringPtr("bservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-bservice1")},
|
||||||
},
|
},
|
||||||
@ -1917,6 +1976,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedLB6.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedLB6.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
@ -1938,6 +1998,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedLB7.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedLB7.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
@ -1966,6 +2027,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedLB8.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
expectedLB8.FrontendIPConfigurations = &[]network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr("aservice1"),
|
Name: to.StringPtr("aservice1"),
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/testCluster/frontendIPConfigurations/aservice1"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr("testCluster-aservice1")},
|
||||||
},
|
},
|
||||||
@ -2017,7 +2079,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcileLoadBalancer shall remove and reconstruct the correspond field of lb",
|
desc: "reconcileLoadBalancer shall remove and reconstruct the corresponding field of lb",
|
||||||
loadBalancerSku: "basic",
|
loadBalancerSku: "basic",
|
||||||
service: service3,
|
service: service3,
|
||||||
existingLB: modifiedLb1,
|
existingLB: modifiedLb1,
|
||||||
@ -2036,7 +2098,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcileLoadBalancer shall remove and reconstruct the correspoind field of lb and set enableTcpReset to true in lbRule",
|
desc: "reconcileLoadBalancer shall remove and reconstruct the corresponding field of lb and set enableTcpReset to true in lbRule",
|
||||||
loadBalancerSku: "standard",
|
loadBalancerSku: "standard",
|
||||||
service: service4,
|
service: service4,
|
||||||
disableOutboundSnat: to.BoolPtr(true),
|
disableOutboundSnat: to.BoolPtr(true),
|
||||||
@ -2046,7 +2108,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcileLoadBalancer shall remove and reconstruct the correspoind field of lb and set enableTcpReset (false => true) in lbRule",
|
desc: "reconcileLoadBalancer shall remove and reconstruct the corresponding field of lb and set enableTcpReset (false => true) in lbRule",
|
||||||
loadBalancerSku: "standard",
|
loadBalancerSku: "standard",
|
||||||
service: service5,
|
service: service5,
|
||||||
disableOutboundSnat: to.BoolPtr(true),
|
disableOutboundSnat: to.BoolPtr(true),
|
||||||
@ -2124,7 +2186,7 @@ func TestReconcileLoadBalancer(t *testing.T) {
|
|||||||
assert.Equal(t, test.expectedError, rerr, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedError, rerr, "TestCase[%d]: %s", i, test.desc)
|
||||||
|
|
||||||
if test.expectedError == nil {
|
if test.expectedError == nil {
|
||||||
assert.Equal(t, &test.expectedLB, lb, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedLB, *lb, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2223,7 +2285,7 @@ func TestGetServiceLoadBalancerStatus(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "getServiceLoadBalancerStatus shall return nil if lb.FrontendIPConfigurations.name != " +
|
desc: "getServiceLoadBalancerStatus shall return nil if lb.FrontendIPConfigurations.name != " +
|
||||||
"az.getFrontendIPConfigName(service)",
|
"az.getDefaultFrontendIPConfigName(service)",
|
||||||
service: &internalService,
|
service: &internalService,
|
||||||
lb: &lb3,
|
lb: &lb3,
|
||||||
},
|
},
|
||||||
@ -2517,11 +2579,13 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
expectedPIP *network.PublicIPAddress
|
expectedPIP *network.PublicIPAddress
|
||||||
expectedError bool
|
expectedError bool
|
||||||
expectedCreateOrUpdateCount int
|
expectedCreateOrUpdateCount int
|
||||||
|
expectedDeleteCount int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall return nil if there's no pip in service",
|
desc: "reconcilePublicIP shall return nil if there's no pip in service",
|
||||||
wantLb: false,
|
wantLb: false,
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 0,
|
||||||
|
expectedDeleteCount: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall return nil if no pip is owned by service",
|
desc: "reconcilePublicIP shall return nil if no pip is owned by service",
|
||||||
@ -2532,6 +2596,7 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 0,
|
||||||
|
expectedDeleteCount: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall delete unwanted pips and create a new one",
|
desc: "reconcilePublicIP shall delete unwanted pips and create a new one",
|
||||||
@ -2545,6 +2610,7 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
expectedID: "/subscriptions/subscription/resourceGroups/rg/providers/" +
|
expectedID: "/subscriptions/subscription/resourceGroups/rg/providers/" +
|
||||||
"Microsoft.Network/publicIPAddresses/testCluster-atest1",
|
"Microsoft.Network/publicIPAddresses/testCluster-atest1",
|
||||||
expectedCreateOrUpdateCount: 1,
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall report error if the given PIP name doesn't exist in the resource group",
|
desc: "reconcilePublicIP shall report error if the given PIP name doesn't exist in the resource group",
|
||||||
@ -2562,6 +2628,7 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedError: true,
|
expectedError: true,
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 0,
|
||||||
|
expectedDeleteCount: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall delete unwanted PIP when given the name of desired PIP",
|
desc: "reconcilePublicIP shall delete unwanted PIP when given the name of desired PIP",
|
||||||
@ -2585,8 +2652,43 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
||||||
Name: to.StringPtr("testPIP"),
|
Name: to.StringPtr("testPIP"),
|
||||||
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
PublicIPAllocationMethod: network.Static,
|
||||||
|
PublicIPAddressVersion: network.IPv4,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "reconcilePublicIP shall not delete unwanted PIP when there are other service references",
|
||||||
|
wantLb: true,
|
||||||
|
annotations: map[string]string{ServiceAnnotationPIPName: "testPIP"},
|
||||||
|
existingPIPs: []network.PublicIPAddress{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("pip1"),
|
||||||
|
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("pip2"),
|
||||||
|
Tags: map[string]*string{"service": to.StringPtr("default/test1,default/test2")},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("testPIP"),
|
||||||
|
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedPIP: &network.PublicIPAddress{
|
||||||
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
||||||
|
Name: to.StringPtr("testPIP"),
|
||||||
|
Tags: map[string]*string{"service": to.StringPtr("default/test1")},
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
PublicIPAllocationMethod: network.Static,
|
||||||
|
PublicIPAddressVersion: network.IPv4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall delete unwanted pips and existing pips, when the existing pips IP tags do not match",
|
desc: "reconcilePublicIP shall delete unwanted pips and existing pips, when the existing pips IP tags do not match",
|
||||||
@ -2625,6 +2727,7 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCreateOrUpdateCount: 1,
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall preserve existing pips, when the existing pips IP tags do match",
|
desc: "reconcilePublicIP shall preserve existing pips, when the existing pips IP tags do match",
|
||||||
@ -2664,7 +2767,8 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "reconcilePublicIP shall find the PIP by given name and shall not delete the PIP which is not owned by service",
|
desc: "reconcilePublicIP shall find the PIP by given name and shall not delete the PIP which is not owned by service",
|
||||||
@ -2685,8 +2789,24 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
expectedPIP: &network.PublicIPAddress{
|
expectedPIP: &network.PublicIPAddress{
|
||||||
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
ID: to.StringPtr("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP"),
|
||||||
Name: to.StringPtr("testPIP"),
|
Name: to.StringPtr("testPIP"),
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
PublicIPAllocationMethod: network.Static,
|
||||||
|
PublicIPAddressVersion: network.IPv4,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedCreateOrUpdateCount: 0,
|
expectedCreateOrUpdateCount: 1,
|
||||||
|
expectedDeleteCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "reconcilePublicIP shall delete the unwanted PIP name from service tag and shall not delete it if there is other reference",
|
||||||
|
wantLb: false,
|
||||||
|
existingPIPs: []network.PublicIPAddress{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("pip1"),
|
||||||
|
Tags: map[string]*string{serviceTagKey: to.StringPtr("default/test1,default/test2")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCreateOrUpdateCount: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2768,6 +2888,14 @@ func TestReconcilePublicIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, test.expectedCreateOrUpdateCount, createOrUpdateCount, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedCreateOrUpdateCount, createOrUpdateCount, "TestCase[%d]: %s", i, test.desc)
|
||||||
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s", i, test.desc)
|
||||||
|
|
||||||
|
deletedCount := 0
|
||||||
|
for _, deleted := range deletedPips {
|
||||||
|
if deleted {
|
||||||
|
deletedCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expectedDeleteCount, deletedCount, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2894,6 +3022,21 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "ensurePublicIPExists shall report an conflict error if the DNS label is conflicted",
|
||||||
|
inputDNSLabel: "test",
|
||||||
|
foundDNSLabelAnnotation: true,
|
||||||
|
existingPIPs: []network.PublicIPAddress{{
|
||||||
|
Name: to.StringPtr("pip1"),
|
||||||
|
Tags: map[string]*string{serviceUsingDNSKey: to.StringPtr("test1")},
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
DNSSettings: &network.PublicIPAddressDNSSettings{
|
||||||
|
DomainNameLabel: to.StringPtr("previousdns"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
expectedError: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
@ -2944,12 +3087,12 @@ func TestEnsurePublicIPExists(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pip, err := az.ensurePublicIPExists(&service, "pip1", test.inputDNSLabel, "", false, test.foundDNSLabelAnnotation)
|
pip, err := az.ensurePublicIPExists(&service, "pip1", test.inputDNSLabel, "", false, test.foundDNSLabelAnnotation)
|
||||||
|
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s, encountered unexpected error: %v", i, test.desc, err)
|
||||||
if test.expectedID != "" {
|
if test.expectedID != "" {
|
||||||
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedID, to.String(pip.ID), "TestCase[%d]: %s", i, test.desc)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, test.expectedPIP, pip, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedPIP, pip, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
assert.Equal(t, test.expectedError, err != nil, "TestCase[%d]: %s", i, test.desc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3100,3 +3243,306 @@ func TestIsBackendPoolPreConfigured(t *testing.T) {
|
|||||||
assert.Equal(t, test.expectedOutput, isPreConfigured, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedOutput, isPreConfigured, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParsePIPServiceTag(t *testing.T) {
|
||||||
|
tags := []*string{
|
||||||
|
to.StringPtr("ns1/svc1,ns2/svc2"),
|
||||||
|
to.StringPtr(" ns1/svc1, ns2/svc2 "),
|
||||||
|
to.StringPtr("ns1/svc1,"),
|
||||||
|
to.StringPtr(""),
|
||||||
|
nil,
|
||||||
|
}
|
||||||
|
expectedNames := [][]string{
|
||||||
|
{"ns1/svc1", "ns2/svc2"},
|
||||||
|
{"ns1/svc1", "ns2/svc2"},
|
||||||
|
{"ns1/svc1"},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tag := range tags {
|
||||||
|
names := parsePIPServiceTag(tag)
|
||||||
|
assert.Equal(t, expectedNames[i], names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBindServicesToPIP(t *testing.T) {
|
||||||
|
pips := []*network.PublicIPAddress{
|
||||||
|
{Tags: nil},
|
||||||
|
{Tags: map[string]*string{}},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("ns1/svc1")}},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("ns1/svc1,ns2/svc2")}},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("ns2/svc2,ns3/svc3")}},
|
||||||
|
}
|
||||||
|
serviceNames := []string{"ns2/svc2", "ns3/svc3"}
|
||||||
|
expectedTags := []map[string]*string{
|
||||||
|
{serviceTagKey: to.StringPtr("ns2/svc2,ns3/svc3")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns2/svc2,ns3/svc3")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns1/svc1,ns2/svc2,ns3/svc3")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns1/svc1,ns2/svc2,ns3/svc3")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns2/svc2,ns3/svc3")},
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := []bool{true, true, true, true, false}
|
||||||
|
|
||||||
|
for i, pip := range pips {
|
||||||
|
addedNew, _ := bindServicesToPIP(pip, serviceNames, false)
|
||||||
|
assert.Equal(t, expectedTags[i], pip.Tags)
|
||||||
|
assert.Equal(t, flags[i], addedNew)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnbindServiceFromPIP(t *testing.T) {
|
||||||
|
pips := []*network.PublicIPAddress{
|
||||||
|
{Tags: nil},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("")}},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("ns1/svc1")}},
|
||||||
|
{Tags: map[string]*string{serviceTagKey: to.StringPtr("ns1/svc1,ns2/svc2")}},
|
||||||
|
}
|
||||||
|
serviceName := "ns2/svc2"
|
||||||
|
expectedTags := []map[string]*string{
|
||||||
|
nil,
|
||||||
|
{serviceTagKey: to.StringPtr("")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns1/svc1")},
|
||||||
|
{serviceTagKey: to.StringPtr("ns1/svc1")},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, pip := range pips {
|
||||||
|
_ = unbindServiceFromPIP(pip, serviceName)
|
||||||
|
assert.Equal(t, expectedTags[i], pip.Tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsFrontendIPConfigIsUnsafeToDelete(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
service := getTestService("service1", v1.ProtocolTCP, nil, false, 80)
|
||||||
|
az := GetTestCloud(ctrl)
|
||||||
|
fipID := to.StringPtr("fip")
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
existingLB *network.LoadBalancer
|
||||||
|
unsafe bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "isFrontendIPConfigIsUnsafeToDelete should return true if there is a " +
|
||||||
|
"loadBalancing rule from other service referencing the frontend IP config",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
LoadBalancingRules: &[]network.LoadBalancingRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice2-rule"),
|
||||||
|
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unsafe: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "isFrontendIPConfigIsUnsafeToDelete should return false if there is a " +
|
||||||
|
"loadBalancing rule from this service referencing the frontend IP config",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
OutboundRules: &[]network.OutboundRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
OutboundRulePropertiesFormat: &network.OutboundRulePropertiesFormat{
|
||||||
|
FrontendIPConfigurations: &[]network.SubResource{
|
||||||
|
{ID: to.StringPtr("fip")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unsafe: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "isFrontendIPConfigIsUnsafeToDelete should return false if there is a " +
|
||||||
|
"outbound rule referencing the frontend IP config",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
LoadBalancingRules: &[]network.LoadBalancingRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "isFrontendIPConfigIsUnsafeToDelete should return true if there is a " +
|
||||||
|
"inbound NAT rule referencing the frontend IP config",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
InboundNatRules: &[]network.InboundNatRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice2-rule"),
|
||||||
|
InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unsafe: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "isFrontendIPConfigIsUnsafeToDelete should return true if there is a " +
|
||||||
|
"inbound NAT pool referencing the frontend IP config",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
InboundNatPools: &[]network.InboundNatPool{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice2-rule"),
|
||||||
|
InboundNatPoolPropertiesFormat: &network.InboundNatPoolPropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unsafe: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
unsafe, _ := az.isFrontendIPConfigIsUnsafeToDelete(testCase.existingLB, &service, fipID)
|
||||||
|
assert.Equal(t, testCase.unsafe, unsafe, testCase.desc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckLoadBalancerResourcesConflicted(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
service := getTestService("service1", v1.ProtocolTCP, nil, false, 80)
|
||||||
|
az := GetTestCloud(ctrl)
|
||||||
|
fipID := "fip"
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
existingLB *network.LoadBalancer
|
||||||
|
expectedErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "checkLoadBalancerResourcesConflicted should report the conflict error if " +
|
||||||
|
"there is a conflicted loadBalancing rule",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
LoadBalancingRules: &[]network.LoadBalancingRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice2-rule"),
|
||||||
|
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPort: to.Int32Ptr(80),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "checkLoadBalancerResourcesConflicted should report the conflict error if " +
|
||||||
|
"there is a conflicted inbound NAT rule",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
InboundNatRules: &[]network.InboundNatRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPort: to.Int32Ptr(80),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "checkLoadBalancerResourcesConflicted should report the conflict error if " +
|
||||||
|
"there is a conflicted inbound NAT pool",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
InboundNatPools: &[]network.InboundNatPool{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
InboundNatPoolPropertiesFormat: &network.InboundNatPoolPropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPortRangeStart: to.Int32Ptr(80),
|
||||||
|
FrontendPortRangeEnd: to.Int32Ptr(90),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "checkLoadBalancerResourcesConflicted should not report the conflict error if there " +
|
||||||
|
"is no conflicted loadBalancer resources",
|
||||||
|
existingLB: &network.LoadBalancer{
|
||||||
|
Name: to.StringPtr("lb"),
|
||||||
|
LoadBalancerPropertiesFormat: &network.LoadBalancerPropertiesFormat{
|
||||||
|
LoadBalancingRules: &[]network.LoadBalancingRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice2-rule"),
|
||||||
|
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPort: to.Int32Ptr(90),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InboundNatRules: &[]network.InboundNatRule{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
InboundNatRulePropertiesFormat: &network.InboundNatRulePropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPort: to.Int32Ptr(90),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InboundNatPools: &[]network.InboundNatPool{
|
||||||
|
{
|
||||||
|
Name: to.StringPtr("aservice1-rule"),
|
||||||
|
InboundNatPoolPropertiesFormat: &network.InboundNatPoolPropertiesFormat{
|
||||||
|
FrontendIPConfiguration: &network.SubResource{ID: to.StringPtr("fip")},
|
||||||
|
FrontendPortRangeStart: to.Int32Ptr(800),
|
||||||
|
FrontendPortRangeEnd: to.Int32Ptr(900),
|
||||||
|
Protocol: network.TransportProtocol(v1.ProtocolTCP),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
err := az.checkLoadBalancerResourcesConflicted(testCase.existingLB, fipID, &service)
|
||||||
|
assert.Equal(t, testCase.expectedErr, err != nil, testCase.desc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
cloudprovider "k8s.io/cloud-provider"
|
cloudprovider "k8s.io/cloud-provider"
|
||||||
"k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient"
|
"k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient"
|
||||||
|
"k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient"
|
||||||
"k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient"
|
"k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient"
|
||||||
"k8s.io/legacy-cloud-providers/azure/retry"
|
"k8s.io/legacy-cloud-providers/azure/retry"
|
||||||
)
|
)
|
||||||
@ -447,7 +448,7 @@ func TestGetFrontendIPConfigName(t *testing.T) {
|
|||||||
svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = c.subnetName
|
svc.Annotations[ServiceAnnotationLoadBalancerInternalSubnet] = c.subnetName
|
||||||
svc.Annotations[ServiceAnnotationLoadBalancerInternal] = strconv.FormatBool(c.isInternal)
|
svc.Annotations[ServiceAnnotationLoadBalancerInternal] = strconv.FormatBool(c.isInternal)
|
||||||
|
|
||||||
ipconfigName := az.getFrontendIPConfigName(svc)
|
ipconfigName := az.getDefaultFrontendIPConfigName(svc)
|
||||||
assert.Equal(t, c.expected, ipconfigName, c.description)
|
assert.Equal(t, c.expected, ipconfigName, c.description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1509,3 +1510,158 @@ func TestStandardEnsureHostsInPool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServiceOwnsFrontendIP(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
cloud := GetTestCloud(ctrl)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
existingPIPs []network.PublicIPAddress
|
||||||
|
fip network.FrontendIPConfiguration
|
||||||
|
service *v1.Service
|
||||||
|
isOwned bool
|
||||||
|
isPrimary bool
|
||||||
|
expectedErr error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should detect the primary service",
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("uid"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isOwned: true,
|
||||||
|
isPrimary: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should return false if the secondary external service doesn't set it's loadBalancer IP",
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("secondary"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should report a not found error if there is no public IP " +
|
||||||
|
"found according to the external service's loadBalancer IP but do not return the error",
|
||||||
|
existingPIPs: []network.PublicIPAddress{
|
||||||
|
{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
IPAddress: to.StringPtr("4.3.2.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
|
PublicIPAddress: &network.PublicIPAddress{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("secondary"),
|
||||||
|
},
|
||||||
|
Spec: v1.ServiceSpec{
|
||||||
|
LoadBalancerIP: "1.2.3.4",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should return false if there is a mismatch between the PIP's ID and " +
|
||||||
|
"the counterpart on the frontend IP config",
|
||||||
|
existingPIPs: []network.PublicIPAddress{
|
||||||
|
{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
IPAddress: to.StringPtr("4.3.2.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
|
PublicIPAddress: &network.PublicIPAddress{
|
||||||
|
ID: to.StringPtr("pip1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("secondary"),
|
||||||
|
},
|
||||||
|
Spec: v1.ServiceSpec{
|
||||||
|
LoadBalancerIP: "4.3.2.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should detect the secondary external service",
|
||||||
|
existingPIPs: []network.PublicIPAddress{
|
||||||
|
{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
|
||||||
|
IPAddress: to.StringPtr("4.3.2.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
|
PublicIPAddress: &network.PublicIPAddress{
|
||||||
|
ID: to.StringPtr("pip"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("secondary"),
|
||||||
|
},
|
||||||
|
Spec: v1.ServiceSpec{
|
||||||
|
LoadBalancerIP: "4.3.2.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isOwned: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "serviceOwnsFrontendIP should detect the secondary internal service",
|
||||||
|
fip: network.FrontendIPConfiguration{
|
||||||
|
Name: to.StringPtr("auid"),
|
||||||
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
|
PrivateIPAddress: to.StringPtr("4.3.2.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
service: &v1.Service{
|
||||||
|
ObjectMeta: meta.ObjectMeta{
|
||||||
|
UID: types.UID("secondary"),
|
||||||
|
Annotations: map[string]string{ServiceAnnotationLoadBalancerInternal: "true"},
|
||||||
|
},
|
||||||
|
Spec: v1.ServiceSpec{
|
||||||
|
LoadBalancerIP: "4.3.2.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isOwned: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
mockPIPClient := mockpublicipclient.NewMockInterface(ctrl)
|
||||||
|
cloud.PublicIPAddressesClient = mockPIPClient
|
||||||
|
mockPIPClient.EXPECT().List(gomock.Any(), gomock.Any()).Return(test.existingPIPs, nil).MaxTimes(1)
|
||||||
|
|
||||||
|
isOwned, isPrimary, err := cloud.serviceOwnsFrontendIP(test.fip, test.service)
|
||||||
|
assert.Equal(t, test.expectedErr, err, test.desc)
|
||||||
|
assert.Equal(t, test.isOwned, isOwned, test.desc)
|
||||||
|
assert.Equal(t, test.isPrimary, isPrimary, test.desc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -231,6 +231,7 @@ func setMockLBs(az *Cloud, ctrl *gomock.Controller, expectedLBs *[]network.LoadB
|
|||||||
fips := []network.FrontendIPConfiguration{
|
fips := []network.FrontendIPConfiguration{
|
||||||
{
|
{
|
||||||
Name: to.StringPtr(fmt.Sprintf("a%s%d", fullServiceName, serviceIndex)),
|
Name: to.StringPtr(fmt.Sprintf("a%s%d", fullServiceName, serviceIndex)),
|
||||||
|
ID: to.StringPtr("fip"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PrivateIPAllocationMethod: "Dynamic",
|
PrivateIPAllocationMethod: "Dynamic",
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr(fmt.Sprintf("testCluster-a%s%d", fullServiceName, serviceIndex))},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr(fmt.Sprintf("testCluster-a%s%d", fullServiceName, serviceIndex))},
|
||||||
@ -249,6 +250,7 @@ func setMockLBs(az *Cloud, ctrl *gomock.Controller, expectedLBs *[]network.LoadB
|
|||||||
})
|
})
|
||||||
fip := network.FrontendIPConfiguration{
|
fip := network.FrontendIPConfiguration{
|
||||||
Name: to.StringPtr(fmt.Sprintf("a%s%d", fullServiceName, serviceIndex)),
|
Name: to.StringPtr(fmt.Sprintf("a%s%d", fullServiceName, serviceIndex)),
|
||||||
|
ID: to.StringPtr("fip"),
|
||||||
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
FrontendIPConfigurationPropertiesFormat: &network.FrontendIPConfigurationPropertiesFormat{
|
||||||
PrivateIPAllocationMethod: "Dynamic",
|
PrivateIPAllocationMethod: "Dynamic",
|
||||||
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr(fmt.Sprintf("testCluster-a%s%d", fullServiceName, serviceIndex))},
|
PublicIPAddress: &network.PublicIPAddress{ID: to.StringPtr(fmt.Sprintf("testCluster-a%s%d", fullServiceName, serviceIndex))},
|
||||||
@ -292,10 +294,10 @@ func testLoadBalancerServiceDefaultModeSelection(t *testing.T, isInternal bool)
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedLBName := setMockLBs(az, ctrl, &expectedLBs, "service", 1, index, isInternal)
|
expectedLBName := setMockLBs(az, ctrl, &expectedLBs, "service", 1, index, isInternal)
|
||||||
@ -349,10 +351,10 @@ func testLoadBalancerServiceAutoModeSelection(t *testing.T, isInternal bool) {
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
setLoadBalancerAutoModeAnnotation(&svc)
|
setLoadBalancerAutoModeAnnotation(&svc)
|
||||||
|
|
||||||
@ -421,10 +423,10 @@ func testLoadBalancerServicesSpecifiedSelection(t *testing.T, isInternal bool) {
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
lbMode := fmt.Sprintf("%s,%s", selectedAvailabilitySetName1, selectedAvailabilitySetName2)
|
lbMode := fmt.Sprintf("%s,%s", selectedAvailabilitySetName1, selectedAvailabilitySetName2)
|
||||||
setLoadBalancerModeAnnotation(&svc, lbMode)
|
setLoadBalancerModeAnnotation(&svc, lbMode)
|
||||||
@ -470,10 +472,10 @@ func testLoadBalancerMaxRulesServices(t *testing.T, isInternal bool) {
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
setMockLBs(az, ctrl, &expectedLBs, "service", az.Config.MaximumLoadBalancerRuleCount, index, isInternal)
|
setMockLBs(az, ctrl, &expectedLBs, "service", az.Config.MaximumLoadBalancerRuleCount, index, isInternal)
|
||||||
@ -551,10 +553,10 @@ func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal boo
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
setLoadBalancerAutoModeAnnotation(&svc)
|
setLoadBalancerAutoModeAnnotation(&svc)
|
||||||
|
|
||||||
@ -573,10 +575,10 @@ func testLoadBalancerServiceAutoModeDeleteSelection(t *testing.T, isInternal boo
|
|||||||
svcName := fmt.Sprintf("service-%d", index)
|
svcName := fmt.Sprintf("service-%d", index)
|
||||||
var svc v1.Service
|
var svc v1.Service
|
||||||
if isInternal {
|
if isInternal {
|
||||||
svc = getInternalTestService(svcName, 8081)
|
svc = getInternalTestService(svcName, int32(index))
|
||||||
validateTestSubnet(t, az, &svc)
|
validateTestSubnet(t, az, &svc)
|
||||||
} else {
|
} else {
|
||||||
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, 8081)
|
svc = getTestService(svcName, v1.ProtocolTCP, nil, false, int32(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoadBalancerAutoModeAnnotation(&svc)
|
setLoadBalancerAutoModeAnnotation(&svc)
|
||||||
@ -919,7 +921,7 @@ func TestReconcileLoadBalancerMultipleServices(t *testing.T) {
|
|||||||
setMockEnv(az, ctrl, expectedInterfaces, expectedVirtualMachines, 2)
|
setMockEnv(az, ctrl, expectedInterfaces, expectedVirtualMachines, 2)
|
||||||
|
|
||||||
svc1 := getTestService("service1", v1.ProtocolTCP, nil, false, 80, 443)
|
svc1 := getTestService("service1", v1.ProtocolTCP, nil, false, 80, 443)
|
||||||
svc2 := getTestService("service2", v1.ProtocolTCP, nil, false, 80)
|
svc2 := getTestService("service2", v1.ProtocolTCP, nil, false, 81)
|
||||||
|
|
||||||
expectedLBs := make([]network.LoadBalancer, 0)
|
expectedLBs := make([]network.LoadBalancer, 0)
|
||||||
setMockLBs(az, ctrl, &expectedLBs, "service", 1, 1, false)
|
setMockLBs(az, ctrl, &expectedLBs, "service", 1, 1, false)
|
||||||
@ -1030,7 +1032,7 @@ func TestServiceRespectsNoSessionAffinity(t *testing.T) {
|
|||||||
mockPIPsClient := mockpublicipclient.NewMockInterface(ctrl)
|
mockPIPsClient := mockpublicipclient.NewMockInterface(ctrl)
|
||||||
az.PublicIPAddressesClient = mockPIPsClient
|
az.PublicIPAddressesClient = mockPIPsClient
|
||||||
mockPIPsClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
mockPIPsClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||||
mockPIPsClient.EXPECT().Get(gomock.Any(), az.ResourceGroup, "testCluster-aservicesanone", gomock.Any()).Return(expectedPIP, nil).AnyTimes()
|
mockPIPsClient.EXPECT().Get(gomock.Any(), az.ResourceGroup, gomock.Any(), gomock.Any()).Return(expectedPIP, nil).AnyTimes()
|
||||||
|
|
||||||
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
|
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1082,7 +1084,7 @@ func TestServiceRespectsClientIPSessionAffinity(t *testing.T) {
|
|||||||
mockPIPsClient := mockpublicipclient.NewMockInterface(ctrl)
|
mockPIPsClient := mockpublicipclient.NewMockInterface(ctrl)
|
||||||
az.PublicIPAddressesClient = mockPIPsClient
|
az.PublicIPAddressesClient = mockPIPsClient
|
||||||
mockPIPsClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
mockPIPsClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||||
mockPIPsClient.EXPECT().Get(gomock.Any(), az.ResourceGroup, "testCluster-aservicesaclientip", gomock.Any()).Return(expectedPIP, nil).AnyTimes()
|
mockPIPsClient.EXPECT().Get(gomock.Any(), az.ResourceGroup, gomock.Any(), gomock.Any()).Return(expectedPIP, nil).AnyTimes()
|
||||||
|
|
||||||
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
|
lb, err := az.reconcileLoadBalancer(testClusterName, &svc, clusterResources.nodes, true /* wantLb */)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1600,7 +1602,7 @@ func validateLoadBalancer(t *testing.T, loadBalancer *network.LoadBalancer, serv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expectedFrontendIP := ExpectedFrontendIPInfo{
|
expectedFrontendIP := ExpectedFrontendIPInfo{
|
||||||
Name: az.getFrontendIPConfigName(&svc),
|
Name: az.getDefaultFrontendIPConfigName(&svc),
|
||||||
Subnet: to.StringPtr(expectedSubnetName),
|
Subnet: to.StringPtr(expectedSubnetName),
|
||||||
}
|
}
|
||||||
expectedFrontendIPs = append(expectedFrontendIPs, expectedFrontendIP)
|
expectedFrontendIPs = append(expectedFrontendIPs, expectedFrontendIP)
|
||||||
|
Loading…
Reference in New Issue
Block a user