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
163ef4d2
Unverified
Commit
163ef4d2
authored
May 30, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 30, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78463 from prameshj/ilb-annotate
Skip ILB creation on GCE if neg annotation is present
parents
44a3bf47
fea60b87
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
+81
-0
gce_annotations.go
.../src/k8s.io/legacy-cloud-providers/gce/gce_annotations.go
+3
-0
gce_loadbalancer_internal.go
...o/legacy-cloud-providers/gce/gce_loadbalancer_internal.go
+13
-0
gce_loadbalancer_internal_test.go
...acy-cloud-providers/gce/gce_loadbalancer_internal_test.go
+59
-0
gce_loadbalancer_utils_test.go
...legacy-cloud-providers/gce/gce_loadbalancer_utils_test.go
+6
-0
No files found.
staging/src/k8s.io/legacy-cloud-providers/gce/gce_annotations.go
View file @
163ef4d2
...
...
@@ -58,6 +58,9 @@ const (
// NetworkTierAnnotationPremium is an annotation to indicate the Service is on the Premium network tier
NetworkTierAnnotationPremium
=
cloud
.
NetworkTierPremium
// NEGAnnotation is an annotation to indicate that the loadbalancer service is using NEGs instead of InstanceGroups
NEGAnnotation
=
"cloud.google.com/neg"
)
// GetLoadBalancerAnnotationType returns the type of GCP load balancer which should be assembled.
...
...
staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go
View file @
163ef4d2
...
...
@@ -35,7 +35,16 @@ const (
allInstances
=
"ALL"
)
func
usesNEG
(
service
*
v1
.
Service
)
bool
{
_
,
ok
:=
service
.
GetAnnotations
()[
NEGAnnotation
]
return
ok
}
func
(
g
*
Cloud
)
ensureInternalLoadBalancer
(
clusterName
,
clusterID
string
,
svc
*
v1
.
Service
,
existingFwdRule
*
compute
.
ForwardingRule
,
nodes
[]
*
v1
.
Node
)
(
*
v1
.
LoadBalancerStatus
,
error
)
{
if
usesNEG
(
svc
)
{
// Do not manage loadBalancer for services using NEGs
return
&
svc
.
Status
.
LoadBalancer
,
nil
}
nm
:=
types
.
NamespacedName
{
Name
:
svc
.
Name
,
Namespace
:
svc
.
Namespace
}
ports
,
protocol
:=
getPortsAndProtocol
(
svc
.
Spec
.
Ports
)
if
protocol
!=
v1
.
ProtocolTCP
&&
protocol
!=
v1
.
ProtocolUDP
{
...
...
@@ -201,6 +210,10 @@ func (g *Cloud) clearPreviousInternalResources(svc *v1.Service, loadBalancerName
// updateInternalLoadBalancer is called when the list of nodes has changed. Therefore, only the instance groups
// and possibly the backend service need to be updated.
func
(
g
*
Cloud
)
updateInternalLoadBalancer
(
clusterName
,
clusterID
string
,
svc
*
v1
.
Service
,
nodes
[]
*
v1
.
Node
)
error
{
if
usesNEG
(
svc
)
{
// Do not manage loadBalancer for services using NEGs
return
nil
}
g
.
sharedResourceLock
.
Lock
()
defer
g
.
sharedResourceLock
.
Unlock
()
...
...
staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal_test.go
View file @
163ef4d2
...
...
@@ -847,3 +847,62 @@ func TestCompareHealthChecks(t *testing.T) {
})
}
}
func
TestEnsureInternalLoadBalancerNEG
(
t
*
testing
.
T
)
{
t
.
Parallel
()
vals
:=
DefaultTestClusterValues
()
gce
,
err
:=
fakeGCECloud
(
vals
)
require
.
NoError
(
t
,
err
)
nodeNames
:=
[]
string
{
"test-node-1"
}
nodes
,
err
:=
createAndInsertNodes
(
gce
,
nodeNames
,
vals
.
ZoneName
)
require
.
NoError
(
t
,
err
)
apiService
:=
fakeLoadbalancerServiceWithNEGs
(
string
(
LBTypeInternal
))
status
,
err
:=
gce
.
EnsureLoadBalancer
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
,
nodes
)
assert
.
NoError
(
t
,
err
)
// No loadbalancer resources will be created due to the NEG annotation
assert
.
Empty
(
t
,
status
.
Ingress
)
assertInternalLbResourcesDeleted
(
t
,
gce
,
apiService
,
vals
,
true
)
// Invoking delete should be a no-op
err
=
gce
.
EnsureLoadBalancerDeleted
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
)
assert
.
NoError
(
t
,
err
)
// Now remove the annotation so that lb resources are created
delete
(
apiService
.
Annotations
,
NEGAnnotation
)
status
,
err
=
gce
.
EnsureLoadBalancer
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
,
nodes
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEmpty
(
t
,
status
.
Ingress
)
assertInternalLbResources
(
t
,
gce
,
apiService
,
vals
,
nodeNames
)
}
func
TestEnsureInternalLoadBalancerDeletedNEGs
(
t
*
testing
.
T
)
{
t
.
Parallel
()
vals
:=
DefaultTestClusterValues
()
gce
,
err
:=
fakeGCECloud
(
vals
)
require
.
NoError
(
t
,
err
)
nodeNames
:=
[]
string
{
"test-node-1"
}
nodes
,
err
:=
createAndInsertNodes
(
gce
,
nodeNames
,
vals
.
ZoneName
)
require
.
NoError
(
t
,
err
)
apiService
:=
fakeLoadbalancerService
(
string
(
LBTypeInternal
))
status
,
err
:=
gce
.
EnsureLoadBalancer
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
,
nodes
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEmpty
(
t
,
status
.
Ingress
)
// Annotation gets added to service
apiService
.
Annotations
[
NEGAnnotation
]
=
"{
\"
ilb
\"
: true}"
newLBStatus
:=
v1
.
LoadBalancerStatus
{
Ingress
:
[]
v1
.
LoadBalancerIngress
{{
IP
:
"1.2.3.4"
}}}
// mock scenario where a different controller modifies status.
apiService
.
Status
.
LoadBalancer
=
newLBStatus
status
,
err
=
gce
.
EnsureLoadBalancer
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
,
nodes
)
assert
.
NoError
(
t
,
err
)
// ensure that the status info is intact
assert
.
Equal
(
t
,
status
,
&
newLBStatus
)
// Invoked when service is deleted.
err
=
gce
.
EnsureLoadBalancerDeleted
(
context
.
Background
(),
vals
.
ClusterName
,
apiService
)
assert
.
NoError
(
t
,
err
)
assertInternalLbResourcesDeleted
(
t
,
gce
,
apiService
,
vals
,
true
)
}
staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_utils_test.go
View file @
163ef4d2
...
...
@@ -62,6 +62,12 @@ func fakeLoadbalancerService(lbType string) *v1.Service {
}
}
func
fakeLoadbalancerServiceWithNEGs
(
lbType
string
)
*
v1
.
Service
{
svc
:=
fakeLoadbalancerService
(
lbType
)
svc
.
Annotations
[
NEGAnnotation
]
=
"{
\"
ilb
\"
: true}"
return
svc
}
var
(
FilewallChangeMsg
=
fmt
.
Sprintf
(
"%s %s %s"
,
v1
.
EventTypeNormal
,
eventReasonManualChange
,
eventMsgFirewallChange
)
)
...
...
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