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
2741126c
Commit
2741126c
authored
Jan 08, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3239 from smarterclayton/healthy_registry_should_decorate
HealthyRegistry should only decorate minions, not omit them
parents
3ddde070
a0d71181
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
45 deletions
+54
-45
healthy_registry.go
pkg/registry/minion/healthy_registry.go
+32
-31
healthy_registry_test.go
pkg/registry/minion/healthy_registry_test.go
+10
-6
rest_test.go
pkg/registry/minion/rest_test.go
+6
-6
minion.go
pkg/registry/registrytest/minion.go
+6
-2
No files found.
pkg/registry/minion/healthy_registry.go
View file @
2741126c
...
@@ -22,8 +22,6 @@ import (
...
@@ -22,8 +22,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
)
)
type
HealthyRegistry
struct
{
type
HealthyRegistry
struct
{
...
@@ -41,22 +39,9 @@ func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker) R
...
@@ -41,22 +39,9 @@ func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker) R
func
(
r
*
HealthyRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
func
(
r
*
HealthyRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
minion
,
err
:=
r
.
delegate
.
GetMinion
(
ctx
,
minionID
)
minion
,
err
:=
r
.
delegate
.
GetMinion
(
ctx
,
minionID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
minion
,
err
}
if
minion
==
nil
{
return
nil
,
ErrDoesNotExist
}
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
status
,
err
:=
r
.
client
.
HealthCheck
(
minionID
)
return
r
.
checkMinion
(
minion
),
nil
if
err
!=
nil
{
return
nil
,
err
}
if
status
==
health
.
Unhealthy
{
return
nil
,
ErrNotHealty
}
return
minion
,
nil
}
}
func
(
r
*
HealthyRegistry
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
{
func
(
r
*
HealthyRegistry
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
{
...
@@ -72,26 +57,42 @@ func (r *HealthyRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error
...
@@ -72,26 +57,42 @@ func (r *HealthyRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error
}
}
func
(
r
*
HealthyRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
currentMinions
*
api
.
NodeList
,
err
error
)
{
func
(
r
*
HealthyRegistry
)
ListMinions
(
ctx
api
.
Context
)
(
currentMinions
*
api
.
NodeList
,
err
error
)
{
result
:=
&
api
.
NodeList
{}
list
,
err
:=
r
.
delegate
.
ListMinions
(
ctx
)
list
,
err
:=
r
.
delegate
.
ListMinions
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
result
,
err
return
nil
,
err
}
}
for
_
,
minion
:=
range
list
.
Items
{
for
i
:=
range
list
.
Items
{
status
,
err
:=
r
.
client
.
HealthCheck
(
minion
.
Name
)
list
.
Items
[
i
]
=
*
r
.
checkMinion
(
&
list
.
Items
[
i
])
if
err
!=
nil
{
glog
.
V
(
1
)
.
Infof
(
"%#v failed health check with error: %v"
,
minion
,
err
)
continue
}
if
status
==
health
.
Healthy
{
result
.
Items
=
append
(
result
.
Items
,
minion
)
}
else
{
glog
.
Errorf
(
"%#v failed a health check, ignoring."
,
minion
)
}
}
}
return
resul
t
,
nil
return
lis
t
,
nil
}
}
func
(
r
*
HealthyRegistry
)
WatchMinions
(
ctx
api
.
Context
,
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
HealthyRegistry
)
WatchMinions
(
ctx
api
.
Context
,
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
return
r
.
delegate
.
WatchMinions
(
ctx
,
label
,
field
,
resourceVersion
)
w
,
err
:=
r
.
delegate
.
WatchMinions
(
ctx
,
label
,
field
,
resourceVersion
)
if
err
!=
nil
{
return
nil
,
err
}
return
watch
.
Filter
(
w
,
watch
.
FilterFunc
(
func
(
in
watch
.
Event
)
(
watch
.
Event
,
bool
)
{
if
node
,
ok
:=
in
.
Object
.
(
*
api
.
Node
);
ok
&&
node
!=
nil
{
in
.
Object
=
r
.
checkMinion
(
node
)
}
return
in
,
true
})),
nil
}
func
(
r
*
HealthyRegistry
)
checkMinion
(
node
*
api
.
Node
)
*
api
.
Node
{
condition
:=
api
.
ConditionFull
switch
status
,
err
:=
r
.
client
.
HealthCheck
(
node
.
Name
);
{
case
err
!=
nil
:
condition
=
api
.
ConditionUnknown
case
status
==
health
.
Unhealthy
:
condition
=
api
.
ConditionNone
}
// TODO: distinguish other conditions like Reachable/Live, and begin storing this
// data on nodes directly via sync loops.
node
.
Status
.
Conditions
=
append
(
node
.
Status
.
Conditions
,
api
.
NodeCondition
{
Kind
:
api
.
NodeReady
,
Status
:
condition
,
})
return
node
}
}
pkg/registry/minion/healthy_registry_test.go
View file @
2741126c
...
@@ -86,19 +86,23 @@ func TestFiltering(t *testing.T) {
...
@@ -86,19 +86,23 @@ func TestFiltering(t *testing.T) {
delegate
:
mockMinionRegistry
,
delegate
:
mockMinionRegistry
,
client
:
&
notMinion
{
minion
:
"m1"
},
client
:
&
notMinion
{
minion
:
"m1"
},
}
}
expected
:=
[]
string
{
"m2"
,
"m3"
}
expected
:=
[]
string
{
"m
1"
,
"m
2"
,
"m3"
}
list
,
err
:=
healthy
.
ListMinions
(
ctx
)
list
,
err
:=
healthy
.
ListMinions
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
list
,
registrytest
.
MakeMinionList
(
expected
,
api
.
NodeResources
{}))
{
expectedMinions
:=
registrytest
.
MakeMinionList
(
expected
,
api
.
NodeResources
{})
expectedMinions
.
Items
[
0
]
.
Status
.
Conditions
=
[]
api
.
NodeCondition
{{
Kind
:
api
.
NodeReady
,
Status
:
api
.
ConditionNone
}}
expectedMinions
.
Items
[
1
]
.
Status
.
Conditions
=
[]
api
.
NodeCondition
{{
Kind
:
api
.
NodeReady
,
Status
:
api
.
ConditionFull
}}
expectedMinions
.
Items
[
2
]
.
Status
.
Conditions
=
[]
api
.
NodeCondition
{{
Kind
:
api
.
NodeReady
,
Status
:
api
.
ConditionFull
}}
if
!
reflect
.
DeepEqual
(
list
,
expectedMinions
)
{
t
.
Errorf
(
"Expected %v, Got %v"
,
expected
,
list
)
t
.
Errorf
(
"Expected %v, Got %v"
,
expected
,
list
)
}
}
minion
,
err
:=
healthy
.
GetMinion
(
ctx
,
"m1"
)
minion
,
err
:=
healthy
.
GetMinion
(
ctx
,
"m1"
)
if
err
=
=
nil
{
if
err
!
=
nil
{
t
.
Errorf
(
"unexpected
non-error"
)
t
.
Errorf
(
"unexpected
error: %v"
,
err
)
}
}
if
minion
!
=
nil
{
if
minion
=
=
nil
{
t
.
Errorf
(
"Unexpected
presence of
'm1'"
)
t
.
Errorf
(
"Unexpected
empty
'm1'"
)
}
}
}
}
pkg/registry/minion/rest_test.go
View file @
2741126c
...
@@ -34,8 +34,8 @@ func TestMinionRegistryREST(t *testing.T) {
...
@@ -34,8 +34,8 @@ func TestMinionRegistryREST(t *testing.T) {
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
err
!=
nil
||
obj
.
(
*
api
.
Node
)
.
Name
!=
"bar"
{
if
obj
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
err
!=
nil
||
obj
.
(
*
api
.
Node
)
.
Name
!=
"bar"
{
t
.
Errorf
(
"missing expected object"
)
t
.
Errorf
(
"missing expected object"
)
}
}
if
_
,
err
:=
ms
.
Get
(
ctx
,
"baz"
);
err
!=
ErrDoesNotExist
{
if
_
,
err
:=
ms
.
Get
(
ctx
,
"baz"
);
!
errors
.
IsNotFound
(
err
)
{
t
.
Errorf
(
"has unexpected
object"
)
t
.
Errorf
(
"has unexpected
error: %v"
,
err
)
}
}
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
}})
c
,
err
:=
ms
.
Create
(
ctx
,
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
}})
...
@@ -61,8 +61,8 @@ func TestMinionRegistryREST(t *testing.T) {
...
@@ -61,8 +61,8 @@ func TestMinionRegistryREST(t *testing.T) {
if
s
,
ok
:=
obj
.
Object
.
(
*
api
.
Status
);
!
ok
||
s
.
Status
!=
api
.
StatusSuccess
{
if
s
,
ok
:=
obj
.
Object
.
(
*
api
.
Status
);
!
ok
||
s
.
Status
!=
api
.
StatusSuccess
{
t
.
Errorf
(
"delete return value was weird: %#v"
,
obj
)
t
.
Errorf
(
"delete return value was weird: %#v"
,
obj
)
}
}
if
_
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
err
!=
ErrDoesNotExist
{
if
_
,
err
:=
ms
.
Get
(
ctx
,
"bar"
);
!
errors
.
IsNotFound
(
err
)
{
t
.
Errorf
(
"delete didn't actually delete
"
)
t
.
Errorf
(
"delete didn't actually delete
: %v"
,
err
)
}
}
_
,
err
=
ms
.
Delete
(
ctx
,
"bar"
)
_
,
err
=
ms
.
Delete
(
ctx
,
"bar"
)
...
@@ -105,8 +105,8 @@ func TestMinionRegistryHealthCheck(t *testing.T) {
...
@@ -105,8 +105,8 @@ func TestMinionRegistryHealthCheck(t *testing.T) {
if
m
,
ok
:=
result
.
Object
.
(
*
api
.
Node
);
!
ok
||
m
.
Name
!=
"m1"
{
if
m
,
ok
:=
result
.
Object
.
(
*
api
.
Node
);
!
ok
||
m
.
Name
!=
"m1"
{
t
.
Errorf
(
"insert return value was weird: %#v"
,
result
)
t
.
Errorf
(
"insert return value was weird: %#v"
,
result
)
}
}
if
_
,
err
:=
ms
.
Get
(
ctx
,
"m1"
);
err
=
=
nil
{
if
_
,
err
:=
ms
.
Get
(
ctx
,
"m1"
);
err
!
=
nil
{
t
.
Errorf
(
"node is unhealthy, expect no
result from apiserver"
)
t
.
Errorf
(
"node is unhealthy, expect no
error: %v"
,
err
)
}
}
}
}
...
...
pkg/registry/registrytest/minion.go
View file @
2741126c
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"sync"
"sync"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
...
@@ -80,12 +81,15 @@ func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error {
...
@@ -80,12 +81,15 @@ func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error {
func
(
r
*
MinionRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
func
(
r
*
MinionRegistry
)
GetMinion
(
ctx
api
.
Context
,
minionID
string
)
(
*
api
.
Node
,
error
)
{
r
.
Lock
()
r
.
Lock
()
defer
r
.
Unlock
()
defer
r
.
Unlock
()
if
r
.
Err
!=
nil
{
return
nil
,
r
.
Err
}
for
_
,
node
:=
range
r
.
Minions
.
Items
{
for
_
,
node
:=
range
r
.
Minions
.
Items
{
if
node
.
Name
==
minionID
{
if
node
.
Name
==
minionID
{
return
&
node
,
r
.
Err
return
&
node
,
nil
}
}
}
}
return
nil
,
r
.
Err
return
nil
,
errors
.
NewNotFound
(
"node"
,
minionID
)
}
}
func
(
r
*
MinionRegistry
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
{
func
(
r
*
MinionRegistry
)
DeleteMinion
(
ctx
api
.
Context
,
minionID
string
)
error
{
...
...
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