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
faaa485b
Commit
faaa485b
authored
Jun 02, 2018
by
Da K. Ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated helper funcs to use nodename.
parent
8ea1d92d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
33 deletions
+58
-33
BUILD
pkg/controller/daemon/util/BUILD
+3
-1
daemonset_util.go
pkg/controller/daemon/util/daemonset_util.go
+55
-32
daemonset_util_test.go
pkg/controller/daemon/util/daemonset_util_test.go
+0
-0
No files found.
pkg/controller/daemon/util/BUILD
View file @
faaa485b
...
@@ -14,7 +14,6 @@ go_library(
...
@@ -14,7 +14,6 @@ go_library(
"//pkg/api/v1/pod:go_default_library",
"//pkg/api/v1/pod:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/features:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/kubelet/types:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//vendor/k8s.io/api/apps/v1:go_default_library",
"//vendor/k8s.io/api/apps/v1:go_default_library",
...
@@ -45,9 +44,12 @@ go_test(
...
@@ -45,9 +44,12 @@ go_test(
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//pkg/api/testapi:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
],
],
)
)
pkg/controller/daemon/util/daemonset_util.go
View file @
faaa485b
...
@@ -29,7 +29,6 @@ import (
...
@@ -29,7 +29,6 @@ import (
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/features"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
kubelettypes
"k8s.io/kubernetes/pkg/kubelet/types"
kubelettypes
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
)
)
...
@@ -136,19 +135,20 @@ func SplitByAvailablePods(minReadySeconds int32, pods []*v1.Pod) ([]*v1.Pod, []*
...
@@ -136,19 +135,20 @@ func SplitByAvailablePods(minReadySeconds int32, pods []*v1.Pod) ([]*v1.Pod, []*
return
availablePods
,
unavailablePods
return
availablePods
,
unavailablePods
}
}
// ReplaceDaemonSetPodHostnameNodeAffinity replaces the 'kubernetes.io/hostname' NodeAffinity term with
// ReplaceDaemonSetPodNodeNameNodeAffinity replaces the RequiredDuringSchedulingIgnoredDuringExecution
// the given "nodeName" in the "affinity" terms.
// NodeAffinity of the given affinity with a new NodeAffinity that selects the given nodeName.
func
ReplaceDaemonSetPodHostnameNodeAffinity
(
affinity
*
v1
.
Affinity
,
nodename
string
)
*
v1
.
Affinity
{
// Note that this function assumes that no NodeAffinity conflicts with the selected nodeName.
func
ReplaceDaemonSetPodNodeNameNodeAffinity
(
affinity
*
v1
.
Affinity
,
nodename
string
)
*
v1
.
Affinity
{
nodeSelReq
:=
v1
.
NodeSelectorRequirement
{
Key
:
algorithm
.
NodeFieldSelectorKeyNodeName
,
Operator
:
v1
.
NodeSelectorOpIn
,
Values
:
[]
string
{
nodename
},
}
nodeSelector
:=
&
v1
.
NodeSelector
{
nodeSelector
:=
&
v1
.
NodeSelector
{
NodeSelectorTerms
:
[]
v1
.
NodeSelectorTerm
{
NodeSelectorTerms
:
[]
v1
.
NodeSelectorTerm
{
{
{
MatchExpressions
:
[]
v1
.
NodeSelectorRequirement
{
MatchFields
:
[]
v1
.
NodeSelectorRequirement
{
nodeSelReq
},
{
Key
:
kubeletapis
.
LabelHostname
,
Operator
:
v1
.
NodeSelectorOpIn
,
Values
:
[]
string
{
nodename
},
},
},
},
},
},
},
}
}
...
@@ -175,28 +175,12 @@ func ReplaceDaemonSetPodHostnameNodeAffinity(affinity *v1.Affinity, nodename str
...
@@ -175,28 +175,12 @@ func ReplaceDaemonSetPodHostnameNodeAffinity(affinity *v1.Affinity, nodename str
return
affinity
return
affinity
}
}
nodeSelectorTerms
:=
[]
v1
.
NodeSelectorTerm
{}
// Removes hostname node selector, as only the target hostname will take effect.
for
_
,
term
:=
range
nodeAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
.
NodeSelectorTerms
{
exps
:=
[]
v1
.
NodeSelectorRequirement
{}
for
_
,
exp
:=
range
term
.
MatchExpressions
{
if
exp
.
Key
!=
kubeletapis
.
LabelHostname
{
exps
=
append
(
exps
,
exp
)
}
}
if
len
(
exps
)
>
0
{
term
.
MatchExpressions
=
exps
nodeSelectorTerms
=
append
(
nodeSelectorTerms
,
term
)
}
}
// Adds target hostname NodeAffinity term.
nodeSelectorTerms
=
append
(
nodeSelectorTerms
,
nodeSelector
.
NodeSelectorTerms
[
0
])
// Replace node selector with the new one.
// Replace node selector with the new one.
nodeAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
.
NodeSelectorTerms
=
nodeSelectorTerms
nodeAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
.
NodeSelectorTerms
=
[]
v1
.
NodeSelectorTerm
{
{
MatchFields
:
[]
v1
.
NodeSelectorRequirement
{
nodeSelReq
},
},
}
return
affinity
return
affinity
}
}
...
@@ -225,3 +209,42 @@ func AppendNoScheduleTolerationIfNotExist(tolerations []v1.Toleration) []v1.Tole
...
@@ -225,3 +209,42 @@ func AppendNoScheduleTolerationIfNotExist(tolerations []v1.Toleration) []v1.Tole
return
tolerations
return
tolerations
}
}
// GetTargetNodeName get the target node name of DaemonSet pods. If `.spec.NodeName` is not empty (nil),
// return `.spec.NodeName`; otherwise, retrieve node name of pending pods from NodeAffinity. Return error
// if failed to retrieve node name from `.spec.NodeName` and NodeAffinity.
func
GetTargetNodeName
(
pod
*
v1
.
Pod
)
(
string
,
error
)
{
if
len
(
pod
.
Spec
.
NodeName
)
!=
0
{
return
pod
.
Spec
.
NodeName
,
nil
}
// If ScheduleDaemonSetPods was enabled before, retrieve node name of unscheduled pods from NodeAffinity
if
pod
.
Spec
.
Affinity
==
nil
||
pod
.
Spec
.
Affinity
.
NodeAffinity
==
nil
||
pod
.
Spec
.
Affinity
.
NodeAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
==
nil
{
return
""
,
fmt
.
Errorf
(
"no spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution for pod %s/%s"
,
pod
.
Namespace
,
pod
.
Name
)
}
terms
:=
pod
.
Spec
.
Affinity
.
NodeAffinity
.
RequiredDuringSchedulingIgnoredDuringExecution
.
NodeSelectorTerms
if
len
(
terms
)
<
1
{
return
""
,
fmt
.
Errorf
(
"no nodeSelectorTerms in requiredDuringSchedulingIgnoredDuringExecution of pod %s/%s"
,
pod
.
Namespace
,
pod
.
Name
)
}
for
_
,
term
:=
range
terms
{
for
_
,
exp
:=
range
term
.
MatchFields
{
if
exp
.
Key
==
algorithm
.
NodeFieldSelectorKeyNodeName
&&
exp
.
Operator
==
v1
.
NodeSelectorOpIn
{
if
len
(
exp
.
Values
)
!=
1
{
return
""
,
fmt
.
Errorf
(
"the matchFields value of '%s' is not unique for pod %s/%s"
,
algorithm
.
NodeFieldSelectorKeyNodeName
,
pod
.
Namespace
,
pod
.
Name
)
}
return
exp
.
Values
[
0
],
nil
}
}
}
return
""
,
fmt
.
Errorf
(
"no node name found for pod %s/%s"
,
pod
.
Namespace
,
pod
.
Name
)
}
pkg/controller/daemon/util/daemonset_util_test.go
View file @
faaa485b
This diff is collapsed.
Click to expand it.
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