Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.0] Allow external service with floating ip disabled to use PLS #2079

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/provider/azure_privatelinkservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (az *Cloud) reconcilePrivateLinkService(

if createPLS {
// Firstly, make sure it's internal service
if !requiresInternalLoadBalancer(service) {
return fmt.Errorf("reconcilePrivateLinkService for service(%s): service requiring private link service must be internal", serviceName)
if !requiresInternalLoadBalancer(service) && !consts.IsK8sServiceDisableLoadBalancerFloatingIP(service) {
return fmt.Errorf("reconcilePrivateLinkService for service(%s): service requiring private link service must be internal or disable floating ip", serviceName)
}

// Secondly, check if there is a private link service already created
Expand Down Expand Up @@ -518,8 +518,10 @@ func getPLSSubnetName(service *v1.Service) *string {
return &l
}

if l, found := service.Annotations[consts.ServiceAnnotationLoadBalancerInternalSubnet]; found && strings.TrimSpace(l) != "" {
return &l
if requiresInternalLoadBalancer(service) {
if l, found := service.Annotations[consts.ServiceAnnotationLoadBalancerInternalSubnet]; found && strings.TrimSpace(l) != "" {
return &l
}
}

return nil
Expand Down
30 changes: 28 additions & 2 deletions pkg/provider/azure_privatelinkservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,33 @@ func TestReconcilePrivateLinkService(t *testing.T) {
wantPLS: true,
},
{
desc: "reconcilePrivateLinkService should return error if service requires PLS but needs external LB",
desc: "reconcilePrivateLinkService should return error if service requires PLS but needs external LB and floating ip enabled",
annotations: map[string]string{
consts.ServiceAnnotationPLSCreation: "true",
},
wantPLS: true,
expectedError: true,
},
{
desc: "reconcilePrivateLinkService should create a new PLS for external service with floating ip disabled",
annotations: map[string]string{
consts.ServiceAnnotationPLSCreation: "true",
consts.ServiceAnnotationDisableLoadBalancerFloatingIP: "true",
},
wantPLS: true,
expectedSubnetGet: true,
existingSubnet: &network.Subnet{
Name: to.StringPtr("subnet"),
ID: to.StringPtr("subnetID"),
SubnetPropertiesFormat: &network.SubnetPropertiesFormat{
PrivateLinkServiceNetworkPolicies: network.VirtualNetworkPrivateLinkServiceNetworkPoliciesDisabled,
},
},
expectedPLSList: true,
existingPLSList: []network.PrivateLinkService{},
expectedPLSCreate: true,
expectedPLS: &network.PrivateLinkService{Name: to.StringPtr("pls-fipConfig")},
},
{
desc: "reconcilePrivateLinkService should create a new PLS if no existing PLS attached to the LB frontend",
annotations: map[string]string{
Expand Down Expand Up @@ -300,7 +320,10 @@ func TestReconcilePrivateLinkService(t *testing.T) {
for i, test := range testCases {
az := GetTestCloud(ctrl)
service := getTestServiceWithAnnotation("test", test.annotations, 80)
fipConfig := &network.FrontendIPConfiguration{ID: to.StringPtr("fipConfigID")}
fipConfig := &network.FrontendIPConfiguration{
Name: to.StringPtr("fipConfig"),
ID: to.StringPtr("fipConfigID"),
}
clusterName := testClusterName

mockSubnetsClient := az.SubnetsClient.(*mocksubnetclient.MockInterface)
Expand Down Expand Up @@ -1329,6 +1352,7 @@ func TestGetPLSSubnetName(t *testing.T) {
{
desc: "Service with empty private link subnet specified but LB subnet specified should return LB subnet",
annotations: map[string]string{
consts.ServiceAnnotationLoadBalancerInternal: "true",
consts.ServiceAnnotationPLSIpConfigurationSubnet: "",
consts.ServiceAnnotationLoadBalancerInternalSubnet: "lb-subnet",
},
Expand All @@ -1337,13 +1361,15 @@ func TestGetPLSSubnetName(t *testing.T) {
{
desc: "Service with LB subnet specified should return it",
annotations: map[string]string{
consts.ServiceAnnotationLoadBalancerInternal: "true",
consts.ServiceAnnotationLoadBalancerInternalSubnet: "lb-subnet",
},
expectedSubnet: to.StringPtr("lb-subnet"),
},
{
desc: "Service with both empty subnets specified should return nil",
annotations: map[string]string{
consts.ServiceAnnotationLoadBalancerInternal: "true",
consts.ServiceAnnotationPLSIpConfigurationSubnet: "",
consts.ServiceAnnotationLoadBalancerInternalSubnet: "",
},
Expand Down