mirror of https://github.com/k3s-io/k3s
Merge pull request #64889 from dims/ensure-directory-is-created-for-kubelet-configuration
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Ensure directory is created for kubelet configuration **What this PR does / why we need it**: Ensure directory is present before writing the config file. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #64887 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/8/head
commit
bedb27e130
|
@ -19,6 +19,7 @@ package kubelet
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
|
@ -161,6 +162,11 @@ func writeConfigBytesToDisk(b []byte, kubeletDir string) error {
|
|||
configFile := filepath.Join(kubeletDir, kubeadmconstants.KubeletConfigurationFileName)
|
||||
fmt.Printf("[kubelet] Writing kubelet configuration to file %q\n", configFile)
|
||||
|
||||
// creates target folder if not already exists
|
||||
if err := os.MkdirAll(kubeletDir, 0700); err != nil {
|
||||
return fmt.Errorf("failed to create directory %q: %v", kubeletDir, err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(configFile, b, 0644); err != nil {
|
||||
return fmt.Errorf("failed to write kubelet configuration to the file %q: %v", configFile, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue