1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-28 14:41:10 +01:00

bump(*): k8s to 1.20-rc.0

This commit is contained in:
Mike Dame
2020-12-02 14:40:50 -05:00
parent 922c4f6a63
commit 251f44e568
368 changed files with 45286 additions and 13301 deletions

View File

@@ -28,6 +28,7 @@ import (
"k8s.io/code-generator/cmd/client-gen/path"
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
codegennamer "k8s.io/code-generator/pkg/namer"
genutil "k8s.io/code-generator/pkg/util"
"k8s.io/gengo/args"
"k8s.io/gengo/generator"
"k8s.io/gengo/namer"
@@ -279,7 +280,7 @@ func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.Cust
// Create a map from "old GV" to "new GV" so we know what changes we need to make.
changes := make(map[clientgentypes.GroupVersion]clientgentypes.GroupVersion)
for gv, inputDir := range customArgs.GroupVersionPackages() {
p := universe.Package(inputDir)
p := universe.Package(genutil.Vendorless(inputDir))
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
newGV := clientgentypes.GroupVersion{
Group: clientgentypes.Group(override[0]),

View File

@@ -411,7 +411,7 @@ var createSubresourceTemplate = `
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", c.ns, $.inputType|private$), &$.resultType|raw${})
$else$Invokes($.NewRootCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
$else$Invokes($.NewRootCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
if obj == nil {
return nil, err
}

View File

@@ -42,6 +42,11 @@ type CustomArgs struct {
// generator pick up manually written conversion funcs from external packages.
ExtraPeerDirs []string
// Additional dirs to parse and load, but not consider for peers. This is
// useful when packages depend on other packages and want to call
// conversions across them.
ExtraDirs []string
// SkipUnsafe indicates whether to generate unsafe conversions to improve the efficiency
// of these operations. The unsafe operation is a direct pointer assignment via unsafe
// (within the allowed uses of unsafe) and is equivalent to a proposed Golang change to
@@ -67,6 +72,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
"Comma-separated list of apimachinery import paths which are considered, after tag-specified peers, for conversions. Only change these if you have very good reasons.")
pflag.CommandLine.StringSliceVar(&ca.ExtraPeerDirs, "extra-peer-dirs", ca.ExtraPeerDirs,
"Application specific comma-separated list of import paths which are considered, after tag-specified peers and base-peer-dirs, for conversions.")
pflag.CommandLine.StringSliceVar(&ca.ExtraDirs, "extra-dirs", ca.ExtraDirs,
"Application specific comma-separated list of import paths which are loaded and considered for callable conversions, but are not considered peers for conversion.")
pflag.CommandLine.BoolVar(&ca.SkipUnsafe, "skip-unsafe", ca.SkipUnsafe,
"If true, will not generate code using unsafe pointer conversions; resulting code may be slower.")
}

View File

@@ -33,6 +33,7 @@ import (
"k8s.io/klog/v2"
conversionargs "k8s.io/code-generator/cmd/conversion-gen/args"
genutil "k8s.io/code-generator/pkg/util"
)
// These are the comment tags that carry parameters for conversion generation.
@@ -259,11 +260,13 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
continue
}
skipUnsafe := false
extraDirs := []string{}
if customArgs, ok := arguments.CustomArgs.(*conversionargs.CustomArgs); ok {
if len(peerPkgs) > 0 {
peerPkgs = append(peerPkgs, customArgs.BasePeerDirs...)
peerPkgs = append(peerPkgs, customArgs.ExtraPeerDirs...)
}
extraDirs = customArgs.ExtraDirs
skipUnsafe = customArgs.SkipUnsafe
}
@@ -292,18 +295,15 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
// in the output directory.
// TODO: build a more fundamental concept in gengo for dealing with modifications
// to vendored packages.
vendorless := func(pkg string) string {
if pos := strings.LastIndex(pkg, "/vendor/"); pos != -1 {
return pkg[pos+len("/vendor/"):]
}
return pkg
}
for i := range peerPkgs {
peerPkgs[i] = vendorless(peerPkgs[i])
peerPkgs[i] = genutil.Vendorless(peerPkgs[i])
}
for i := range extraDirs {
extraDirs[i] = genutil.Vendorless(extraDirs[i])
}
// Make sure our peer-packages are added and fully parsed.
for _, pp := range peerPkgs {
for _, pp := range append(peerPkgs, extraDirs...) {
context.AddDir(pp)
p := context.Universe[pp]
if nil == p {
@@ -817,21 +817,27 @@ func (g *genConversion) doMap(inType, outType *types.Type, sw *generator.Snippet
sw.Do("$.|raw$(val)\n", outType.Elem)
}
} else {
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
conversionExists := true
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
sw.Do("if err := $.|raw$(&val, newVal, s); err != nil {\n", function)
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
sw.Do("if err := "+nameTmpl+"(&val, newVal, s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
} else {
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(&val, newVal, 0); err != nil {\n", nil)
args := argsFromType(inType.Elem, outType.Elem)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
if inType.Key == outType.Key {
sw.Do("(*out)[key] = *newVal\n", nil)
} else {
sw.Do("(*out)[$.|raw$(key)] = *newVal\n", outType.Key)
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
if inType.Key == outType.Key {
sw.Do("(*out)[key] = *newVal\n", nil)
} else {
sw.Do("(*out)[$.|raw$(key)] = *newVal\n", outType.Key)
}
}
}
} else {
@@ -855,21 +861,21 @@ func (g *genConversion) doSlice(inType, outType *types.Type, sw *generator.Snipp
sw.Do("(*out)[i] = $.|raw$((*in)[i])\n", outType.Elem)
}
} else {
conversionExists := true
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
sw.Do("if err := $.|raw$(&(*in)[i], &(*out)[i], s); err != nil {\n", function)
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
sw.Do("if err := "+nameTmpl+"(&(*in)[i], &(*out)[i], s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
} else {
// TODO: This triggers on metav1.ObjectMeta <-> metav1.ObjectMeta and
// similar because neither package is the target package, and
// we really don't know which package will have the conversion
// function defined. This fires on basically every object
// conversion outside of pkg/api/v1.
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(&(*in)[i], &(*out)[i], 0); err != nil {\n", nil)
args := argsFromType(inType.Elem, outType.Elem)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("}\n", nil)
}
@@ -976,14 +982,19 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
sw.Do("out.$.name$ = in.$.name$\n", args)
continue
}
conversionExists := true
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
} else {
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
args := argsFromType(inMemberType, outMemberType)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
case types.Alias:
if isDirectlyAssignable(inMemberType, outMemberType) {
if inMemberType == outMemberType {
@@ -992,24 +1003,34 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
sw.Do("out.$.name$ = $.outType|raw$(in.$.name$)\n", args)
}
} else {
conversionExists := true
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
} else {
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
args := argsFromType(inMemberType, outMemberType)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
default:
conversionExists := true
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
} else {
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
args := argsFromType(inMemberType, outMemberType)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
}
}
@@ -1038,16 +1059,21 @@ func (g *genConversion) doPointer(inType, outType *types.Type, sw *generator.Sni
sw.Do("**out = $.|raw$(**in)\n", outType.Elem)
}
} else {
conversionExists := true
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
sw.Do("if err := $.|raw$(*in, *out, s); err != nil {\n", function)
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
sw.Do("if err := "+nameTmpl+"(*in, *out, s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
} else {
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
sw.Do("if err := s.Convert(*in, *out, 0); err != nil {\n", nil)
args := argsFromType(inType.Elem, outType.Elem)
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
sw.Do("compileErrorOnMissingConversion()\n", nil)
conversionExists = false
}
if conversionExists {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
}
}

View File

@@ -30,21 +30,33 @@ limitations under the License.
// 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
// (internal,external) and (pkg1,pkg2) = (external,internal). The
// generated conversion functions recurse on the structure of the data
// types. For structs, source and destination fields are matched up
// according to name; if a source field has no corresponding
// destination or there is a fundamental mismatch in the type of the
// field then the generated autoConvert_... function has just a
// warning comment about that field. 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.
//
// For each pair of types `conversion-gen` will also generate 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
// `AddConversionFunc`/`AddGeneratedConversionFunc` method of the
// relevant `Scheme` object from k8s.io/apimachinery/pkg/runtime.
// if both of two conditions are met: (1) the destination package does
// not contain a function of that name in a non-generated file and (2)
// the generation of the corresponding autoConvert_... function did
// not run into trouble with a missing or fundamentally differently
// typed field. A generated Convert_... function simply calls the
// corresponding `autoConvert...` function. `conversion_gen` also
// generates a function that updates a given `runtime.Scheme` by
// registering all the Convert_... functions found and generated.
// Thus developers can override the generated behavior for selected
// type pairs by putting the desired Convert_... functions in
// non-generated files. Further, developers are practically required
// to override the generated behavior when there are missing or
// fundamentally differently typed fields.
//
// `conversion-gen` will scan its `--input-dirs`, looking at the
// package defined in each of those directories for comment tags that

View File

@@ -740,7 +740,7 @@ func formatProtoFile(source []byte) ([]byte, error) {
func assembleProtoFile(w io.Writer, f *generator.File) {
w.Write(f.Header)
fmt.Fprint(w, "syntax = 'proto2';\n\n")
fmt.Fprint(w, "syntax = \"proto2\";\n\n")
if len(f.PackageName) > 0 {
fmt.Fprintf(w, "package %s;\n\n", f.PackageName)

View File

@@ -89,13 +89,6 @@ func packageForInternalInterfaces(base string) string {
return filepath.Join(base, "internalinterfaces")
}
func vendorless(p string) string {
if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {
return p[pos+len("/vendor/"):]
}
return p
}
// Packages makes the client package definition.
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
boilerplate, err := arguments.LoadGoBoilerplate()
@@ -122,7 +115,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
internalGroupVersions := make(map[string]clientgentypes.GroupVersions)
groupGoNames := make(map[string]string)
for _, inputDir := range arguments.InputDirs {
p := context.Universe.Package(vendorless(inputDir))
p := context.Universe.Package(genutil.Vendorless(inputDir))
objectMeta, internal, err := objectMetaForPackage(p)
if err != nil {