Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bf79c7c7
Unverified
Commit
bf79c7c7
authored
May 10, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77719 from feiskyer/fix-service-tag
Fix some service tags not supported issues for Azure LoadBalancer service
parents
8fecbd8e
5b396710
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
21 deletions
+70
-21
azure_loadbalancer.go
...k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go
+13
-21
azure_loadbalancer_test.go
...o/legacy-cloud-providers/azure/azure_loadbalancer_test.go
+57
-0
No files found.
staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer.go
View file @
bf79c7c7
...
@@ -74,6 +74,7 @@ const (
...
@@ -74,6 +74,7 @@ const (
// ServiceAnnotationAllowedServiceTag is the annotation used on the service
// ServiceAnnotationAllowedServiceTag is the annotation used on the service
// to specify a list of allowed service tags separated by comma
// to specify a list of allowed service tags separated by comma
// Refer https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#service-tags for all supported service tags.
ServiceAnnotationAllowedServiceTag
=
"service.beta.kubernetes.io/azure-allowed-service-tags"
ServiceAnnotationAllowedServiceTag
=
"service.beta.kubernetes.io/azure-allowed-service-tags"
// ServiceAnnotationLoadBalancerIdleTimeout is the annotation used on the service
// ServiceAnnotationLoadBalancerIdleTimeout is the annotation used on the service
...
@@ -90,13 +91,6 @@ const (
...
@@ -90,13 +91,6 @@ const (
clusterNameKey
=
"kubernetes-cluster-name"
clusterNameKey
=
"kubernetes-cluster-name"
)
)
var
(
// supportedServiceTags holds a list of supported service tags on Azure.
// Refer https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#service-tags for more information.
supportedServiceTags
=
sets
.
NewString
(
"VirtualNetwork"
,
"VIRTUAL_NETWORK"
,
"AzureLoadBalancer"
,
"AZURE_LOADBALANCER"
,
"Internet"
,
"INTERNET"
,
"AzureTrafficManager"
,
"Storage"
,
"Sql"
)
)
// GetLoadBalancer returns whether the specified load balancer exists, and
// GetLoadBalancer returns whether the specified load balancer exists, and
// if so, what its status is.
// if so, what its status is.
func
(
az
*
Cloud
)
GetLoadBalancer
(
ctx
context
.
Context
,
clusterName
string
,
service
*
v1
.
Service
)
(
status
*
v1
.
LoadBalancerStatus
,
exists
bool
,
err
error
)
{
func
(
az
*
Cloud
)
GetLoadBalancer
(
ctx
context
.
Context
,
clusterName
string
,
service
*
v1
.
Service
)
(
status
*
v1
.
LoadBalancerStatus
,
exists
bool
,
err
error
)
{
...
@@ -1028,10 +1022,7 @@ func (az *Cloud) reconcileSecurityGroup(clusterName string, service *v1.Service,
...
@@ -1028,10 +1022,7 @@ func (az *Cloud) reconcileSecurityGroup(clusterName string, service *v1.Service,
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
serviceTags
,
err
:=
getServiceTags
(
service
)
serviceTags
:=
getServiceTags
(
service
)
if
err
!=
nil
{
return
nil
,
err
}
var
sourceAddressPrefixes
[]
string
var
sourceAddressPrefixes
[]
string
if
(
sourceRanges
==
nil
||
servicehelpers
.
IsAllowAll
(
sourceRanges
))
&&
len
(
serviceTags
)
==
0
{
if
(
sourceRanges
==
nil
||
servicehelpers
.
IsAllowAll
(
sourceRanges
))
&&
len
(
serviceTags
)
==
0
{
if
!
requiresInternalLoadBalancer
(
service
)
{
if
!
requiresInternalLoadBalancer
(
service
)
{
...
@@ -1609,24 +1600,25 @@ func useSharedSecurityRule(service *v1.Service) bool {
...
@@ -1609,24 +1600,25 @@ func useSharedSecurityRule(service *v1.Service) bool {
return
false
return
false
}
}
func
getServiceTags
(
service
*
v1
.
Service
)
([]
string
,
error
)
{
func
getServiceTags
(
service
*
v1
.
Service
)
[]
string
{
if
service
==
nil
{
return
nil
}
if
serviceTags
,
found
:=
service
.
Annotations
[
ServiceAnnotationAllowedServiceTag
];
found
{
if
serviceTags
,
found
:=
service
.
Annotations
[
ServiceAnnotationAllowedServiceTag
];
found
{
result
:=
[]
string
{}
tags
:=
strings
.
Split
(
strings
.
TrimSpace
(
serviceTags
),
","
)
tags
:=
strings
.
Split
(
strings
.
TrimSpace
(
serviceTags
),
","
)
for
_
,
tag
:=
range
tags
{
for
_
,
tag
:=
range
tags
{
// Storage and Sql service tags support setting regions with suffix ".Region"
serviceTag
:=
strings
.
TrimSpace
(
tag
)
if
strings
.
HasPrefix
(
tag
,
"Storage."
)
||
strings
.
HasPrefix
(
tag
,
"Sql."
)
{
if
serviceTag
!=
""
{
continue
result
=
append
(
result
,
serviceTag
)
}
if
!
supportedServiceTags
.
Has
(
tag
)
{
return
nil
,
fmt
.
Errorf
(
"only %q are allowed in service tags"
,
supportedServiceTags
.
List
())
}
}
}
}
return
tags
,
nil
return
result
}
}
return
nil
,
nil
return
nil
}
}
func
serviceOwnsPublicIP
(
pip
*
network
.
PublicIPAddress
,
clusterName
,
serviceName
string
)
bool
{
func
serviceOwnsPublicIP
(
pip
*
network
.
PublicIPAddress
,
clusterName
,
serviceName
string
)
bool
{
...
...
staging/src/k8s.io/legacy-cloud-providers/azure/azure_loadbalancer_test.go
View file @
bf79c7c7
...
@@ -447,3 +447,60 @@ func TestServiceOwnsPublicIP(t *testing.T) {
...
@@ -447,3 +447,60 @@ func TestServiceOwnsPublicIP(t *testing.T) {
assert
.
Equal
(
t
,
owns
,
c
.
expected
,
"TestCase[%d]: %s"
,
i
,
c
.
desc
)
assert
.
Equal
(
t
,
owns
,
c
.
expected
,
"TestCase[%d]: %s"
,
i
,
c
.
desc
)
}
}
}
}
func
TestGetServiceTags
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
desc
string
service
*
v1
.
Service
expected
[]
string
}{
{
desc
:
"nil should be returned when service is nil"
,
service
:
nil
,
expected
:
nil
,
},
{
desc
:
"nil should be returned when service has no annotations"
,
service
:
&
v1
.
Service
{},
expected
:
nil
,
},
{
desc
:
"single tag should be returned when service has set one annotations"
,
service
:
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
ServiceAnnotationAllowedServiceTag
:
"tag1"
,
},
},
},
expected
:
[]
string
{
"tag1"
},
},
{
desc
:
"multiple tags should be returned when service has set multi-annotations"
,
service
:
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
ServiceAnnotationAllowedServiceTag
:
"tag1, tag2"
,
},
},
},
expected
:
[]
string
{
"tag1"
,
"tag2"
},
},
{
desc
:
"correct tags should be returned when comma or spaces are included in the annotations"
,
service
:
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
ServiceAnnotationAllowedServiceTag
:
", tag1, "
,
},
},
},
expected
:
[]
string
{
"tag1"
},
},
}
for
i
,
c
:=
range
tests
{
tags
:=
getServiceTags
(
c
.
service
)
assert
.
Equal
(
t
,
tags
,
c
.
expected
,
"TestCase[%d]: %s"
,
i
,
c
.
desc
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment