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:
hongzhouzi
2022-11-15 14:56:38 +08:00
committed by GitHub
parent 5f91c1663a
commit 44167aa47a
3106 changed files with 321340 additions and 172080 deletions

View File

@@ -29,7 +29,7 @@ import (
"k8s.io/gengo/namer"
"k8s.io/gengo/types"
"k8s.io/klog"
"k8s.io/klog/v2"
)
func errs2strings(errors []error) []string {
@@ -64,7 +64,7 @@ type DefaultFileType struct {
}
func (ft DefaultFileType) AssembleFile(f *File, pathname string) error {
klog.V(2).Infof("Assembling file %q", pathname)
klog.V(5).Infof("Assembling file %q", pathname)
destFile, err := os.Create(pathname)
if err != nil {
return err
@@ -91,7 +91,7 @@ func (ft DefaultFileType) AssembleFile(f *File, pathname string) error {
}
func (ft DefaultFileType) VerifyFile(f *File, pathname string) error {
klog.V(2).Infof("Verifying file %q", pathname)
klog.V(5).Infof("Verifying file %q", pathname)
friendlyName := filepath.Join(f.PackageName, f.Name)
b := &bytes.Buffer{}
et := NewErrorTracker(b)
@@ -214,7 +214,22 @@ func (c *Context) addNameSystems(namers namer.NameSystems) *Context {
// import path already, this will be appended to 'outDir'.
func (c *Context) ExecutePackage(outDir string, p Package) error {
path := filepath.Join(outDir, p.Path())
klog.V(2).Infof("Processing package %q, disk location %q", p.Name(), path)
// When working outside of GOPATH, we typically won't want to generate the
// full path for a package. For example, if our current project's root/base
// package is github.com/foo/bar, outDir=., p.Path()=github.com/foo/bar/generated,
// then we really want to be writing files to ./generated, not ./github.com/foo/bar/generated.
// The following will trim a path prefix (github.com/foo/bar) from p.Path() to arrive at
// a relative path that works with projects not in GOPATH.
if c.TrimPathPrefix != "" {
separator := string(filepath.Separator)
if !strings.HasSuffix(c.TrimPathPrefix, separator) {
c.TrimPathPrefix += separator
}
path = strings.TrimPrefix(path, c.TrimPathPrefix)
}
klog.V(5).Infof("Processing package %q, disk location %q", p.Name(), path)
// Filter out any types the *package* doesn't care about.
packageContext := c.filteredBy(p.Filter)
os.MkdirAll(path, 0755)

View File

@@ -183,6 +183,9 @@ type Context struct {
// Allows generators to add packages at runtime.
builder *parser.Builder
// If specified, trim the prefix from a package's path before writing files.
TrimPathPrefix string
}
// NewContext generates a context from the given builder, naming systems, and

View File

@@ -20,7 +20,7 @@ import (
"go/token"
"strings"
"k8s.io/klog"
"k8s.io/klog/v2"
"k8s.io/gengo/namer"
"k8s.io/gengo/types"

View File

@@ -57,7 +57,7 @@ func NewSnippetWriter(w io.Writer, c *Context, left, right string) *SnippetWrite
// Do parses format and runs args through it. You can have arbitrary logic in
// the format (see the text/template documentation), but consider running many
// short templaces, with ordinary go logic in between--this may be more
// short templates with ordinary go logic in between--this may be more
// readable. Do is chainable. Any error causes every other call to do to be
// ignored, and the error will be returned by Error(). So you can check it just
// once, at the end of your function.