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
5a64c049
Unverified
Commit
5a64c049
authored
Oct 28, 2017
by
Andrew Rynhard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow extra volumes to be defined
parent
6daba6a2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
17 deletions
+140
-17
types.go
cmd/kubeadm/app/apis/kubeadm/types.go
+12
-0
types.go
cmd/kubeadm/app/apis/kubeadm/v1alpha1/types.go
+12
-0
manifests.go
cmd/kubeadm/app/phases/controlplane/manifests.go
+3
-3
volumes.go
cmd/kubeadm/app/phases/controlplane/volumes.go
+55
-10
volumes_test.go
cmd/kubeadm/app/phases/controlplane/volumes_test.go
+0
-0
local.go
cmd/kubeadm/app/phases/etcd/local.go
+4
-1
utils.go
cmd/kubeadm/app/util/staticpod/utils.go
+24
-2
utils_test.go
cmd/kubeadm/app/util/staticpod/utils_test.go
+30
-1
No files found.
cmd/kubeadm/app/apis/kubeadm/types.go
View file @
5a64c049
...
...
@@ -42,6 +42,10 @@ type MasterConfiguration struct {
ControllerManagerExtraArgs
map
[
string
]
string
SchedulerExtraArgs
map
[
string
]
string
APIServerExtraVolumes
[]
HostPathMount
ControllerManagerExtraVolumes
[]
HostPathMount
SchedulerExtraVolumes
[]
HostPathMount
// APIServerCertSANs sets extra Subject Alternative Names for the API Server signing cert
APIServerCertSANs
[]
string
// CertificatesDir specifies where to store or look for all required certificates
...
...
@@ -137,3 +141,11 @@ func (cfg *MasterConfiguration) GetControlPlaneImageRepository() string {
}
return
cfg
.
ImageRepository
}
// HostPathMount contains elements describing volumes that are mounted from the
// host
type
HostPathMount
struct
{
Name
string
HostPath
string
MountPath
string
}
cmd/kubeadm/app/apis/kubeadm/v1alpha1/types.go
View file @
5a64c049
...
...
@@ -42,6 +42,10 @@ type MasterConfiguration struct {
ControllerManagerExtraArgs
map
[
string
]
string
`json:"controllerManagerExtraArgs,omitempty"`
SchedulerExtraArgs
map
[
string
]
string
`json:"schedulerExtraArgs,omitempty"`
APIServerExtraVolumes
[]
HostPathMount
`json:"apiServerExtraVolumes,omitempty"`
ControllerManagerExtraVolumes
[]
HostPathMount
`json:"controllerManagerExtraVolumes,omitempty"`
SchedulerExtraVolumes
[]
HostPathMount
`json:"schedulerExtraVolumes,omitempty"`
// APIServerCertSANs sets extra Subject Alternative Names for the API Server signing cert
APIServerCertSANs
[]
string
`json:"apiServerCertSANs,omitempty"`
// CertificatesDir specifies where to store or look for all required certificates
...
...
@@ -119,3 +123,11 @@ type NodeConfiguration struct {
// the security of kubeadm since other nodes can impersonate the master.
DiscoveryTokenUnsafeSkipCAVerification
bool
`json:"discoveryTokenUnsafeSkipCAVerification"`
}
// HostPathMount contains elements describing volumes that are mounted from the
// host
type
HostPathMount
struct
{
Name
string
`json:"name"`
HostPath
string
`json:"hostPath"`
MountPath
string
`json:"mountPath"`
}
cmd/kubeadm/app/phases/controlplane/manifests.go
View file @
5a64c049
...
...
@@ -77,7 +77,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.MasterConfiguration, k8sVersion *version.
Name
:
kubeadmconstants
.
KubeAPIServer
,
Image
:
images
.
GetCoreImage
(
kubeadmconstants
.
KubeAPIServer
,
cfg
.
GetControlPlaneImageRepository
(),
cfg
.
KubernetesVersion
,
cfg
.
UnifiedControlPlaneImage
),
Command
:
getAPIServerCommand
(
cfg
,
k8sVersion
),
VolumeMounts
:
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeAPIServer
),
VolumeMounts
:
staticpodutil
.
VolumeMountMapToSlice
(
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeAPIServer
)
),
LivenessProbe
:
staticpodutil
.
ComponentProbe
(
int
(
cfg
.
API
.
BindPort
),
"/healthz"
,
v1
.
URISchemeHTTPS
),
Resources
:
staticpodutil
.
ComponentResources
(
"250m"
),
Env
:
getProxyEnvVars
(),
...
...
@@ -86,7 +86,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.MasterConfiguration, k8sVersion *version.
Name
:
kubeadmconstants
.
KubeControllerManager
,
Image
:
images
.
GetCoreImage
(
kubeadmconstants
.
KubeControllerManager
,
cfg
.
GetControlPlaneImageRepository
(),
cfg
.
KubernetesVersion
,
cfg
.
UnifiedControlPlaneImage
),
Command
:
getControllerManagerCommand
(
cfg
,
k8sVersion
),
VolumeMounts
:
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeControllerManager
),
VolumeMounts
:
staticpodutil
.
VolumeMountMapToSlice
(
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeControllerManager
)
),
LivenessProbe
:
staticpodutil
.
ComponentProbe
(
10252
,
"/healthz"
,
v1
.
URISchemeHTTP
),
Resources
:
staticpodutil
.
ComponentResources
(
"200m"
),
Env
:
getProxyEnvVars
(),
...
...
@@ -95,7 +95,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.MasterConfiguration, k8sVersion *version.
Name
:
kubeadmconstants
.
KubeScheduler
,
Image
:
images
.
GetCoreImage
(
kubeadmconstants
.
KubeScheduler
,
cfg
.
GetControlPlaneImageRepository
(),
cfg
.
KubernetesVersion
,
cfg
.
UnifiedControlPlaneImage
),
Command
:
getSchedulerCommand
(
cfg
),
VolumeMounts
:
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeScheduler
),
VolumeMounts
:
staticpodutil
.
VolumeMountMapToSlice
(
mounts
.
GetVolumeMounts
(
kubeadmconstants
.
KubeScheduler
)
),
LivenessProbe
:
staticpodutil
.
ComponentProbe
(
10251
,
"/healthz"
,
v1
.
URISchemeHTTP
),
Resources
:
staticpodutil
.
ComponentResources
(
"100m"
),
Env
:
getProxyEnvVars
(),
...
...
cmd/kubeadm/app/phases/controlplane/volumes.go
View file @
5a64c049
...
...
@@ -86,40 +86,85 @@ func getHostPathVolumesForTheControlPlane(cfg *kubeadmapi.MasterConfiguration) c
mounts
.
NewHostPathMount
(
kubeadmconstants
.
KubeControllerManager
,
caCertsPkiVolumeName
,
caCertsPkiVolumePath
,
caCertsPkiVolumePath
,
true
,
&
hostPathDirectoryOrCreate
)
}
// Merge user defined mounts and ensure unique volume and volume mount
// names
mounts
.
AddExtraHostPathMounts
(
kubeadmconstants
.
KubeAPIServer
,
cfg
.
APIServerExtraVolumes
,
true
,
&
hostPathDirectoryOrCreate
)
mounts
.
AddExtraHostPathMounts
(
kubeadmconstants
.
KubeControllerManager
,
cfg
.
ControllerManagerExtraVolumes
,
true
,
&
hostPathDirectoryOrCreate
)
mounts
.
AddExtraHostPathMounts
(
kubeadmconstants
.
KubeScheduler
,
cfg
.
SchedulerExtraVolumes
,
true
,
&
hostPathDirectoryOrCreate
)
return
mounts
}
// controlPlaneHostPathMounts is a helper struct for handling all the control plane's hostPath mounts in an easy way
type
controlPlaneHostPathMounts
struct
{
volumes
map
[
string
][]
v1
.
Volume
volumeMounts
map
[
string
][]
v1
.
VolumeMount
// volumes is a nested map that forces a unique volumes. The outer map's
// keys are a string that should specify the target component to add the
// volume to. The values (inner map) of the outer map are maps with string
// keys and v1.Volume values. The inner map's key should specify the volume
// name.
volumes
map
[
string
]
map
[
string
]
v1
.
Volume
// volumeMounts is a nested map that forces a unique volume mounts. The
// outer map's keys are a string that should specify the target component
// to add the volume mount to. The values (inner map) of the outer map are
// maps with string keys and v1.VolumeMount values. The inner map's key
// should specify the volume mount name.
volumeMounts
map
[
string
]
map
[
string
]
v1
.
VolumeMount
}
func
newControlPlaneHostPathMounts
()
controlPlaneHostPathMounts
{
return
controlPlaneHostPathMounts
{
volumes
:
map
[
string
]
[
]
v1
.
Volume
{},
volumeMounts
:
map
[
string
]
[
]
v1
.
VolumeMount
{},
volumes
:
map
[
string
]
map
[
string
]
v1
.
Volume
{},
volumeMounts
:
map
[
string
]
map
[
string
]
v1
.
VolumeMount
{},
}
}
func
(
c
*
controlPlaneHostPathMounts
)
NewHostPathMount
(
component
,
mountName
,
hostPath
,
containerPath
string
,
readOnly
bool
,
hostPathType
*
v1
.
HostPathType
)
{
c
.
volumes
[
component
]
=
append
(
c
.
volumes
[
component
],
staticpodutil
.
NewVolume
(
mountName
,
hostPath
,
hostPathType
))
c
.
volumeMounts
[
component
]
=
append
(
c
.
volumeMounts
[
component
],
staticpodutil
.
NewVolumeMount
(
mountName
,
containerPath
,
readOnly
))
vol
:=
staticpodutil
.
NewVolume
(
mountName
,
hostPath
,
hostPathType
)
c
.
addComponentVolume
(
component
,
vol
)
volMount
:=
staticpodutil
.
NewVolumeMount
(
mountName
,
containerPath
,
readOnly
)
c
.
addComponentVolumeMount
(
component
,
volMount
)
}
func
(
c
*
controlPlaneHostPathMounts
)
AddHostPathMounts
(
component
string
,
vols
[]
v1
.
Volume
,
volMounts
[]
v1
.
VolumeMount
)
{
c
.
volumes
[
component
]
=
append
(
c
.
volumes
[
component
],
vols
...
)
c
.
volumeMounts
[
component
]
=
append
(
c
.
volumeMounts
[
component
],
volMounts
...
)
for
_
,
v
:=
range
vols
{
c
.
addComponentVolume
(
component
,
v
)
}
for
_
,
v
:=
range
volMounts
{
c
.
addComponentVolumeMount
(
component
,
v
)
}
}
// AddExtraHostPathMounts adds host path mounts and overwrites the default
// paths in the case that a user specifies the same volume/volume mount name.
func
(
c
*
controlPlaneHostPathMounts
)
AddExtraHostPathMounts
(
component
string
,
extraVols
[]
kubeadmapi
.
HostPathMount
,
readOnly
bool
,
hostPathType
*
v1
.
HostPathType
)
{
for
_
,
extraVol
:=
range
extraVols
{
fmt
.
Printf
(
"[controlplane] Adding extra host path mount %q to %q
\n
"
,
extraVol
.
Name
,
component
)
c
.
NewHostPathMount
(
component
,
extraVol
.
Name
,
extraVol
.
HostPath
,
extraVol
.
MountPath
,
readOnly
,
hostPathType
)
}
}
func
(
c
*
controlPlaneHostPathMounts
)
GetVolumes
(
component
string
)
[
]
v1
.
Volume
{
func
(
c
*
controlPlaneHostPathMounts
)
GetVolumes
(
component
string
)
map
[
string
]
v1
.
Volume
{
return
c
.
volumes
[
component
]
}
func
(
c
*
controlPlaneHostPathMounts
)
GetVolumeMounts
(
component
string
)
[
]
v1
.
VolumeMount
{
func
(
c
*
controlPlaneHostPathMounts
)
GetVolumeMounts
(
component
string
)
map
[
string
]
v1
.
VolumeMount
{
return
c
.
volumeMounts
[
component
]
}
func
(
c
*
controlPlaneHostPathMounts
)
addComponentVolume
(
component
string
,
vol
v1
.
Volume
)
{
if
_
,
ok
:=
c
.
volumes
[
component
];
!
ok
{
c
.
volumes
[
component
]
=
map
[
string
]
v1
.
Volume
{}
}
c
.
volumes
[
component
][
vol
.
Name
]
=
vol
}
func
(
c
*
controlPlaneHostPathMounts
)
addComponentVolumeMount
(
component
string
,
volMount
v1
.
VolumeMount
)
{
if
_
,
ok
:=
c
.
volumeMounts
[
component
];
!
ok
{
c
.
volumeMounts
[
component
]
=
map
[
string
]
v1
.
VolumeMount
{}
}
c
.
volumeMounts
[
component
][
volMount
.
Name
]
=
volMount
}
// getEtcdCertVolumes returns the volumes/volumemounts needed for talking to an external etcd cluster
func
getEtcdCertVolumes
(
etcdCfg
kubeadmapi
.
Etcd
)
([]
v1
.
Volume
,
[]
v1
.
VolumeMount
)
{
certPaths
:=
[]
string
{
etcdCfg
.
CAFile
,
etcdCfg
.
CertFile
,
etcdCfg
.
KeyFile
}
...
...
cmd/kubeadm/app/phases/controlplane/volumes_test.go
View file @
5a64c049
This diff is collapsed.
Click to expand it.
cmd/kubeadm/app/phases/etcd/local.go
View file @
5a64c049
...
...
@@ -50,6 +50,9 @@ func CreateLocalEtcdStaticPodManifestFile(manifestDir string, cfg *kubeadmapi.Ma
// NB. GetEtcdPodSpec methods holds the information about how kubeadm creates etcd static pod mainfests.
func
GetEtcdPodSpec
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
v1
.
Pod
{
pathType
:=
v1
.
HostPathDirectoryOrCreate
etcdMounts
:=
map
[
string
]
v1
.
Volume
{
etcdVolumeName
:
staticpodutil
.
NewVolume
(
etcdVolumeName
,
cfg
.
Etcd
.
DataDir
,
&
pathType
),
}
return
staticpodutil
.
ComponentPod
(
v1
.
Container
{
Name
:
kubeadmconstants
.
Etcd
,
Command
:
getEtcdCommand
(
cfg
),
...
...
@@ -57,7 +60,7 @@ func GetEtcdPodSpec(cfg *kubeadmapi.MasterConfiguration) v1.Pod {
// Mount the etcd datadir path read-write so etcd can store data in a more persistent manner
VolumeMounts
:
[]
v1
.
VolumeMount
{
staticpodutil
.
NewVolumeMount
(
etcdVolumeName
,
cfg
.
Etcd
.
DataDir
,
false
)},
LivenessProbe
:
staticpodutil
.
ComponentProbe
(
2379
,
"/health"
,
v1
.
URISchemeHTTP
),
},
[]
v1
.
Volume
{
staticpodutil
.
NewVolume
(
etcdVolumeName
,
cfg
.
Etcd
.
DataDir
,
&
pathType
)}
)
},
etcdMounts
)
}
// getEtcdCommand builds the right etcd command from the given config object
...
...
cmd/kubeadm/app/util/staticpod/utils.go
View file @
5a64c049
...
...
@@ -31,7 +31,7 @@ import (
)
// ComponentPod returns a Pod object from the container and volume specifications
func
ComponentPod
(
container
v1
.
Container
,
volumes
[
]
v1
.
Volume
)
v1
.
Pod
{
func
ComponentPod
(
container
v1
.
Container
,
volumes
map
[
string
]
v1
.
Volume
)
v1
.
Pod
{
return
v1
.
Pod
{
TypeMeta
:
metav1
.
TypeMeta
{
APIVersion
:
"v1"
,
...
...
@@ -48,7 +48,7 @@ func ComponentPod(container v1.Container, volumes []v1.Volume) v1.Pod {
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
container
},
HostNetwork
:
true
,
Volumes
:
volumes
,
Volumes
:
VolumeMapToSlice
(
volumes
)
,
},
}
}
...
...
@@ -102,6 +102,28 @@ func NewVolumeMount(name, path string, readOnly bool) v1.VolumeMount {
}
}
// VolumeMapToSlice returns a slice of volumes from a map's values
func
VolumeMapToSlice
(
volumes
map
[
string
]
v1
.
Volume
)
[]
v1
.
Volume
{
v
:=
make
([]
v1
.
Volume
,
0
,
len
(
volumes
))
for
_
,
vol
:=
range
volumes
{
v
=
append
(
v
,
vol
)
}
return
v
}
// VolumeMountMapToSlice returns a slice of volumes from a map's values
func
VolumeMountMapToSlice
(
volumeMounts
map
[
string
]
v1
.
VolumeMount
)
[]
v1
.
VolumeMount
{
v
:=
make
([]
v1
.
VolumeMount
,
0
,
len
(
volumeMounts
))
for
_
,
volMount
:=
range
volumeMounts
{
v
=
append
(
v
,
volMount
)
}
return
v
}
// GetExtraParameters builds a list of flag arguments two string-string maps, one with default, base commands and one with overrides
func
GetExtraParameters
(
overrides
map
[
string
]
string
,
defaults
map
[
string
]
string
)
[]
string
{
var
command
[]
string
...
...
cmd/kubeadm/app/util/staticpod/utils_test.go
View file @
5a64c049
...
...
@@ -111,7 +111,7 @@ func TestComponentPod(t *testing.T) {
for
_
,
rt
:=
range
tests
{
c
:=
v1
.
Container
{
Name
:
rt
.
name
}
actual
:=
ComponentPod
(
c
,
[
]
v1
.
Volume
{})
actual
:=
ComponentPod
(
c
,
map
[
string
]
v1
.
Volume
{})
if
!
reflect
.
DeepEqual
(
rt
.
expected
,
actual
)
{
t
.
Errorf
(
"failed componentPod:
\n\t
expected: %v
\n\t
actual: %v"
,
...
...
@@ -198,6 +198,35 @@ func TestNewVolumeMount(t *testing.T) {
}
}
}
func
TestVolumeMapToSlice
(
t
*
testing
.
T
)
{
testVolumes
:=
map
[
string
]
v1
.
Volume
{
"foo"
:
{
Name
:
"foo"
,
},
}
volumeSlice
:=
VolumeMapToSlice
(
testVolumes
)
if
len
(
volumeSlice
)
!=
1
{
t
.
Errorf
(
"Expected slice length of 1, got %d"
,
len
(
volumeSlice
))
}
if
volumeSlice
[
0
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected volume name
\"
foo
\"
, got %s"
,
volumeSlice
[
0
]
.
Name
)
}
}
func
TestVolumeMountMapToSlice
(
t
*
testing
.
T
)
{
testVolumeMounts
:=
map
[
string
]
v1
.
VolumeMount
{
"foo"
:
{
Name
:
"foo"
,
},
}
volumeMountSlice
:=
VolumeMountMapToSlice
(
testVolumeMounts
)
if
len
(
volumeMountSlice
)
!=
1
{
t
.
Errorf
(
"Expected slice length of 1, got %d"
,
len
(
volumeMountSlice
))
}
if
volumeMountSlice
[
0
]
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected volume mount name
\"
foo
\"
, got %s"
,
volumeMountSlice
[
0
]
.
Name
)
}
}
func
TestGetExtraParameters
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
...
...
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