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
36f9bc08
Commit
36f9bc08
authored
Apr 12, 2018
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug for headless services without ports
parent
9816b431
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
endpoints_controller.go
pkg/controller/endpoint/endpoints_controller.go
+11
-7
endpoints_controller_test.go
pkg/controller/endpoint/endpoints_controller_test.go
+1
-1
No files found.
pkg/controller/endpoint/endpoints_controller.go
View file @
36f9bc08
...
...
@@ -454,8 +454,8 @@ func (e *EndpointController) syncService(key string) error {
// Allow headless service not to have ports.
if
len
(
service
.
Spec
.
Ports
)
==
0
{
if
service
.
Spec
.
ClusterIP
==
api
.
ClusterIPNone
{
epp
:=
v1
.
EndpointPort
{
Port
:
0
,
Protocol
:
v1
.
ProtocolTCP
}
subsets
,
totalReadyEps
,
totalNotReadyEps
=
addEndpointSubset
(
subsets
,
pod
,
epa
,
epp
,
tolerateUnreadyEndpoints
)
subsets
,
totalReadyEps
,
totalNotReadyEps
=
addEndpointSubset
(
subsets
,
pod
,
epa
,
nil
,
tolerateUnreadyEndpoints
)
// No need to repack subsets for headless service without ports.
}
}
else
{
for
i
:=
range
service
.
Spec
.
Ports
{
...
...
@@ -470,14 +470,14 @@ func (e *EndpointController) syncService(key string) error {
}
var
readyEps
,
notReadyEps
int
epp
:=
v1
.
EndpointPort
{
Name
:
portName
,
Port
:
int32
(
portNum
),
Protocol
:
portProto
}
epp
:=
&
v1
.
EndpointPort
{
Name
:
portName
,
Port
:
int32
(
portNum
),
Protocol
:
portProto
}
subsets
,
readyEps
,
notReadyEps
=
addEndpointSubset
(
subsets
,
pod
,
epa
,
epp
,
tolerateUnreadyEndpoints
)
totalReadyEps
=
totalReadyEps
+
readyEps
totalNotReadyEps
=
totalNotReadyEps
+
notReadyEps
}
subsets
=
endpoints
.
RepackSubsets
(
subsets
)
}
}
subsets
=
endpoints
.
RepackSubsets
(
subsets
)
// See if there's actually an update here.
currentEndpoints
,
err
:=
e
.
endpointsLister
.
Endpoints
(
service
.
Namespace
)
.
Get
(
service
.
Name
)
...
...
@@ -561,20 +561,24 @@ func (e *EndpointController) checkLeftoverEndpoints() {
}
func
addEndpointSubset
(
subsets
[]
v1
.
EndpointSubset
,
pod
*
v1
.
Pod
,
epa
v1
.
EndpointAddress
,
epp
v1
.
EndpointPort
,
tolerateUnreadyEndpoints
bool
)
([]
v1
.
EndpointSubset
,
int
,
int
)
{
epp
*
v1
.
EndpointPort
,
tolerateUnreadyEndpoints
bool
)
([]
v1
.
EndpointSubset
,
int
,
int
)
{
var
readyEps
int
=
0
var
notReadyEps
int
=
0
ports
:=
[]
v1
.
EndpointPort
{}
if
epp
!=
nil
{
ports
=
append
(
ports
,
*
epp
)
}
if
tolerateUnreadyEndpoints
||
podutil
.
IsPodReady
(
pod
)
{
subsets
=
append
(
subsets
,
v1
.
EndpointSubset
{
Addresses
:
[]
v1
.
EndpointAddress
{
epa
},
Ports
:
[]
v1
.
EndpointPort
{
epp
}
,
Ports
:
ports
,
})
readyEps
++
}
else
if
shouldPodBeInEndpoints
(
pod
)
{
glog
.
V
(
5
)
.
Infof
(
"Pod is out of service: %s/%s"
,
pod
.
Namespace
,
pod
.
Name
)
subsets
=
append
(
subsets
,
v1
.
EndpointSubset
{
NotReadyAddresses
:
[]
v1
.
EndpointAddress
{
epa
},
Ports
:
[]
v1
.
EndpointPort
{
epp
}
,
Ports
:
ports
,
})
notReadyEps
++
}
...
...
pkg/controller/endpoint/endpoints_controller_test.go
View file @
36f9bc08
...
...
@@ -753,7 +753,7 @@ func TestSyncEndpointsHeadlessService(t *testing.T) {
},
Subsets
:
[]
v1
.
EndpointSubset
{{
Addresses
:
[]
v1
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
NodeName
:
&
emptyNodeName
,
TargetRef
:
&
v1
.
ObjectReference
{
Kind
:
"Pod"
,
Name
:
"pod0"
,
Namespace
:
ns
}}},
Ports
:
[]
v1
.
EndpointPort
{
{
Port
:
0
,
Protocol
:
"TCP"
}
},
Ports
:
[]
v1
.
EndpointPort
{},
}},
})
endpointsHandler
.
ValidateRequestCount
(
t
,
1
)
...
...
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