mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Fix subnet annotation checking for Azure internal loadbalancer
This commit is contained in:
parent
139a13d312
commit
8d0c5d9727
@ -1538,7 +1538,7 @@ func requiresInternalLoadBalancer(service *v1.Service) bool {
|
|||||||
|
|
||||||
func subnet(service *v1.Service) *string {
|
func subnet(service *v1.Service) *string {
|
||||||
if requiresInternalLoadBalancer(service) {
|
if requiresInternalLoadBalancer(service) {
|
||||||
if l, found := service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]; found {
|
if l, found := service.Annotations[ServiceAnnotationLoadBalancerInternalSubnet]; found && strings.TrimSpace(l) != "" {
|
||||||
return &l
|
return &l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/Azure/go-autorest/autorest/to"
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFindProbe(t *testing.T) {
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user