Commit 2c774753 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #44467 from JulienBalestra/fix-rkt-host-path-volume

Automatic merge from submit-queue (batch tested with PRs 44469, 44566, 44467, 44526) Kubelet:rkt Fix the hostPath Volume creation **What this PR does / why we need it**: This PR fix the `hostPath` volume when the path exist and it's not a directory. At the moment, the creation of a `hostPath` volume for an existing file leads to this error: > kubelet[1984]: E0413 07:53:16.480922 1984 pod_workers.go:184] Error syncing pod 38359a57-1fb1-11e7-a484-76870fe7db83, skipping: failed to SyncPod: mkdir /usr/share/coreos/lsb-release: not a directory **Special notes for your reviewer**: You can have a look to the difference with this [gist](https://gist.github.com/JulienBalestra/28ae15efc8a1393d350300880c07ff4f)
parents 08ea5387 edc4ccd6
...@@ -1320,11 +1320,14 @@ func (r *Runtime) setupPodNetwork(pod *v1.Pod) (string, string, error) { ...@@ -1320,11 +1320,14 @@ func (r *Runtime) setupPodNetwork(pod *v1.Pod) (string, string, error) {
func createHostPathVolumes(pod *v1.Pod) (err error) { func createHostPathVolumes(pod *v1.Pod) (err error) {
for _, v := range pod.Spec.Volumes { for _, v := range pod.Spec.Volumes {
if v.VolumeSource.HostPath != nil { if v.VolumeSource.HostPath != nil {
err = os.MkdirAll(v.HostPath.Path, os.ModePerm) _, err = os.Stat(v.HostPath.Path)
if err != nil && !os.IsExist(err) { if os.IsNotExist(err) {
return err if err = os.MkdirAll(v.HostPath.Path, os.ModePerm); err != nil {
glog.Errorf("Create volume HostPath %q for Pod %q failed: %q", v.HostPath.Path, format.Pod(pod), err.Error())
return err
}
glog.V(4).Infof("Created volume HostPath %q for Pod %q", v.HostPath.Path, format.Pod(pod))
} }
glog.V(4).Infof("Created volume HostPath %q for Pod %q", v.HostPath.Path, format.Pod(pod))
} }
} }
return nil return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment