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
e089c364
Commit
e089c364
authored
Aug 03, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use nodePortOp for allocating healthCheck nodePort
parent
a4996c99
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
15 deletions
+11
-15
rest.go
pkg/registry/core/service/rest.go
+11
-15
No files found.
pkg/registry/core/service/rest.go
View file @
e089c364
...
...
@@ -124,7 +124,7 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, includ
// Handle ExternalTraiffc related fields during service creation.
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExternalTrafficLocalOnly
)
{
if
apiservice
.
NeedsHealthCheck
(
service
)
{
if
err
:=
rs
.
allocateHealthCheckNodePort
(
service
);
err
!=
nil
{
if
err
:=
rs
.
allocateHealthCheckNodePort
(
service
,
nodePortOp
);
err
!=
nil
{
return
nil
,
errors
.
NewInternalError
(
err
)
}
}
...
...
@@ -244,7 +244,7 @@ func externalTrafficPolicyUpdate(oldService, service *api.Service) {
// healthCheckNodePortUpdate handles HealthCheckNodePort allocation/release
// and adjusts HealthCheckNodePort during service update if needed.
func
(
rs
*
REST
)
healthCheckNodePortUpdate
(
oldService
,
service
*
api
.
Service
)
(
bool
,
error
)
{
func
(
rs
*
REST
)
healthCheckNodePortUpdate
(
oldService
,
service
*
api
.
Service
,
nodePortOp
*
portallocator
.
PortAllocationOperation
)
(
bool
,
error
)
{
neededHealthCheckNodePort
:=
apiservice
.
NeedsHealthCheck
(
oldService
)
oldHealthCheckNodePort
:=
oldService
.
Spec
.
HealthCheckNodePort
...
...
@@ -257,7 +257,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
// Insert health check node port into the service's HealthCheckNodePort field if needed.
case
!
neededHealthCheckNodePort
&&
needsHealthCheckNodePort
:
glog
.
Infof
(
"Transition to LoadBalancer type service with ExternalTrafficPolicy=Local"
)
if
err
:=
rs
.
allocateHealthCheckNodePort
(
service
);
err
!=
nil
{
if
err
:=
rs
.
allocateHealthCheckNodePort
(
service
,
nodePortOp
);
err
!=
nil
{
return
false
,
errors
.
NewInternalError
(
err
)
}
...
...
@@ -265,12 +265,8 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
// Free the existing healthCheckNodePort and clear the HealthCheckNodePort field.
case
neededHealthCheckNodePort
&&
!
needsHealthCheckNodePort
:
glog
.
Infof
(
"Transition to non LoadBalancer type service or LoadBalancer type service with ExternalTrafficPolicy=Global"
)
err
:=
rs
.
serviceNodePorts
.
Release
(
int
(
oldHealthCheckNodePort
))
if
err
!=
nil
{
glog
.
Warningf
(
"error releasing service health check %s node port %d: %v"
,
service
.
Name
,
oldHealthCheckNodePort
,
err
)
return
false
,
errors
.
NewInternalError
(
fmt
.
Errorf
(
"failed to free health check nodePort: %v"
,
err
))
}
glog
.
Infof
(
"Freed health check nodePort: %d"
,
oldHealthCheckNodePort
)
glog
.
V
(
4
)
.
Infof
(
"Releasing healthCheckNodePort: %d"
,
oldHealthCheckNodePort
)
nodePortOp
.
ReleaseDeferred
(
int
(
oldHealthCheckNodePort
))
// Clear the HealthCheckNodePort field.
service
.
Spec
.
HealthCheckNodePort
=
0
...
...
@@ -354,7 +350,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.
// Handle ExternalTraiffc related updates.
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExternalTrafficLocalOnly
)
{
success
,
err
:=
rs
.
healthCheckNodePortUpdate
(
oldService
,
service
)
success
,
err
:=
rs
.
healthCheckNodePortUpdate
(
oldService
,
service
,
nodePortOp
)
if
!
success
||
err
!=
nil
{
return
nil
,
false
,
err
}
...
...
@@ -474,24 +470,24 @@ func findRequestedNodePort(port int, servicePorts []api.ServicePort) int {
}
// allocateHealthCheckNodePort allocates health check node port to service.
func
(
rs
*
REST
)
allocateHealthCheckNodePort
(
service
*
api
.
Service
)
error
{
func
(
rs
*
REST
)
allocateHealthCheckNodePort
(
service
*
api
.
Service
,
nodePortOp
*
portallocator
.
PortAllocationOperation
)
error
{
healthCheckNodePort
:=
service
.
Spec
.
HealthCheckNodePort
if
healthCheckNodePort
!=
0
{
// If the request has a health check nodePort in mind, attempt to reserve it.
err
:=
rs
.
serviceNodePorts
.
Allocate
(
int
(
healthCheckNodePort
))
err
:=
nodePortOp
.
Allocate
(
int
(
healthCheckNodePort
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to allocate requested HealthCheck NodePort %v: %v"
,
healthCheckNodePort
,
err
)
}
glog
.
Infof
(
"Reserved user requested n
odePort: %d"
,
healthCheckNodePort
)
glog
.
V
(
4
)
.
Infof
(
"Reserved user requested healthCheckN
odePort: %d"
,
healthCheckNodePort
)
}
else
{
// If the request has no health check nodePort specified, allocate any.
healthCheckNodePort
,
err
:=
rs
.
serviceNodePorts
.
AllocateNext
()
healthCheckNodePort
,
err
:=
nodePortOp
.
AllocateNext
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to allocate a HealthCheck NodePort %v: %v"
,
healthCheckNodePort
,
err
)
}
service
.
Spec
.
HealthCheckNodePort
=
int32
(
healthCheckNodePort
)
glog
.
Infof
(
"Reserved allocated n
odePort: %d"
,
healthCheckNodePort
)
glog
.
V
(
4
)
.
Infof
(
"Reserved allocated healthCheckN
odePort: %d"
,
healthCheckNodePort
)
}
return
nil
}
...
...
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