Skip to content

Commit

Permalink
Merge pull request #5164 from lodrem/refactor-lb/consolidate-security…
Browse files Browse the repository at this point in the history
…-rules

Refine LoadBalancer service access control and consolidating security-rules
  • Loading branch information
k8s-ci-robot committed Jan 5, 2024
2 parents 05b4c16 + 87a5835 commit 1d8032f
Show file tree
Hide file tree
Showing 30 changed files with 8,712 additions and 3,758 deletions.
603 changes: 113 additions & 490 deletions pkg/provider/azure_loadbalancer.go

Large diffs are not rendered by default.

2,529 changes: 2,529 additions & 0 deletions pkg/provider/azure_loadbalancer_accesscontrol_test.go

Large diffs are not rendered by default.

944 changes: 0 additions & 944 deletions pkg/provider/azure_loadbalancer_test.go

Large diffs are not rendered by default.

997 changes: 1 addition & 996 deletions pkg/provider/azure_test.go

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions pkg/provider/azure_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,6 @@ func getExtendedLocationTypeFromString(extendedLocationType string) network.Exte
return network.EdgeZone
}

func getServiceAdditionalPublicIPs(service *v1.Service) ([]string, error) {
if service == nil {
return nil, nil
}

result := []string{}
if val, ok := service.Annotations[consts.ServiceAnnotationAdditionalPublicIPs]; ok {
pips := strings.Split(strings.TrimSpace(val), ",")
for _, pip := range pips {
ip := strings.TrimSpace(pip)
if ip == "" {
continue // skip empty string
}

if net.ParseIP(ip) == nil {
return nil, fmt.Errorf("%s is not a valid IP address", ip)
}

result = append(result, ip)
}
}

return result, nil
}

func getNodePrivateIPAddress(node *v1.Node, isIPv6 bool) string {
for _, nodeAddress := range node.Status.Addresses {
if strings.EqualFold(string(nodeAddress.Type), string(v1.NodeInternalIP)) &&
Expand Down
73 changes: 0 additions & 73 deletions pkg/provider/azure_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package provider

import (
"fmt"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -190,78 +189,6 @@ func TestReconcileTags(t *testing.T) {
}
}

func TestGetServiceAdditionalPublicIPs(t *testing.T) {
for _, testCase := range []struct {
description string
service *v1.Service
expectedIPs []string
expectedError error
}{
{
description: "nil service should return empty IP list",
},
{
description: "service without annotation should return empty IP list",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{},
},
},
expectedIPs: []string{},
},
{
description: "service without annotation should return empty IP list",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
consts.ServiceAnnotationAdditionalPublicIPs: "",
},
},
},
expectedIPs: []string{},
},
{
description: "service with one IP in annotation should return expected IPs",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
consts.ServiceAnnotationAdditionalPublicIPs: "1.2.3.4 ",
},
},
},
expectedIPs: []string{"1.2.3.4"},
},
{
description: "service with multiple IPs in annotation should return expected IPs",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
consts.ServiceAnnotationAdditionalPublicIPs: "1.2.3.4, 2.3.4.5 ",
},
},
},
expectedIPs: []string{"1.2.3.4", "2.3.4.5"},
},
{
description: "service with wrong IP in annotation should report an error",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
consts.ServiceAnnotationAdditionalPublicIPs: "invalid",
},
},
},
expectedError: fmt.Errorf("invalid is not a valid IP address"),
},
} {
t.Run(testCase.description, func(t *testing.T) {
ips, err := getServiceAdditionalPublicIPs(testCase.service)
assert.Equal(t, testCase.expectedIPs, ips)
assert.Equal(t, testCase.expectedError, err)
})
}
}

func TestGetNodePrivateIPAddress(t *testing.T) {
testcases := []struct {
desc string
Expand Down

0 comments on commit 1d8032f

Please sign in to comment.