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
80156474
Commit
80156474
authored
Jun 06, 2017
by
Henrik Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always check if default labels on node need to be updated in kubelet
parent
7209cb76
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
207 additions
and
3 deletions
+207
-3
BUILD
pkg/kubelet/BUILD
+1
-0
kubelet_node_status.go
pkg/kubelet/kubelet_node_status.go
+28
-0
kubelet_node_status_test.go
pkg/kubelet/kubelet_node_status_test.go
+178
-3
No files found.
pkg/kubelet/BUILD
View file @
80156474
...
...
@@ -170,6 +170,7 @@ go_test(
"//pkg/api:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/capabilities:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/kubelet/apis/kubeletconfig:go_default_library",
"//pkg/kubelet/cadvisor/testing:go_default_library",
"//pkg/kubelet/cm:go_default_library",
...
...
pkg/kubelet/kubelet_node_status.go
View file @
80156474
...
...
@@ -137,6 +137,7 @@ func (kl *Kubelet) tryRegisterWithAPIServer(node *v1.Node) bool {
// the value of the controller-managed attach-detach
// annotation.
requiresUpdate
:=
kl
.
reconcileCMADAnnotationWithExistingNode
(
node
,
existingNode
)
requiresUpdate
=
kl
.
updateDefaultLabels
(
node
,
existingNode
)
||
requiresUpdate
if
requiresUpdate
{
if
_
,
err
:=
nodeutil
.
PatchNodeStatus
(
kl
.
kubeClient
,
types
.
NodeName
(
kl
.
nodeName
),
originalNode
,
existingNode
);
err
!=
nil
{
...
...
@@ -161,6 +162,33 @@ func (kl *Kubelet) tryRegisterWithAPIServer(node *v1.Node) bool {
return
false
}
// updateDefaultLabels will set the default labels on the node
func
(
kl
*
Kubelet
)
updateDefaultLabels
(
initialNode
,
existingNode
*
v1
.
Node
)
bool
{
defaultLabels
:=
[]
string
{
kubeletapis
.
LabelHostname
,
kubeletapis
.
LabelZoneFailureDomain
,
kubeletapis
.
LabelZoneRegion
,
kubeletapis
.
LabelInstanceType
,
kubeletapis
.
LabelOS
,
kubeletapis
.
LabelArch
,
}
var
needsUpdate
bool
=
false
//Set default labels but make sure to not set labels with empty values
for
_
,
label
:=
range
defaultLabels
{
if
existingNode
.
Labels
[
label
]
!=
initialNode
.
Labels
[
label
]
{
existingNode
.
Labels
[
label
]
=
initialNode
.
Labels
[
label
]
needsUpdate
=
true
}
if
existingNode
.
Labels
[
label
]
==
""
{
delete
(
existingNode
.
Labels
,
label
)
}
}
return
needsUpdate
}
// reconcileCMADAnnotationWithExistingNode reconciles the controller-managed
// attach-detach annotation on a new node and the existing node, returning
// whether the existing node must be updated.
...
...
pkg/kubelet/kubelet_node_status_test.go
View file @
80156474
...
...
@@ -43,6 +43,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/fake"
core
"k8s.io/client-go/testing"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/kubelet/cm"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"
...
...
@@ -675,8 +676,15 @@ func TestRegisterWithApiServer(t *testing.T) {
kubeClient
.
AddReactor
(
"get"
,
"nodes"
,
func
(
action
core
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
// Return an existing (matching) node on get.
return
true
,
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testKubeletHostname
},
Spec
:
v1
.
NodeSpec
{
ExternalID
:
testKubeletHostname
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testKubeletHostname
,
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
testKubeletHostname
,
kubeletapis
.
LabelOS
:
goruntime
.
GOOS
,
kubeletapis
.
LabelArch
:
goruntime
.
GOARCH
,
},
},
Spec
:
v1
.
NodeSpec
{
ExternalID
:
testKubeletHostname
},
},
nil
})
kubeClient
.
AddReactor
(
"*"
,
"*"
,
func
(
action
core
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
...
...
@@ -731,7 +739,13 @@ func TestTryRegisterWithApiServer(t *testing.T) {
newNode
:=
func
(
cmad
bool
,
externalID
string
)
*
v1
.
Node
{
node
:=
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{},
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
testKubeletHostname
,
kubeletapis
.
LabelOS
:
goruntime
.
GOOS
,
kubeletapis
.
LabelArch
:
goruntime
.
GOARCH
,
},
},
Spec
:
v1
.
NodeSpec
{
ExternalID
:
externalID
,
},
...
...
@@ -961,3 +975,164 @@ func TestUpdateNewNodeStatusTooLargeReservation(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
True
(
t
,
apiequality
.
Semantic
.
DeepEqual
(
expectedNode
.
Status
.
Allocatable
,
updatedNode
.
Status
.
Allocatable
),
"%s"
,
diff
.
ObjectDiff
(
expectedNode
.
Status
.
Allocatable
,
updatedNode
.
Status
.
Allocatable
))
}
func
TestUpdateDefaultLabels
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
cases
:=
[]
struct
{
name
string
initialNode
*
v1
.
Node
existingNode
*
v1
.
Node
needsUpdate
bool
finalLabels
map
[
string
]
string
}{
{
name
:
"make sure default labels exist"
,
initialNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
},
existingNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{},
},
},
needsUpdate
:
true
,
finalLabels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
{
name
:
"make sure default labels are up to date"
,
initialNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
},
existingNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"old-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"old-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"old-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"old-instance-type"
,
kubeletapis
.
LabelOS
:
"old-os"
,
kubeletapis
.
LabelArch
:
"old-arch"
,
},
},
},
needsUpdate
:
true
,
finalLabels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
{
name
:
"make sure existing labels do not get deleted"
,
initialNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
},
existingNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
"please-persist"
:
"foo"
,
},
},
},
needsUpdate
:
false
,
finalLabels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
"please-persist"
:
"foo"
,
},
},
{
name
:
"no update needed"
,
initialNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
},
existingNode
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
},
needsUpdate
:
false
,
finalLabels
:
map
[
string
]
string
{
kubeletapis
.
LabelHostname
:
"new-hostname"
,
kubeletapis
.
LabelZoneFailureDomain
:
"new-zone-failure-domain"
,
kubeletapis
.
LabelZoneRegion
:
"new-zone-region"
,
kubeletapis
.
LabelInstanceType
:
"new-instance-type"
,
kubeletapis
.
LabelOS
:
"new-os"
,
kubeletapis
.
LabelArch
:
"new-arch"
,
},
},
}
for
_
,
tc
:=
range
cases
{
defer
testKubelet
.
Cleanup
()
kubelet
:=
testKubelet
.
kubelet
needsUpdate
:=
kubelet
.
updateDefaultLabels
(
tc
.
initialNode
,
tc
.
existingNode
)
assert
.
Equal
(
t
,
tc
.
needsUpdate
,
needsUpdate
,
tc
.
name
)
assert
.
Equal
(
t
,
tc
.
finalLabels
,
tc
.
existingNode
.
Labels
,
tc
.
name
)
}
}
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