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
d230b246
Commit
d230b246
authored
Oct 20, 2018
by
Ed Bartosh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: check required number of CPUs on master
Implemented preflight check to ensure that number of CPUs on the master node is not less than required.
parent
2dc9acc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
+44
-0
constants.go
cmd/kubeadm/app/constants/constants.go
+3
-0
checks.go
cmd/kubeadm/app/preflight/checks.go
+20
-0
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+21
-0
No files found.
cmd/kubeadm/app/constants/constants.go
View file @
d230b246
...
@@ -323,6 +323,9 @@ const (
...
@@ -323,6 +323,9 @@ const (
// DefaultAPIServerBindAddress is the default bind address for the API Server
// DefaultAPIServerBindAddress is the default bind address for the API Server
DefaultAPIServerBindAddress
=
"0.0.0.0"
DefaultAPIServerBindAddress
=
"0.0.0.0"
// MasterNumCPU is the number of CPUs required on master
MasterNumCPU
=
2
)
)
var
(
var
(
...
...
cmd/kubeadm/app/preflight/checks.go
View file @
d230b246
...
@@ -845,6 +845,25 @@ func (ipc ImagePullCheck) Check() (warnings, errors []error) {
...
@@ -845,6 +845,25 @@ func (ipc ImagePullCheck) Check() (warnings, errors []error) {
return
warnings
,
errors
return
warnings
,
errors
}
}
// NumCPUCheck checks if current number of CPUs is not less than required
type
NumCPUCheck
struct
{
NumCPU
int
}
// Name returns the label for NumCPUCheck
func
(
NumCPUCheck
)
Name
()
string
{
return
"NumCPU"
}
// Check number of CPUs required by kubeadm
func
(
ncc
NumCPUCheck
)
Check
()
(
warnings
,
errors
[]
error
)
{
numCPU
:=
runtime
.
NumCPU
()
if
numCPU
<
ncc
.
NumCPU
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"the number of available CPUs %d is less than the required %d"
,
numCPU
,
ncc
.
NumCPU
))
}
return
warnings
,
errors
}
// RunInitMasterChecks executes all individual, applicable to Master node checks.
// RunInitMasterChecks executes all individual, applicable to Master node checks.
func
RunInitMasterChecks
(
execer
utilsexec
.
Interface
,
cfg
*
kubeadmapi
.
InitConfiguration
,
ignorePreflightErrors
sets
.
String
)
error
{
func
RunInitMasterChecks
(
execer
utilsexec
.
Interface
,
cfg
*
kubeadmapi
.
InitConfiguration
,
ignorePreflightErrors
sets
.
String
)
error
{
// First, check if we're root separately from the other preflight checks and fail fast
// First, check if we're root separately from the other preflight checks and fail fast
...
@@ -854,6 +873,7 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigu
...
@@ -854,6 +873,7 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigu
manifestsDir
:=
filepath
.
Join
(
kubeadmconstants
.
KubernetesDir
,
kubeadmconstants
.
ManifestsSubDirName
)
manifestsDir
:=
filepath
.
Join
(
kubeadmconstants
.
KubernetesDir
,
kubeadmconstants
.
ManifestsSubDirName
)
checks
:=
[]
Checker
{
checks
:=
[]
Checker
{
NumCPUCheck
{
NumCPU
:
kubeadmconstants
.
MasterNumCPU
},
KubernetesVersionCheck
{
KubernetesVersion
:
cfg
.
KubernetesVersion
,
KubeadmVersion
:
kubeadmversion
.
Get
()
.
GitVersion
},
KubernetesVersionCheck
{
KubernetesVersion
:
cfg
.
KubernetesVersion
,
KubeadmVersion
:
kubeadmversion
.
Get
()
.
GitVersion
},
FirewalldCheck
{
ports
:
[]
int
{
int
(
cfg
.
APIEndpoint
.
BindPort
),
10250
}},
FirewalldCheck
{
ports
:
[]
int
{
int
(
cfg
.
APIEndpoint
.
BindPort
),
10250
}},
PortOpenCheck
{
port
:
int
(
cfg
.
APIEndpoint
.
BindPort
)},
PortOpenCheck
{
port
:
int
(
cfg
.
APIEndpoint
.
BindPort
)},
...
...
cmd/kubeadm/app/preflight/checks_test.go
View file @
d230b246
...
@@ -777,3 +777,24 @@ func TestImagePullCheck(t *testing.T) {
...
@@ -777,3 +777,24 @@ func TestImagePullCheck(t *testing.T) {
t
.
Fatalf
(
"expected 2 errors but got %d: %q"
,
len
(
errors
),
errors
)
t
.
Fatalf
(
"expected 2 errors but got %d: %q"
,
len
(
errors
),
errors
)
}
}
}
}
func
TestNumCPUCheck
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
numCPU
int
numErrors
int
numWarnings
int
}{
{
0
,
0
,
0
},
{
999999999
,
1
,
0
},
}
for
_
,
rt
:=
range
tests
{
warnings
,
errors
:=
NumCPUCheck
{
NumCPU
:
rt
.
numCPU
}
.
Check
()
if
len
(
warnings
)
!=
rt
.
numWarnings
{
t
.
Errorf
(
"expected %d warning(s) but got %d: %q"
,
rt
.
numWarnings
,
len
(
warnings
),
warnings
)
}
if
len
(
errors
)
!=
rt
.
numErrors
{
t
.
Errorf
(
"expected %d warning(s) but got %d: %q"
,
rt
.
numErrors
,
len
(
errors
),
errors
)
}
}
}
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