Skip to content

Commit

Permalink
Merge pull request #2074 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2073-to-release-1.24

[release-1.24] Allow external service with floating ip disabled to use PLS
  • Loading branch information
k8s-ci-robot committed Jul 25, 2022
2 parents c0d07b8 + ae3dc85 commit c622e3b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
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

0 comments on commit c622e3b

Please sign in to comment.