Merge pull request #74498 from feiskyer/fix-subnet

Fix subnet annotation checking for Azure internal loadbalancer
pull/564/head
Kubernetes Prow Robot 2019-02-25 21:48:32 -08:00 committed by GitHub
commit 3c92a6d344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 1 deletions

View File

@ -1538,7 +1538,7 @@ func requiresInternalLoadBalancer(service *v1.Service) bool {
func subnet(service *v1.Service) *string {
if requiresInternalLoadBalancer(service) {
if l, found := service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]; found {
if l, found := service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]; found && strings.TrimSpace(l) != "" {
return &l
}
}

View File

@ -25,6 +25,7 @@ import (
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestFindProbe(t *testing.T) {
@ -243,3 +244,67 @@ func TestGetIdleTimeout(t *testing.T) {
})
}
}
func TestSubnet(t *testing.T) {
for i, c := range []struct {
desc string
service *v1.Service
expected *string
}{
{
desc: "No annotation should return nil",
service: &v1.Service{},
expected: nil,
},
{
desc: "annotation with subnet but no ILB should return nil",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ServiceAnnotationLoadBalancerInternalSubnet: "subnet",
},
},
},
expected: nil,
},
{
desc: "annotation with subnet but ILB=false should return nil",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ServiceAnnotationLoadBalancerInternalSubnet: "subnet",
ServiceAnnotationLoadBalancerInternal: "false",
},
},
},
expected: nil,
},
{
desc: "annotation with empty subnet should return nil",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ServiceAnnotationLoadBalancerInternalSubnet: "",
ServiceAnnotationLoadBalancerInternal: "true",
},
},
},
expected: nil,
},
{
desc: "annotation with subnet and ILB should return subnet",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ServiceAnnotationLoadBalancerInternalSubnet: "subnet",
ServiceAnnotationLoadBalancerInternal: "true",
},
},
},
expected: to.StringPtr("subnet"),
},
} {
real := subnet(c.service)
assert.Equal(t, c.expected, real, fmt.Sprintf("TestCase[%d]: %s", i, c.desc))
}
}