kubeadm: Add writable parameter to *ExtraVolumes init config

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
This commit is contained in:
Rostislav M. Georgiev 2018-02-22 17:48:18 +02:00
parent 891b471064
commit 545cd0559d
6 changed files with 45 additions and 25 deletions

View File

@ -60,6 +60,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
Name: "foo", Name: "foo",
HostPath: "foo", HostPath: "foo",
MountPath: "foo", MountPath: "foo",
Writable: false,
}} }}
obj.Etcd.ExtraArgs = map[string]string{"foo": "foo"} obj.Etcd.ExtraArgs = map[string]string{"foo": "foo"}
obj.Etcd.SelfHosted = &kubeadm.SelfHostedEtcd{ obj.Etcd.SelfHosted = &kubeadm.SelfHostedEtcd{

View File

@ -281,6 +281,8 @@ type HostPathMount struct {
HostPath string HostPath string
// MountPath is the path inside the pod where hostPath will be mounted. // MountPath is the path inside the pod where hostPath will be mounted.
MountPath string MountPath string
// Writable controls write access to the volume
Writable bool
} }
// KubeProxy contains elements describing the proxy configuration. // KubeProxy contains elements describing the proxy configuration.

View File

@ -259,6 +259,8 @@ type HostPathMount struct {
HostPath string `json:"hostPath"` HostPath string `json:"hostPath"`
// MountPath is the path inside the pod where hostPath will be mounted. // MountPath is the path inside the pod where hostPath will be mounted.
MountPath string `json:"mountPath"` MountPath string `json:"mountPath"`
// Writable controls write access to the volume
Writable bool `json:"writable,omitempty"`
} }
// KubeProxy contains elements describing the proxy configuration. // KubeProxy contains elements describing the proxy configuration.

View File

@ -155,6 +155,7 @@ func autoConvert_v1alpha1_HostPathMount_To_kubeadm_HostPathMount(in *HostPathMou
out.Name = in.Name out.Name = in.Name
out.HostPath = in.HostPath out.HostPath = in.HostPath
out.MountPath = in.MountPath out.MountPath = in.MountPath
out.Writable = in.Writable
return nil return nil
} }
@ -167,6 +168,7 @@ func autoConvert_kubeadm_HostPathMount_To_v1alpha1_HostPathMount(in *kubeadm.Hos
out.Name = in.Name out.Name = in.Name
out.HostPath = in.HostPath out.HostPath = in.HostPath
out.MountPath = in.MountPath out.MountPath = in.MountPath
out.Writable = in.Writable
return nil return nil
} }

View File

@ -105,9 +105,9 @@ func getHostPathVolumesForTheControlPlane(cfg *kubeadmapi.MasterConfiguration) c
// Merge user defined mounts and ensure unique volume and volume mount // Merge user defined mounts and ensure unique volume and volume mount
// names // names
mounts.AddExtraHostPathMounts(kubeadmconstants.KubeAPIServer, cfg.APIServerExtraVolumes, true, &hostPathDirectoryOrCreate) mounts.AddExtraHostPathMounts(kubeadmconstants.KubeAPIServer, cfg.APIServerExtraVolumes, &hostPathDirectoryOrCreate)
mounts.AddExtraHostPathMounts(kubeadmconstants.KubeControllerManager, cfg.ControllerManagerExtraVolumes, true, &hostPathDirectoryOrCreate) mounts.AddExtraHostPathMounts(kubeadmconstants.KubeControllerManager, cfg.ControllerManagerExtraVolumes, &hostPathDirectoryOrCreate)
mounts.AddExtraHostPathMounts(kubeadmconstants.KubeScheduler, cfg.SchedulerExtraVolumes, true, &hostPathDirectoryOrCreate) mounts.AddExtraHostPathMounts(kubeadmconstants.KubeScheduler, cfg.SchedulerExtraVolumes, &hostPathDirectoryOrCreate)
return mounts return mounts
} }
@ -153,10 +153,10 @@ func (c *controlPlaneHostPathMounts) AddHostPathMounts(component string, vols []
// AddExtraHostPathMounts adds host path mounts and overwrites the default // AddExtraHostPathMounts adds host path mounts and overwrites the default
// paths in the case that a user specifies the same volume/volume mount name. // 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) { func (c *controlPlaneHostPathMounts) AddExtraHostPathMounts(component string, extraVols []kubeadmapi.HostPathMount, hostPathType *v1.HostPathType) {
for _, extraVol := range extraVols { for _, extraVol := range extraVols {
fmt.Printf("[controlplane] Adding extra host path mount %q to %q\n", extraVol.Name, component) 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) c.NewHostPathMount(component, extraVol.Name, extraVol.HostPath, extraVol.MountPath, !extraVol.Writable, hostPathType)
} }
} }

View File

@ -618,27 +618,40 @@ func TestAddExtraHostPathMounts(t *testing.T) {
Name: "foo", Name: "foo",
HostPath: "/tmp/qux", HostPath: "/tmp/qux",
MountPath: "/tmp/qux", MountPath: "/tmp/qux",
Writable: false,
},
{
Name: "bar",
HostPath: "/tmp/asd",
MountPath: "/tmp/asd",
Writable: true,
}, },
} }
mounts.AddExtraHostPathMounts("component", hostPathMounts, true, &hostPathDirectoryOrCreate) mounts.AddExtraHostPathMounts("component", hostPathMounts, &hostPathDirectoryOrCreate)
if _, ok := mounts.volumes["component"]["foo"]; !ok { for _, hostMount := range hostPathMounts {
t.Errorf("Expected to find volume %q", "foo") volumeName := hostMount.Name
if _, ok := mounts.volumes["component"][volumeName]; !ok {
t.Errorf("Expected to find volume %q", volumeName)
} }
vol, _ := mounts.volumes["component"]["foo"] vol := mounts.volumes["component"][volumeName]
if vol.Name != "foo" { if vol.Name != volumeName {
t.Errorf("Expected volume name %q", "foo") t.Errorf("Expected volume name %q", volumeName)
} }
if vol.HostPath.Path != "/tmp/qux" { if vol.HostPath.Path != hostMount.HostPath {
t.Errorf("Expected host path %q", "/tmp/qux") t.Errorf("Expected host path %q", hostMount.HostPath)
} }
if _, ok := mounts.volumeMounts["component"]["foo"]; !ok { if _, ok := mounts.volumeMounts["component"][volumeName]; !ok {
t.Errorf("Expected to find volume mount %q", "foo") t.Errorf("Expected to find volume mount %q", volumeName)
} }
volMount, _ := mounts.volumeMounts["component"]["foo"] volMount, _ := mounts.volumeMounts["component"][volumeName]
if volMount.Name != "foo" { if volMount.Name != volumeName {
t.Errorf("Expected volume mount name %q", "foo") t.Errorf("Expected volume mount name %q", volumeName)
}
if volMount.MountPath != hostMount.MountPath {
t.Errorf("Expected container path %q", hostMount.MountPath)
}
if volMount.ReadOnly != !hostMount.Writable {
t.Errorf("Expected volume writable setting %t", hostMount.Writable)
} }
if volMount.MountPath != "/tmp/qux" {
t.Errorf("Expected container path %q", "/tmp/qux")
} }
} }