chore: update docker and k8s
This commit is contained in:
parent
2b5c7f9e91
commit
c2d440a914
1283 changed files with 67741 additions and 27918 deletions
100
vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
generated
vendored
100
vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
generated
vendored
|
@ -29,7 +29,7 @@ import (
|
|||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog"
|
||||
|
||||
conversionargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||
)
|
||||
|
@ -124,10 +124,10 @@ type conversionFuncMap map[conversionPair]*types.Type
|
|||
// Returns all manually-defined conversion functions in the package.
|
||||
func getManualConversionFunctions(context *generator.Context, pkg *types.Package, manualMap conversionFuncMap) {
|
||||
if pkg == nil {
|
||||
glog.Warningf("Skipping nil package passed to getManualConversionFunctions")
|
||||
klog.Warningf("Skipping nil package passed to getManualConversionFunctions")
|
||||
return
|
||||
}
|
||||
glog.V(5).Infof("Scanning for conversion functions in %v", pkg.Name)
|
||||
klog.V(5).Infof("Scanning for conversion functions in %v", pkg.Name)
|
||||
|
||||
scopeName := types.Ref(conversionPackagePath, "Scope").Name
|
||||
errorName := types.Ref("", "error").Name
|
||||
|
@ -136,34 +136,34 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||
|
||||
for _, f := range pkg.Functions {
|
||||
if f.Underlying == nil || f.Underlying.Kind != types.Func {
|
||||
glog.Errorf("Malformed function: %#v", f)
|
||||
klog.Errorf("Malformed function: %#v", f)
|
||||
continue
|
||||
}
|
||||
if f.Underlying.Signature == nil {
|
||||
glog.Errorf("Function without signature: %#v", f)
|
||||
klog.Errorf("Function without signature: %#v", f)
|
||||
continue
|
||||
}
|
||||
glog.V(8).Infof("Considering function %s", f.Name)
|
||||
klog.V(8).Infof("Considering function %s", f.Name)
|
||||
signature := f.Underlying.Signature
|
||||
// Check whether the function is conversion function.
|
||||
// Note that all of them have signature:
|
||||
// func Convert_inType_To_outType(inType, outType, conversion.Scope) error
|
||||
if signature.Receiver != nil {
|
||||
glog.V(8).Infof("%s has a receiver", f.Name)
|
||||
klog.V(8).Infof("%s has a receiver", f.Name)
|
||||
continue
|
||||
}
|
||||
if len(signature.Parameters) != 3 || signature.Parameters[2].Name != scopeName {
|
||||
glog.V(8).Infof("%s has wrong parameters", f.Name)
|
||||
klog.V(8).Infof("%s has wrong parameters", f.Name)
|
||||
continue
|
||||
}
|
||||
if len(signature.Results) != 1 || signature.Results[0].Name != errorName {
|
||||
glog.V(8).Infof("%s has wrong results", f.Name)
|
||||
klog.V(8).Infof("%s has wrong results", f.Name)
|
||||
continue
|
||||
}
|
||||
inType := signature.Parameters[0]
|
||||
outType := signature.Parameters[1]
|
||||
if inType.Kind != types.Pointer || outType.Kind != types.Pointer {
|
||||
glog.V(8).Infof("%s has wrong parameter types", f.Name)
|
||||
klog.V(8).Infof("%s has wrong parameter types", f.Name)
|
||||
continue
|
||||
}
|
||||
// Now check if the name satisfies the convention.
|
||||
|
@ -171,15 +171,19 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||
args := argsFromType(inType.Elem, outType.Elem)
|
||||
sw.Do("Convert_$.inType|public$_To_$.outType|public$", args)
|
||||
if f.Name.Name == buffer.String() {
|
||||
glog.V(4).Infof("Found conversion function %s", f.Name)
|
||||
klog.V(4).Infof("Found conversion function %s", f.Name)
|
||||
key := conversionPair{inType.Elem, outType.Elem}
|
||||
// We might scan the same package twice, and that's OK.
|
||||
if v, ok := manualMap[key]; ok && v != nil && v.Name.Package != pkg.Path {
|
||||
panic(fmt.Sprintf("duplicate static conversion defined: %s -> %s", key.inType, key.outType))
|
||||
panic(fmt.Sprintf("duplicate static conversion defined: %s -> %s from:\n%s.%s\n%s.%s", key.inType, key.outType, v.Name.Package, v.Name.Name, f.Name.Package, f.Name.Name))
|
||||
}
|
||||
manualMap[key] = f
|
||||
} else {
|
||||
glog.V(8).Infof("%s has wrong name", f.Name)
|
||||
// prevent user error when they don't get the correct conversion signature
|
||||
if strings.HasPrefix(f.Name.Name, "Convert_") {
|
||||
klog.Errorf("Rename function %s %s -> %s to match expected conversion signature", f.Name.Package, f.Name.Name, buffer.String())
|
||||
}
|
||||
klog.V(8).Infof("%s has wrong name", f.Name)
|
||||
}
|
||||
buffer.Reset()
|
||||
}
|
||||
|
@ -188,7 +192,7 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
|||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
packages := generator.Packages{}
|
||||
|
@ -216,7 +220,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
}
|
||||
processed[i] = true
|
||||
|
||||
glog.V(5).Infof("considering pkg %q", i)
|
||||
klog.V(5).Infof("considering pkg %q", i)
|
||||
pkg := context.Universe[i]
|
||||
// typesPkg is where the versioned types are defined. Sometimes it is
|
||||
// different from pkg. For example, kubernetes core/v1 types are defined
|
||||
|
@ -235,9 +239,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
// in their doc.go file.
|
||||
peerPkgs := extractTag(pkg.Comments)
|
||||
if peerPkgs != nil {
|
||||
glog.V(5).Infof(" tags: %q", peerPkgs)
|
||||
klog.V(5).Infof(" tags: %q", peerPkgs)
|
||||
} else {
|
||||
glog.V(5).Infof(" no tag")
|
||||
klog.V(5).Infof(" no tag")
|
||||
continue
|
||||
}
|
||||
skipUnsafe := false
|
||||
|
@ -251,14 +255,14 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
externalTypesValues := extractExternalTypesTag(pkg.Comments)
|
||||
if externalTypesValues != nil {
|
||||
if len(externalTypesValues) != 1 {
|
||||
glog.Fatalf(" expect only one value for %q tag, got: %q", externalTypesTagName, externalTypesValues)
|
||||
klog.Fatalf(" expect only one value for %q tag, got: %q", externalTypesTagName, externalTypesValues)
|
||||
}
|
||||
externalTypes := externalTypesValues[0]
|
||||
glog.V(5).Infof(" external types tags: %q", externalTypes)
|
||||
klog.V(5).Infof(" external types tags: %q", externalTypes)
|
||||
var err error
|
||||
typesPkg, err = context.AddDirectory(externalTypes)
|
||||
if err != nil {
|
||||
glog.Fatalf("cannot import package %s", externalTypes)
|
||||
klog.Fatalf("cannot import package %s", externalTypes)
|
||||
}
|
||||
// update context.Order to the latest context.Universe
|
||||
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
||||
|
@ -287,7 +291,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
context.AddDir(pp)
|
||||
p := context.Universe[pp]
|
||||
if nil == p {
|
||||
glog.Fatalf("failed to find pkg: %s", pp)
|
||||
klog.Fatalf("failed to find pkg: %s", pp)
|
||||
}
|
||||
getManualConversionFunctions(context, p, manualConversions)
|
||||
}
|
||||
|
@ -331,7 +335,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
// from being a candidate for unsafe conversion
|
||||
for k, v := range manualConversions {
|
||||
if isCopyOnly(v.CommentLines) {
|
||||
glog.V(5).Infof("Conversion function %s will not block memory copy because it is copy-only", v.Name)
|
||||
klog.V(5).Infof("Conversion function %s will not block memory copy because it is copy-only", v.Name)
|
||||
continue
|
||||
}
|
||||
// this type should be excluded from all equivalence, because the converter must be called.
|
||||
|
@ -514,9 +518,9 @@ func (g *genConversion) convertibleOnlyWithinPackage(inType, outType *types.Type
|
|||
tagvals := extractTag(t.CommentLines)
|
||||
if tagvals != nil {
|
||||
if tagvals[0] != "false" {
|
||||
glog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tagvals[0])
|
||||
klog.Fatalf("Type %v: unsupported %s value: %q", t, tagName, tagvals[0])
|
||||
}
|
||||
glog.V(5).Infof("type %v requests no conversion generation, skipping", t)
|
||||
klog.V(5).Infof("type %v requests no conversion generation, skipping", t)
|
||||
return false
|
||||
}
|
||||
// TODO: Consider generating functions for other kinds too.
|
||||
|
@ -578,10 +582,10 @@ func (g *genConversion) preexists(inType, outType *types.Type) (*types.Type, boo
|
|||
}
|
||||
|
||||
func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
||||
if glog.V(5) {
|
||||
if klog.V(5) {
|
||||
if m, ok := g.useUnsafe.(equalMemoryTypes); ok {
|
||||
var result []string
|
||||
glog.Infof("All objects without identical memory layout:")
|
||||
klog.Infof("All objects without identical memory layout:")
|
||||
for k, v := range m {
|
||||
if v {
|
||||
continue
|
||||
|
@ -590,7 +594,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
|||
}
|
||||
sort.Strings(result)
|
||||
for _, s := range result {
|
||||
glog.Infof(s)
|
||||
klog.Infof(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -606,20 +610,40 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
|||
}
|
||||
sw.Do("// RegisterConversions adds conversion functions to the given scheme.\n", nil)
|
||||
sw.Do("// Public to allow building arbitrary schemes.\n", nil)
|
||||
sw.Do("func RegisterConversions(scheme $.|raw$) error {\n", schemePtr)
|
||||
sw.Do("return scheme.AddGeneratedConversionFuncs(\n", nil)
|
||||
sw.Do("func RegisterConversions(s $.|raw$) error {\n", schemePtr)
|
||||
for _, t := range g.types {
|
||||
peerType := getPeerTypeFor(c, t, g.peerPackages)
|
||||
sw.Do(nameTmpl+",\n", argsFromType(t, peerType))
|
||||
sw.Do(nameTmpl+",\n", argsFromType(peerType, t))
|
||||
args := argsFromType(t, peerType).With("Scope", types.Ref(conversionPackagePath, "Scope"))
|
||||
sw.Do("if err := s.AddGeneratedConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return "+nameTmpl+"(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
args = argsFromType(peerType, t).With("Scope", types.Ref(conversionPackagePath, "Scope"))
|
||||
sw.Do("if err := s.AddGeneratedConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return "+nameTmpl+"(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
}
|
||||
sw.Do(")\n", nil)
|
||||
var pairs []conversionPair
|
||||
for pair, t := range g.manualConversions {
|
||||
if t.Name.Package != g.outputPackage {
|
||||
continue
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
// sort by name of the conversion function
|
||||
sort.Slice(pairs, func(i, j int) bool {
|
||||
if g.manualConversions[pairs[i]].Name.Name < g.manualConversions[pairs[j]].Name.Name {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
for _, pair := range pairs {
|
||||
args := argsFromType(pair.inType, pair.outType).With("Scope", types.Ref(conversionPackagePath, "Scope")).With("fn", g.manualConversions[pair])
|
||||
sw.Do("if err := s.AddConversionFunc((*$.inType|raw$)(nil), (*$.outType|raw$)(nil), func(a, b interface{}, scope $.Scope|raw$) error { return $.fn|raw$(a.(*$.inType|raw$), b.(*$.outType|raw$), scope) }); err != nil { return err }\n", args)
|
||||
}
|
||||
|
||||
sw.Do("return nil\n", nil)
|
||||
sw.Do("}\n\n", nil)
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
glog.V(5).Infof("generating for type %v", t)
|
||||
klog.V(5).Infof("generating for type %v", t)
|
||||
peerType := getPeerTypeFor(c, t, g.peerPackages)
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
g.generateConversion(t, peerType, sw)
|
||||
|
@ -640,10 +664,10 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
|
|||
// There is a public manual Conversion method: use it.
|
||||
} else if skipped := g.skippedFields[inType]; len(skipped) != 0 {
|
||||
// The inType had some fields we could not generate.
|
||||
glog.Errorf("Warning: could not find nor generate a final Conversion function for %v -> %v", inType, outType)
|
||||
glog.Errorf(" the following fields need manual conversion:")
|
||||
klog.Errorf("Warning: could not find nor generate a final Conversion function for %v -> %v", inType, outType)
|
||||
klog.Errorf(" the following fields need manual conversion:")
|
||||
for _, f := range skipped {
|
||||
glog.Errorf(" - %v", f)
|
||||
klog.Errorf(" - %v", f)
|
||||
}
|
||||
} else {
|
||||
// Emit a public conversion function.
|
||||
|
@ -658,7 +682,7 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
|
|||
// at any nesting level. This makes the autogenerator easy to understand, and
|
||||
// the compiler shouldn't care.
|
||||
func (g *genConversion) generateFor(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
||||
glog.V(5).Infof("generating %v -> %v", inType, outType)
|
||||
klog.V(5).Infof("generating %v -> %v", inType, outType)
|
||||
var f func(*types.Type, *types.Type, *generator.SnippetWriter)
|
||||
|
||||
switch inType.Kind {
|
||||
|
@ -829,7 +853,7 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
|||
sw.Do("}\n", nil)
|
||||
continue
|
||||
}
|
||||
glog.V(5).Infof("Skipped function %s because it is copy-only and we can use direct assignment", function.Name)
|
||||
klog.V(5).Infof("Skipped function %s because it is copy-only and we can use direct assignment", function.Name)
|
||||
}
|
||||
|
||||
// If we can't auto-convert, punt before we emit any code.
|
||||
|
|
72
vendor/k8s.io/code-generator/cmd/conversion-gen/main.go
generated
vendored
72
vendor/k8s.io/code-generator/cmd/conversion-gen/main.go
generated
vendored
|
@ -14,20 +14,59 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
// conversion-gen is a tool for auto-generating Conversion functions.
|
||||
// conversion-gen is a tool for auto-generating functions that convert
|
||||
// between internal and external types. A general conversion code
|
||||
// generation task involves three sets of packages: (1) a set of
|
||||
// packages containing internal types, (2) a single package containing
|
||||
// the external types, and (3) a single destination package (i.e.,
|
||||
// where the generated conversion functions go, and where the
|
||||
// developer-authored conversion functions are). The packages
|
||||
// containing the internal types play the role known as "peer
|
||||
// packages" in the general code-generation framework of Kubernetes.
|
||||
//
|
||||
// Given a list of input directories, it will scan for "peer" packages and
|
||||
// generate functions that efficiently convert between same-name types in each
|
||||
// package. For any pair of types that has a
|
||||
// `Convert_<pkg1>_<type>_To_<pkg2>_<Type()`
|
||||
// function (and its reciprocal), it will simply call that. use standard value
|
||||
// assignment whenever possible. The resulting file will be stored in the same
|
||||
// directory as the processed source package.
|
||||
// For each conversion task, `conversion-gen` will generate functions
|
||||
// that efficiently convert between same-name types in the two
|
||||
// (internal, external) packages. The generated functions include
|
||||
// ones named
|
||||
// autoConvert_<pkg1>_<type>_To_<pkg2>_<type>
|
||||
// for each such pair of types --- both with (pkg1,pkg2) =
|
||||
// (internal,external) and (pkg1,pkg2) = (external,internal).
|
||||
// Additionally: if the destination package does not contain one in a
|
||||
// non-generated file then a function named
|
||||
// Convert_<pkg1>_<type>_To_<pkg2>_<type>
|
||||
// is also generated and it simply calls the `autoConvert...`
|
||||
// function. The generated conversion functions use standard value
|
||||
// assignment wherever possible. For compound types, the generated
|
||||
// conversion functions call the `Convert...` functions for the
|
||||
// subsidiary types. Thus developers can override the behavior for
|
||||
// selected types. For a top-level object type (i.e., the type of an
|
||||
// object that will be input to an apiserver), for such an override to
|
||||
// be used by the apiserver the developer-maintained conversion
|
||||
// functions must also be registered by invoking the
|
||||
// `AddConversionFuncs` method of the relevant `Scheme` object from
|
||||
// k8s.io/apimachinery/pkg/runtime.
|
||||
//
|
||||
// Generation is governed by comment tags in the source. Any package may
|
||||
// request Conversion generation by including a comment in the file-comments of
|
||||
// one file, of the form:
|
||||
// // +k8s:conversion-gen=<import-path-of-peer-package>
|
||||
// `conversion-gen` will scan its `--input-dirs`, looking at the
|
||||
// package defined in each of those directories for comment tags that
|
||||
// define a conversion code generation task. A package requests
|
||||
// conversion code generation by including one or more comment in the
|
||||
// package's `doc.go` file (currently anywhere in that file is
|
||||
// acceptable, but the recommended location is above the `package`
|
||||
// statement), of the form:
|
||||
// // +k8s:conversion-gen=<import-path-of-internal-package>
|
||||
// This introduces a conversion task, for which the destination
|
||||
// package is the one containing the file with the tag and the tag
|
||||
// identifies a package containing internal types. If there is also a
|
||||
// tag of the form
|
||||
// // +k8s:conversion-gen-external-types=<import-path-of-external-package>
|
||||
// then it identifies the package containing the external types;
|
||||
// otherwise they are in the destination package.
|
||||
//
|
||||
// For each conversion code generation task, the full set of internal
|
||||
// packages (AKA peer packages) consists of the ones specified in the
|
||||
// `k8s:conversion-gen` tags PLUS any specified in the
|
||||
// `--base-peer-dirs` and `--extra-peer-dirs` flags on the command
|
||||
// line.
|
||||
//
|
||||
// When generating for a package, individual types or fields of structs may opt
|
||||
// out of Conversion generation by specifying a comment on the of the form:
|
||||
|
@ -38,9 +77,9 @@ import (
|
|||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||
"k8s.io/code-generator/cmd/conversion-gen/generators"
|
||||
|
@ -48,6 +87,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||
|
||||
// Override defaults.
|
||||
|
@ -61,7 +101,7 @@ func main() {
|
|||
pflag.Parse()
|
||||
|
||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||
glog.Fatalf("Error: %v", err)
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
||||
// Run it.
|
||||
|
@ -70,7 +110,7 @@ func main() {
|
|||
generators.DefaultNameSystem(),
|
||||
generators.Packages,
|
||||
); err != nil {
|
||||
glog.Fatalf("Error: %v", err)
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
glog.V(2).Info("Completed successfully.")
|
||||
klog.V(2).Info("Completed successfully.")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue