Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
50
vendor/sigs.k8s.io/kustomize/kyaml/kio/pkgio_writer.go
generated
vendored
50
vendor/sigs.k8s.io/kustomize/kyaml/kio/pkgio_writer.go
generated
vendored
@@ -4,12 +4,14 @@
|
||||
package kio
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
@@ -26,6 +28,9 @@ type LocalPackageWriter struct {
|
||||
|
||||
// ClearAnnotations will clear annotations before writing the resources
|
||||
ClearAnnotations []string `yaml:"clearAnnotations,omitempty"`
|
||||
|
||||
// FileSystem can be used to mock the disk file system.
|
||||
FileSystem filesys.FileSystemOrOnDisk
|
||||
}
|
||||
|
||||
var _ Writer = LocalPackageWriter{}
|
||||
@@ -36,9 +41,10 @@ func (r LocalPackageWriter) Write(nodes []*yaml.RNode) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if s, err := os.Stat(r.PackagePath); err != nil {
|
||||
return err
|
||||
} else if !s.IsDir() {
|
||||
if !r.FileSystem.Exists(r.PackagePath) {
|
||||
return errors.WrapPrefixf(os.ErrNotExist, "could not write to %q", r.PackagePath)
|
||||
}
|
||||
if !r.FileSystem.IsDir(r.PackagePath) {
|
||||
// if the user specified input isn't a directory, the package is the directory of the
|
||||
// target
|
||||
r.PackagePath = filepath.Dir(r.PackagePath)
|
||||
@@ -60,50 +66,42 @@ func (r LocalPackageWriter) Write(nodes []*yaml.RNode) error {
|
||||
|
||||
if !r.KeepReaderAnnotations {
|
||||
r.ClearAnnotations = append(r.ClearAnnotations, kioutil.PathAnnotation)
|
||||
r.ClearAnnotations = append(r.ClearAnnotations, kioutil.LegacyPathAnnotation)
|
||||
}
|
||||
|
||||
// validate outputs before writing any
|
||||
for path := range outputFiles {
|
||||
outputPath := filepath.Join(r.PackagePath, path)
|
||||
if st, err := os.Stat(outputPath); !os.IsNotExist(err) {
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
if st.IsDir() {
|
||||
return fmt.Errorf("config.kubernetes.io/path cannot be a directory: %s", path)
|
||||
}
|
||||
if r.FileSystem.IsDir(outputPath) {
|
||||
return fmt.Errorf("config.kubernetes.io/path cannot be a directory: %s", path)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(outputPath), 0700)
|
||||
err = r.FileSystem.MkdirAll(filepath.Dir(outputPath))
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
// write files
|
||||
buf := bytes.NewBuffer(nil)
|
||||
for path := range outputFiles {
|
||||
outputPath := filepath.Join(r.PackagePath, path)
|
||||
err = os.MkdirAll(filepath.Dir(filepath.Join(r.PackagePath, path)), 0700)
|
||||
err = r.FileSystem.MkdirAll(filepath.Dir(filepath.Join(r.PackagePath, path)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(0600))
|
||||
if err != nil {
|
||||
buf.Reset()
|
||||
w := ByteWriter{
|
||||
Writer: buf,
|
||||
KeepReaderAnnotations: r.KeepReaderAnnotations,
|
||||
ClearAnnotations: r.ClearAnnotations,
|
||||
}
|
||||
if err = w.Write(outputFiles[path]); err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
if err := func() error {
|
||||
defer f.Close()
|
||||
w := ByteWriter{
|
||||
Writer: f,
|
||||
KeepReaderAnnotations: r.KeepReaderAnnotations,
|
||||
ClearAnnotations: r.ClearAnnotations,
|
||||
}
|
||||
if err = w.Write(outputFiles[path]); err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
|
||||
if err := r.FileSystem.WriteFile(outputPath, buf.Bytes()); err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user