mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
17
vendor/k8s.io/kubernetes/pkg/util/io/writer.go
generated
vendored
17
vendor/k8s.io/kubernetes/pkg/util/io/writer.go
generated
vendored
@ -50,15 +50,24 @@ func (writer *StdWriter) WriteFile(filename string, data []byte, perm os.FileMod
|
||||
// it will not see the mounted device in its own namespace. To work around this
|
||||
// limitation one has to first enter hosts namespace (by using 'nsenter') and
|
||||
// only then write data.
|
||||
type NsenterWriter struct{}
|
||||
type NsenterWriter struct {
|
||||
ne *nsenter.Nsenter
|
||||
}
|
||||
|
||||
// NewNsenterWriter creates a new Writer that allows writing data to file using
|
||||
// nsenter command.
|
||||
func NewNsenterWriter(ne *nsenter.Nsenter) *NsenterWriter {
|
||||
return &NsenterWriter{
|
||||
ne: ne,
|
||||
}
|
||||
}
|
||||
|
||||
// WriteFile calls 'nsenter cat - > <the file>' and 'nsenter chmod' to create a
|
||||
// file on the host.
|
||||
func (writer *NsenterWriter) WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
ne := nsenter.NewNsenter()
|
||||
echoArgs := []string{"-c", fmt.Sprintf("cat > %s", filename)}
|
||||
glog.V(5).Infof("nsenter: write data to file %s by nsenter", filename)
|
||||
command := ne.Exec("sh", echoArgs)
|
||||
command := writer.ne.Exec("sh", echoArgs)
|
||||
command.SetStdin(bytes.NewBuffer(data))
|
||||
outputBytes, err := command.CombinedOutput()
|
||||
if err != nil {
|
||||
@ -68,7 +77,7 @@ func (writer *NsenterWriter) WriteFile(filename string, data []byte, perm os.Fil
|
||||
|
||||
chmodArgs := []string{fmt.Sprintf("%o", perm), filename}
|
||||
glog.V(5).Infof("nsenter: change permissions of file %s to %s", filename, chmodArgs[0])
|
||||
outputBytes, err = ne.Exec("chmod", chmodArgs).CombinedOutput()
|
||||
outputBytes, err = writer.ne.Exec("chmod", chmodArgs).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.Errorf("Output from chmod command: %v", string(outputBytes))
|
||||
return err
|
||||
|
Reference in New Issue
Block a user