From 85368d070bebe36279d2a281429778d6eb16a814 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 25 Sep 2016 09:37:48 -0400 Subject: [PATCH 01/15] bump(k8s.io/gengo):4a9ebbace691333e73f9978d798b1bad6c53a50d --- Godeps/Godeps.json | 22 +- Godeps/LICENSES | 210 +++++ hack/.linted_packages | 1 + .../defaulter-gen/generators/defaulter.go | 747 ++++++++++++++++++ 4 files changed, 971 insertions(+), 9 deletions(-) create mode 100644 vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7e42442b34e..f1b3e2ee923 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -2571,39 +2571,43 @@ }, { "ImportPath": "k8s.io/gengo/args", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" + }, + { + "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/examples/import-boss/generators", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/generators", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/sets", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/generator", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/namer", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/parser", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/gengo/types", - "Rev": "9d004f4877d8dc116a678d35e43498404625599d" + "Rev": "4a9ebbace691333e73f9978d798b1bad6c53a50d" }, { "ImportPath": "k8s.io/heapster/metrics/api/v1/types", diff --git a/Godeps/LICENSES b/Godeps/LICENSES index 7794f9956d2..e19dcfbcf3a 100644 --- a/Godeps/LICENSES +++ b/Godeps/LICENSES @@ -76197,6 +76197,216 @@ Library. ================================================================================ +================================================================================ += vendor/k8s.io/gengo/examples/defaulter-gen/generators licensed under: = + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 The Kubernetes Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + += vendor/k8s.io/gengo/LICENSE ad09685d909e7a9f763d2bb62d4bd6fb - +================================================================================ + + ================================================================================ = vendor/k8s.io/gengo/examples/import-boss/generators licensed under: = diff --git a/hack/.linted_packages b/hack/.linted_packages index c4c6fba37ee..4220cec13e9 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -27,6 +27,7 @@ cmd/libs/go2idl/client-gen/test_apis/testgroup.k8s.io/install cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned cmd/libs/go2idl/conversion-gen cmd/libs/go2idl/deepcopy-gen +cmd/libs/go2idl/defaulter-gen cmd/libs/go2idl/generator cmd/libs/go2idl/go-to-protobuf cmd/libs/go2idl/go-to-protobuf/protoc-gen-gogo diff --git a/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go b/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go new file mode 100644 index 00000000000..0895192fc28 --- /dev/null +++ b/vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go @@ -0,0 +1,747 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "bytes" + "fmt" + "io" + "path/filepath" + "reflect" + "strings" + + "k8s.io/gengo/args" + "k8s.io/gengo/generator" + "k8s.io/gengo/namer" + "k8s.io/gengo/types" + + "github.com/golang/glog" +) + +// CustomArgs is used tby the go2idl framework to pass args specific to this +// generator. +type CustomArgs struct { + ExtraPeerDirs []string // Always consider these as last-ditch possibilities for conversions. +} + +// This is the comment tag that carries parameters for defaulter generation. +const tagName = "k8s:defaulter-gen" + +func extractTag(comments []string) []string { + return types.ExtractCommentTags("+", comments)[tagName] +} + +func checkTag(comments []string, require ...string) bool { + values := types.ExtractCommentTags("+", comments)[tagName] + if len(require) == 0 { + return len(values) == 1 && values[0] == "" + } + return reflect.DeepEqual(values, require) +} + +func defaultFnNamer() *namer.NameStrategy { + return &namer.NameStrategy{ + Prefix: "SetDefaults_", + Join: func(pre string, in []string, post string) string { + return pre + strings.Join(in, "_") + post + }, + } +} + +func objectDefaultFnNamer() *namer.NameStrategy { + return &namer.NameStrategy{ + Prefix: "SetObjectDefaults_", + Join: func(pre string, in []string, post string) string { + return pre + strings.Join(in, "_") + post + }, + } +} + +// NameSystems returns the name system used by the generators in this package. +func NameSystems() namer.NameSystems { + return namer.NameSystems{ + "public": namer.NewPublicNamer(1), + "raw": namer.NewRawNamer("", nil), + "defaultfn": defaultFnNamer(), + "objectdefaultfn": objectDefaultFnNamer(), + } +} + +// DefaultNameSystem returns the default name system for ordering the types to be +// processed by the generators in this package. +func DefaultNameSystem() string { + return "public" +} + +// defaults holds the declared defaulting functions for a given type (all defaulting functions +// are expected to be func(1)) +type defaults struct { + // object is the defaulter function for a top level type (typically one with TypeMeta) that + // invokes all child defaulters. May be nil if the object defaulter has not yet been generated. + object *types.Type + // base is a defaulter function defined for a type SetDefaults_Pod which does not invoke all + // child defaults - the base defaulter alone is insufficient to default a type + base *types.Type + // additional is zero or more defaulter functions of the form SetDefaults_Pod_XXXX that can be + // included in the Object defaulter. + additional []*types.Type +} + +// All of the types in conversions map are of type "DeclarationOf" with +// the underlying type being "Func". +type defaulterFuncMap map[*types.Type]defaults + +// Returns all manually-defined defaulting functions in the package. +func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package, manualMap defaulterFuncMap) { + buffer := &bytes.Buffer{} + sw := generator.NewSnippetWriter(buffer, context, "$", "$") + + for _, f := range pkg.Functions { + if f.Underlying == nil || f.Underlying.Kind != types.Func { + glog.Errorf("Malformed function: %#v", f) + continue + } + if f.Underlying.Signature == nil { + glog.Errorf("Function without signature: %#v", f) + continue + } + signature := f.Underlying.Signature + // Check whether the function is defaulting function. + // Note that all of them have signature: + // object: func SetObjectDefaults_inType(*inType) + // base: func SetDefaults_inType(*inType) + // additional: func SetDefaults_inType_Qualifier(*inType) + if signature.Receiver != nil { + continue + } + if len(signature.Parameters) != 1 { + continue + } + if len(signature.Results) != 0 { + continue + } + inType := signature.Parameters[0] + if inType.Kind != types.Pointer { + continue + } + // Check if this is the primary defaulter. + args := defaultingArgsFromType(inType.Elem) + sw.Do("$.inType|defaultfn$", args) + switch { + case f.Name.Name == buffer.String(): + key := inType.Elem + // We might scan the same package twice, and that's OK. + v, ok := manualMap[key] + if ok && v.base != nil && v.base.Name.Package != pkg.Path { + panic(fmt.Sprintf("duplicate static defaulter defined: %#v", key)) + } + v.base = f + manualMap[key] = v + glog.V(6).Infof("found base defaulter function for %s from %s", key.Name, f.Name) + // Is one of the additional defaulters - a top level defaulter on a type that is + // also invoked. + case strings.HasPrefix(f.Name.Name, buffer.String()+"_"): + key := inType.Elem + v, ok := manualMap[key] + if ok { + exists := false + for _, existing := range v.additional { + if existing.Name == f.Name { + exists = true + break + } + } + if exists { + continue + } + } + v.additional = append(v.additional, f) + manualMap[key] = v + glog.V(6).Infof("found additional defaulter function for %s from %s", key.Name, f.Name) + } + buffer.Reset() + sw.Do("$.inType|objectdefaultfn$", args) + if f.Name.Name == buffer.String() { + key := inType.Elem + // We might scan the same package twice, and that's OK. + v, ok := manualMap[key] + if ok && v.base != nil && v.base.Name.Package != pkg.Path { + panic(fmt.Sprintf("duplicate static defaulter defined: %#v", key)) + } + v.object = f + manualMap[key] = v + glog.V(6).Infof("found object defaulter function for %s from %s", key.Name, f.Name) + } + buffer.Reset() + } +} + +func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages { + boilerplate, err := arguments.LoadGoBoilerplate() + if err != nil { + glog.Fatalf("Failed loading boilerplate: %v", err) + } + + packages := generator.Packages{} + header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...) + header = append(header, []byte( + ` +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +`)...) + + // Accumulate pre-existing default functions. + // TODO: This is too ad-hoc. We need a better way. + existingDefaulters := defaulterFuncMap{} + + buffer := &bytes.Buffer{} + sw := generator.NewSnippetWriter(buffer, context, "$", "$") + + // We are generating defaults only for packages that are explicitly + // passed as InputDir. + for _, i := range context.Inputs { + glog.V(5).Infof("considering pkg %q", i) + pkg := context.Universe[i] + if pkg == nil { + // If the input had no Go files, for example. + continue + } + + // Add defaulting functions. + getManualDefaultingFunctions(context, pkg, existingDefaulters) + + var peerPkgs []string + if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { + if len(customArgs.ExtraPeerDirs) > 0 { + peerPkgs = append(peerPkgs, customArgs.ExtraPeerDirs...) + } + } + // Make sure our peer-packages are added and fully parsed. + for _, pp := range peerPkgs { + context.AddDir(pp) + getManualDefaultingFunctions(context, context.Universe[pp], existingDefaulters) + } + + typesWith := extractTag(pkg.Comments) + shouldCreateObjectDefaulterFn := func(t *types.Type) bool { + if defaults, ok := existingDefaulters[t]; ok && defaults.object != nil { + // A default generator is defined + glog.V(5).Infof(" an object defaulter already exists as %s", defaults.base.Name) + return false + } + // opt-out + if checkTag(t.SecondClosestCommentLines, "false") { + return false + } + // opt-in + if checkTag(t.SecondClosestCommentLines, "true") { + return true + } + // For every k8s:defaulter-gen tag at the package level, interpret the value as a + // field name (like TypeMeta, ListMeta, ObjectMeta) and trigger defaulter generation + // for any type with any of the matching field names. Provides a more useful package + // level defaulting than global (because we only need defaulters on a subset of objects - + // usually those with TypeMeta). + if t.Kind == types.Struct && len(typesWith) > 0 { + for _, field := range t.Members { + for _, s := range typesWith { + if field.Name == s { + return true + } + } + } + } + return false + } + + newDefaulters := defaulterFuncMap{} + for _, t := range pkg.Types { + if !shouldCreateObjectDefaulterFn(t) { + continue + } + if namer.IsPrivateGoName(t.Name.Name) { + // We won't be able to convert to a private type. + glog.V(5).Infof(" found a type %v, but it is a private name", t) + continue + } + + // create a synthetic type we can use during generation + newDefaulters[t] = defaults{} + } + + // only generate defaulters for objects that actually have defined defaulters + // prevents empty defaulters from being registered + for { + promoted := 0 + for t, d := range newDefaulters { + if d.object != nil { + continue + } + if buildCallTreeForType(t, true, existingDefaulters, newDefaulters) != nil { + args := defaultingArgsFromType(t) + sw.Do("$.inType|objectdefaultfn$", args) + newDefaulters[t] = defaults{ + object: &types.Type{ + Name: types.Name{ + Package: pkg.Path, + Name: buffer.String(), + }, + Kind: types.Func, + }, + } + buffer.Reset() + promoted++ + } + } + if promoted != 0 { + continue + } + + // prune any types that were not used + for t, d := range newDefaulters { + if d.object == nil { + glog.V(6).Infof("did not generate defaulter for %s because no child defaulters were registered", t.Name) + delete(newDefaulters, t) + } + } + break + } + + if len(newDefaulters) == 0 { + glog.V(5).Infof("no defaulters in package %s", pkg.Name) + continue + } + + packages = append(packages, + &generator.DefaultPackage{ + PackageName: filepath.Base(pkg.Path), + PackagePath: pkg.Path, + HeaderText: header, + GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { + return []generator.Generator{ + NewGenDefaulter(arguments.OutputFileBaseName, pkg.Path, existingDefaulters, newDefaulters, peerPkgs), + } + }, + FilterFunc: func(c *generator.Context, t *types.Type) bool { + return t.Name.Package == pkg.Path + }, + }) + } + return packages +} + +// buildCallTreeForType creates a tree of paths to fields (based on how they would be accessed in Go - pointer, elem, +// slice, or key) and the functions that should be invoked on each field. An in-order traversal of the resulting tree +// can be used to generate a Go function that invokes each nested function on the appropriate type. The return +// value may be nil if there are no functions to call on type or the type is a primitive (Defaulters can only be +// invoked on structs today). When root is true this function will not use a newDefaulter. existingDefaulters should +// contain all defaulting functions by type defined in code - newDefaulters should contain all object defaulters +// that could be or will be generated. If newDefaulters has an entry for a type, but the 'object' field is nil, +// this function skips adding that defaulter - this allows us to avoid generating object defaulter functions for +// list types that call empty defaulters. +func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefaulters defaulterFuncMap) *callNode { + parent := &callNode{} + + if root { + // the root node is always a pointer + parent.elem = true + } + + defaults, _ := existingDefaulters[t] + newDefaults, generated := newDefaulters[t] + switch { + case !root && generated && newDefaults.object != nil: + parent.call = append(parent.call, newDefaults.object) + // if we will be generating the defaulter, it by definition is a covering + // defaulter, so we halt recursion + glog.V(6).Infof("the defaulter %s will be generated as an object defaulter", t.Name) + return parent + + case defaults.object != nil: + // object defaulters are always covering + parent.call = append(parent.call, defaults.object) + return parent + + case defaults.base != nil: + parent.call = append(parent.call, defaults.base) + // if the base function indicates it "covers" (it already includes defaulters) + // we can halt recursion + if checkTag(defaults.base.CommentLines, "covers") { + glog.V(6).Infof("the defaulter %s indicates it covers all sub generators", t.Name) + return parent + } + } + + // base has been added already, now add any additional defaulters defined for this object + parent.call = append(parent.call, defaults.additional...) + + switch t.Kind { + case types.Pointer: + if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { + child.elem = true + parent.children = append(parent.children, *child) + } + case types.Slice, types.Array: + if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { + child.index = true + parent.children = append(parent.children, *child) + } + case types.Map: + if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { + child.key = true + parent.children = append(parent.children, *child) + } + case types.Struct: + for _, field := range t.Members { + name := field.Name + if len(name) == 0 { + if field.Type.Kind == types.Pointer { + name = field.Type.Elem.Name.Name + } else { + name = field.Type.Name.Name + } + } + if child := buildCallTreeForType(field.Type, false, existingDefaulters, newDefaulters); child != nil { + child.field = name + parent.children = append(parent.children, *child) + } + } + } + if len(parent.children) == 0 && len(parent.call) == 0 { + //glog.V(6).Infof("decided type %s needs no generation", t.Name) + return nil + } + return parent +} + +const ( + runtimePackagePath = "k8s.io/kubernetes/pkg/runtime" + conversionPackagePath = "k8s.io/kubernetes/pkg/conversion" +) + +// genDefaulter produces a file with a autogenerated conversions. +type genDefaulter struct { + generator.DefaultGen + targetPackage string + peerPackages []string + newDefaulters defaulterFuncMap + existingDefaulters defaulterFuncMap + imports namer.ImportTracker + typesForInit []*types.Type +} + +func NewGenDefaulter(sanitizedName, targetPackage string, existingDefaulters, newDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator { + return &genDefaulter{ + DefaultGen: generator.DefaultGen{ + OptionalName: sanitizedName, + }, + targetPackage: targetPackage, + peerPackages: peerPkgs, + newDefaulters: newDefaulters, + existingDefaulters: existingDefaulters, + imports: generator.NewImportTracker(), + typesForInit: make([]*types.Type, 0), + } +} + +func (g *genDefaulter) Namers(c *generator.Context) namer.NameSystems { + // Have the raw namer for this file track what it imports. + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.targetPackage, g.imports), + } +} + +func (g *genDefaulter) isOtherPackage(pkg string) bool { + if pkg == g.targetPackage { + return false + } + if strings.HasSuffix(pkg, `"`+g.targetPackage+`"`) { + return false + } + return true +} + +func (g *genDefaulter) Filter(c *generator.Context, t *types.Type) bool { + defaults, ok := g.newDefaulters[t] + if !ok || defaults.object == nil { + return false + } + g.typesForInit = append(g.typesForInit, t) + return true +} + +func (g *genDefaulter) Imports(c *generator.Context) (imports []string) { + var importLines []string + for _, singleImport := range g.imports.ImportLines() { + if g.isOtherPackage(singleImport) { + importLines = append(importLines, singleImport) + } + } + return importLines +} + +func (g *genDefaulter) Init(c *generator.Context, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + scheme := c.Universe.Type(types.Name{Package: runtimePackagePath, Name: "Scheme"}) + schemePtr := &types.Type{ + Kind: types.Pointer, + Elem: scheme, + } + sw.Do("// RegisterDefaults adds defaulters functions to the given scheme.\n", nil) + sw.Do("// Public to allow building arbitrary schemes.\n", nil) + sw.Do("// All generated defaulters are covering - they call all nested defaulters.\n", nil) + sw.Do("func RegisterDefaults(scheme $.|raw$) error {\n", schemePtr) + for _, t := range g.typesForInit { + args := defaultingArgsFromType(t) + sw.Do("scheme.AddTypeDefaultingFunc(&$.inType|raw${}, func(obj interface{}) { $.inType|objectdefaultfn$(obj.(*$.inType|raw$)) })\n", args) + } + sw.Do("return nil\n", nil) + sw.Do("}\n\n", nil) + return sw.Error() +} + +func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + if _, ok := g.newDefaulters[t]; !ok { + return nil + } + + glog.V(5).Infof("generating for type %v", t) + + callTree := buildCallTreeForType(t, true, g.existingDefaulters, g.newDefaulters) + if callTree == nil { + glog.V(5).Infof(" no defaulters defined") + return nil + } + i := 0 + callTree.VisitInOrder(func(ancestors []*callNode, current *callNode) { + if len(current.call) == 0 { + return + } + path := callPath(append(ancestors, current)) + glog.V(5).Infof(" %d: %s", i, path) + i++ + }) + + sw := generator.NewSnippetWriter(w, c, "$", "$") + g.generateDefaulter(t, callTree, sw) + return sw.Error() +} + +func defaultingArgsFromType(inType *types.Type) generator.Args { + return generator.Args{ + "inType": inType, + } +} + +func (g *genDefaulter) generateDefaulter(inType *types.Type, callTree *callNode, sw *generator.SnippetWriter) { + sw.Do("func $.inType|objectdefaultfn$(in *$.inType|raw$) {\n", defaultingArgsFromType(inType)) + callTree.WriteMethod("in", 0, nil, sw) + sw.Do("}\n\n", nil) +} + +// callNode represents an entry in a tree of Go type accessors - the path from the root to a leaf represents +// how in Go code an access would be performed. For example, if a defaulting function exists on a container +// lifecycle hook, to invoke that defaulter correctly would require this Go code: +// +// for i := range pod.Spec.Containers { +// o := &pod.Spec.Containers[i] +// if o.LifecycleHook != nil { +// SetDefaults_LifecycleHook(o.LifecycleHook) +// } +// } +// +// That would be represented by a call tree like: +// +// callNode +// field: "Spec" +// children: +// - field: "Containers" +// children: +// - index: true +// children: +// - field: "LifecycleHook" +// elem: true +// call: +// - SetDefaults_LifecycleHook +// +// which we can traverse to build that Go struct (you must call the field Spec, then Containers, then range over +// that field, then check whether the LifecycleHook field is nil, before calling SetDefaults_LifecycleHook on +// the pointer to that field). +type callNode struct { + // field is the name of the Go member to access + field string + // key is true if this is a map and we must range over the key and values + key bool + // index is true if this is a slice and we must range over the slice values + index bool + // elem is true if the previous elements refer to a pointer (typically just field) + elem bool + + // call is all of the functions that must be invoked on this particular node, in order + call []*types.Type + // children is the child call nodes that must also be traversed + children []callNode +} + +// CallNodeVisitorFunc is a function for visiting a call tree. ancestors is the list of all parents +// of this node to the root of the tree - will be empty at the root. +type CallNodeVisitorFunc func(ancestors []*callNode, node *callNode) + +func (n *callNode) VisitInOrder(fn CallNodeVisitorFunc) { + n.visitInOrder(nil, fn) +} + +func (n *callNode) visitInOrder(ancestors []*callNode, fn CallNodeVisitorFunc) { + fn(ancestors, n) + ancestors = append(ancestors, n) + for i := range n.children { + n.children[i].visitInOrder(ancestors, fn) + } +} + +var ( + indexVariables = "ijklmnop" + localVariables = "abcdefgh" +) + +// varsForDepth creates temporary variables guaranteed to be unique within lexical Go scopes +// of this depth in a function. It uses canonical Go loop variables for the first 7 levels +// and then resorts to uglier prefixes. +func varsForDepth(depth int) (index, local string) { + if depth > len(indexVariables) { + index = fmt.Sprintf("i%d", depth) + } else { + index = indexVariables[depth : depth+1] + } + if depth > len(localVariables) { + local = fmt.Sprintf("local%d", depth) + } else { + local = localVariables[depth : depth+1] + } + return +} + +// writeCalls generates a list of function calls based on the calls field for the provided variable +// name and pointer. +func (n *callNode) writeCalls(varName string, isVarPointer bool, sw *generator.SnippetWriter) { + accessor := varName + if !isVarPointer { + accessor = "&" + accessor + } + for _, fn := range n.call { + sw.Do("$.fn|raw$($.var$)\n", generator.Args{ + "fn": fn, + "var": accessor, + }) + } +} + +// WriteMethod performs an in-order traversal of the calltree, generating loops and if blocks as necessary +// to correctly turn the call tree into a method body that invokes all calls on all child nodes of the call tree. +// Depth is used to generate local variables at the proper depth. +func (n *callNode) WriteMethod(varName string, depth int, ancestors []*callNode, sw *generator.SnippetWriter) { + // if len(n.call) > 0 { + // sw.Do(fmt.Sprintf("// %s\n", callPath(append(ancestors, n)).String()), nil) + // } + + if len(n.field) > 0 { + varName = varName + "." + n.field + } + + index, local := varsForDepth(depth) + vars := generator.Args{ + "index": index, + "local": local, + "var": varName, + } + + isPointer := n.elem + if isPointer && len(ancestors) > 0 { + sw.Do("if $.var$ != nil {\n", vars) + } + + switch { + case n.index: + sw.Do("for $.index$ := range $.var$ {\n", vars) + sw.Do("$.local$ := &$.var$[$.index$]\n", vars) + n.writeCalls(local, true, sw) + for i := range n.children { + n.children[i].WriteMethod(local, depth+1, append(ancestors, n), sw) + } + sw.Do("}\n", nil) + case n.key: + default: + n.writeCalls(varName, isPointer, sw) + for i := range n.children { + n.children[i].WriteMethod(varName, depth, append(ancestors, n), sw) + } + } + + if isPointer && len(ancestors) > 0 { + sw.Do("}\n", nil) + } +} + +type callPath []*callNode + +// String prints a representation of a callPath that roughly approximates what a Go accessor +// would look like. Used for debugging only. +func (path callPath) String() string { + if len(path) == 0 { + return "" + } + var parts []string + for _, p := range path { + last := len(parts) - 1 + switch { + case p.elem: + if len(parts) > 0 { + parts[last] = "*" + parts[last] + } else { + parts = append(parts, "*") + } + case p.index: + if len(parts) > 0 { + parts[last] = parts[last] + "[i]" + } else { + parts = append(parts, "[i]") + } + case p.key: + if len(parts) > 0 { + parts[last] = parts[last] + "[key]" + } else { + parts = append(parts, "[key]") + } + default: + if len(p.field) > 0 { + parts = append(parts, p.field) + } else { + parts = append(parts, "") + } + } + } + var calls []string + for _, fn := range path[len(path)-1].call { + calls = append(calls, fn.Name.String()) + } + if len(calls) == 0 { + calls = append(calls, "") + } + + return strings.Join(parts, ".") + " calls " + strings.Join(calls, ", ") +} From 68a9983ec7dbc9de415b65470ab688c26948eda4 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 14:56:23 -0400 Subject: [PATCH 02/15] Add a new Default() method on Scheme Allow defaulter functions to be registered with the scheme. --- pkg/conversion/converter.go | 4 ++-- pkg/runtime/scheme.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/conversion/converter.go b/pkg/conversion/converter.go index 8941b18aefd..9ab468ebe2b 100644 --- a/pkg/conversion/converter.go +++ b/pkg/conversion/converter.go @@ -431,10 +431,10 @@ func (c *Converter) SetStructFieldCopy(srcFieldType interface{}, srcFieldName st } // RegisterDefaultingFunc registers a value-defaulting func with the Converter. -// defaultingFunc must take one parameters: a pointer to the input type. +// defaultingFunc must take one parameter: a pointer to the input type. // // Example: -// c.RegisteDefaultingFunc( +// c.RegisterDefaultingFunc( // func(in *v1.Pod) { // // defaulting logic... // }) diff --git a/pkg/runtime/scheme.go b/pkg/runtime/scheme.go index f5d3bd08298..fdd4d1f44fa 100644 --- a/pkg/runtime/scheme.go +++ b/pkg/runtime/scheme.go @@ -61,6 +61,10 @@ type Scheme struct { // resource field labels in that version to internal version. fieldLabelConversionFuncs map[string]map[string]FieldLabelConversionFunc + // defaulterFuncs is an array of interfaces to be called with an object to provide defaulting + // the provided object must be a pointer. + defaulterFuncs map[reflect.Type]func(interface{}) + // converter stores all registered conversion functions. It also has // default coverting behavior. converter *conversion.Converter @@ -82,6 +86,7 @@ func NewScheme() *Scheme { unversionedKinds: map[string]reflect.Type{}, cloner: conversion.NewCloner(), fieldLabelConversionFuncs: map[string]map[string]FieldLabelConversionFunc{}, + defaulterFuncs: map[reflect.Type]func(interface{}){}, } s.converter = conversion.NewConverter(s.nameFunc) @@ -421,6 +426,22 @@ func (s *Scheme) AddDefaultingFuncs(defaultingFuncs ...interface{}) error { return nil } +// AddTypeDefaultingFuncs registers a function that is passed a pointer to an +// object and can default fields on the object. These functions will be invoked +// when Default() is called. The function will never be called unless the +// defaulted object matches srcType. If this function is invoked twice with the +// same srcType, the fn passed to the later call will be used instead. +func (s *Scheme) AddTypeDefaultingFunc(srcType Object, fn func(interface{})) { + s.defaulterFuncs[reflect.TypeOf(srcType)] = fn +} + +// Default sets defaults on the provided Object. +func (s *Scheme) Default(src Object) { + if fn, ok := s.defaulterFuncs[reflect.TypeOf(src)]; ok { + fn(src) + } +} + // Copy does a deep copy of an API object. func (s *Scheme) Copy(src Object) (Object, error) { dst, err := s.DeepCopy(src) From 0aa8da19a973f93ac39e6adb69511e16e7765b6d Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 23:26:32 -0400 Subject: [PATCH 03/15] Move old defaulters to public functions Also make Deployment defaulting resilient to fuzzing --- pkg/apis/extensions/v1beta1/defaults.go | 2 +- pkg/apis/rbac/v1alpha1/defaults.go | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/apis/extensions/v1beta1/defaults.go b/pkg/apis/extensions/v1beta1/defaults.go index 0708b11e1a3..1591808ca13 100644 --- a/pkg/apis/extensions/v1beta1/defaults.go +++ b/pkg/apis/extensions/v1beta1/defaults.go @@ -71,7 +71,7 @@ func SetDefaults_Deployment(obj *Deployment) { if strategy.Type == "" { strategy.Type = RollingUpdateDeploymentStrategyType } - if strategy.Type == RollingUpdateDeploymentStrategyType { + if strategy.Type == RollingUpdateDeploymentStrategyType || strategy.RollingUpdate != nil { if strategy.RollingUpdate == nil { rollingUpdate := RollingUpdateDeployment{} strategy.RollingUpdate = &rollingUpdate diff --git a/pkg/apis/rbac/v1alpha1/defaults.go b/pkg/apis/rbac/v1alpha1/defaults.go index e97f4109c64..2e0b17277c1 100644 --- a/pkg/apis/rbac/v1alpha1/defaults.go +++ b/pkg/apis/rbac/v1alpha1/defaults.go @@ -22,15 +22,18 @@ import ( func addDefaultingFuncs(scheme *runtime.Scheme) error { return scheme.AddDefaultingFuncs( - func(obj *ClusterRoleBinding) { - if len(obj.RoleRef.APIGroup) == 0 { - obj.RoleRef.APIGroup = GroupName - } - }, - func(obj *RoleBinding) { - if len(obj.RoleRef.APIGroup) == 0 { - obj.RoleRef.APIGroup = GroupName - } - }, + SetDefaults_ClusterRoleBinding, + SetDefaults_RoleBinding, ) } + +func SetDefaults_ClusterRoleBinding(obj *ClusterRoleBinding) { + if len(obj.RoleRef.APIGroup) == 0 { + obj.RoleRef.APIGroup = GroupName + } +} +func SetDefaults_RoleBinding(obj *RoleBinding) { + if len(obj.RoleRef.APIGroup) == 0 { + obj.RoleRef.APIGroup = GroupName + } +} From 5062406b7794ab62e28b65136176011a80d8fbeb Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 25 Sep 2016 12:08:50 -0400 Subject: [PATCH 04/15] Hand generated conversion should check nil --- pkg/api/v1/conversion.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index 35be8a5f408..635f64777c4 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -387,7 +387,9 @@ func Convert_api_ReplicationControllerSpec_To_v1_ReplicationControllerSpec(in *a } func Convert_v1_ReplicationControllerSpec_To_api_ReplicationControllerSpec(in *ReplicationControllerSpec, out *api.ReplicationControllerSpec, s conversion.Scope) error { - out.Replicas = *in.Replicas + if in.Replicas != nil { + out.Replicas = *in.Replicas + } out.MinReadySeconds = in.MinReadySeconds out.Selector = in.Selector if in.Template != nil { From 1c49fc57ed000127caf50a80a139edcc9c068da7 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Thu, 22 Sep 2016 23:54:05 -0400 Subject: [PATCH 05/15] Create a generator for defaulters Given an object that wishes to have a top level defaulter, traverse the object looking for nested fields that have defaulters and generate a single function for that type that invokes all defaulters. The function will have the name `SetObjectDefaults_NAME`. Types use `// +k8s:defaulter-gen=true` to indicate they wish a defaulter generated. If a function already exists with the desired name `SetObjectDefaults_NAME` then no generation will occur. At a package level, authors can bulk select the types to generate by setting the value of the comment to the name of a field - all objects with that field name without `// +k8s:defaulter-gen=false` defined on the type will get a defaulter. Because the defaulting behavior from conversions happens recursively, all defaulters are expected to be invoked. We call these defaulters "non-covering" (other defaulters may be invoked beneath them). The defaulters we generate, by comparison, are "covering" - no nested defaulters should be invoked. To distinguish between these two types, we introduce the `// +k8s:defaulter-gen=covers` comment on a defaulter function which will instruct the generator that the function should terminate recursion. This sets the stage for future defaulter generation from comments by subsuming our existing generators --- cmd/libs/go2idl/defaulter-gen/main.go | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cmd/libs/go2idl/defaulter-gen/main.go diff --git a/cmd/libs/go2idl/defaulter-gen/main.go b/cmd/libs/go2idl/defaulter-gen/main.go new file mode 100644 index 00000000000..b12e58376ed --- /dev/null +++ b/cmd/libs/go2idl/defaulter-gen/main.go @@ -0,0 +1,78 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// defaulter-gen is a tool for auto-generating Defaulter functions. +// +// Given a list of input directories, it will scan for top level types +// and generate efficient defaulters for an entire object from the sum +// of the SetDefault_* methods contained in the object tree. +// +// Generation is governed by comment tags in the source. Any package may +// request defaulter generation by including one or more comment tags at +// the package comment level: +// +// // +k8s:defaulter-gen= +// +// which will create defaulters for any type that contains the provided +// field name (if the type has defaulters). Any type may request explicit +// defaulting by providing the comment tag: +// +// // +k8s:defaulter-gen=true|false +// +// An existing defaulter method (`SetDefaults_TYPE`) can provide the +// comment tag: +// +// // +k8s:defaulter-gen=covers +// +// to indicate that the defaulter does not or should not call any nested +// defaulters. +package main + +import ( + "path/filepath" + + "k8s.io/gengo/args" + "k8s.io/gengo/examples/defaulter-gen/generators" + + "github.com/golang/glog" + "github.com/spf13/pflag" +) + +func main() { + arguments := args.Default() + + // Override defaults. + arguments.OutputFileBaseName = "zz_generated.defaults" + arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt") + + // Custom args. + customArgs := &generators.CustomArgs{ + ExtraPeerDirs: []string{}, + } + pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs, + "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.") + arguments.CustomArgs = customArgs + + // Run it. + if err := arguments.Execute( + generators.NameSystems(), + generators.DefaultNameSystem(), + generators.Packages, + ); err != nil { + glog.Fatalf("Error: %v", err) + } + glog.V(2).Info("Completed successfully.") +} From ca6fc3a68ba5a39365d39ef96cf04843a6174ffd Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 17:25:21 -0400 Subject: [PATCH 06/15] Update makefile to generate defaulters --- Makefile.generated_files | 144 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/Makefile.generated_files b/Makefile.generated_files index a09e428fbff..8861c1a2dc3 100644 --- a/Makefile.generated_files +++ b/Makefile.generated_files @@ -35,7 +35,7 @@ SHELL := /bin/bash # This rule collects all the generated file sets into a single rule. Other # rules should depend on this to ensure generated files are rebuilt. .PHONY: generated_files -generated_files: gen_deepcopy gen_conversion gen_openapi +generated_files: gen_deepcopy gen_defaulter gen_conversion gen_openapi # Code-generation logic. # @@ -286,6 +286,146 @@ $(DEEPCOPY_GEN): hack/make-rules/build.sh cmd/libs/go2idl/deepcopy-gen touch $@ +# +# Defaulter generation +# +# Any package that wants defaulter functions generated must include a +# comment-tag in column 0 of one file of the form: +# // +k8s:defaulter-gen= +# +# The depends on context: +# on types: +# true: always generate a defaulter for this type +# false: never generate a defaulter for this type +# on functions: +# covers: if the function name matches SetDefault_NAME, instructs +# the generator not to recurse +# on packages: +# FIELDNAME: any object with a field of this name is a candidate +# for having a defaulter generated + +# The result file, in each pkg, of defaulter generation. +DEFAULTER_BASENAME := $(GENERATED_FILE_PREFIX)defaults +DEFAULTER_FILENAME := $(DEFAULTER_BASENAME).go + +# The tool used to generate defaulters. +DEFAULTER_GEN := $(BIN_DIR)/defaulter-gen + +# All directories that request any form of defaulter generation. +ifeq ($(DBG_MAKEFILE),1) + $(warning ***** finding all +k8s:defaulter-gen tags) +endif +DEFAULTER_DIRS := $(shell \ + grep --color=never -l '+k8s:defaulter-gen=' $(ALL_K8S_TAG_FILES) \ + | xargs -n1 dirname \ + | sort -u \ +) + +DEFAULTER_FILES := $(addsuffix /$(DEFAULTER_FILENAME), $(DEFAULTER_DIRS)) + +# This rule aggregates the set of files to generate and then generates them all +# in a single run of the tool. +.PHONY: gen_defaulter +gen_defaulter: $(DEFAULTER_FILES) + if [[ -f $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \ + ./hack/run-in-gopath.sh $(DEFAULTER_GEN) \ + --v $(KUBE_VERBOSE) \ + --logtostderr \ + -i $$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -) \ + --extra-peer-dirs $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(DEFAULTER_DIRS)) | sed 's/ /,/g') \ + -O $(DEFAULTER_BASENAME); \ + fi + +# For each dir in DEFAULTER_DIRS, this establishes a dependency between the +# output file and the input files that should trigger a rebuild. +# +# The variable value was set in $(GOFILES_META) and included as part of the +# dependency management logic. +# +# Note that this is a deps-only statement, not a full rule (see below). This +# has to be done in a distinct step because wildcards don't work in static +# pattern rules. +# +# The '$(eval)' is needed because this has a different RHS for each LHS, and +# would otherwise produce results that make can't parse. +# +# We depend on the $(GOFILES_META).stamp to detect when the set of input files +# has changed. This allows us to detect deleted input files. +$(foreach dir, $(DEFAULTER_DIRS), $(eval \ + $(dir)/$(DEFAULTER_FILENAME): $(META_DIR)/$(dir)/$(GOFILES_META).stamp \ + $(gofiles__$(dir)) \ +)) + +# For each dir in DEFAULTER_DIRS, for each target in $(defaulters__$(dir)), +# this establishes a dependency between the output file and the input files +# that should trigger a rebuild. +# +# The variable value was set in $(GOFILES_META) and included as part of the +# dependency management logic. +# +# Note that this is a deps-only statement, not a full rule (see below). This +# has to be done in a distinct step because wildcards don't work in static +# pattern rules. +# +# The '$(eval)' is needed because this has a different RHS for each LHS, and +# would otherwise produce results that make can't parse. +# +# We depend on the $(GOFILES_META).stamp to detect when the set of input files +# has changed. This allows us to detect deleted input files. +$(foreach dir, $(DEFAULTER_DIRS), \ + $(foreach tgt, $(defaulters__$(dir)), $(eval \ + $(dir)/$(DEFAULTER_FILENAME): $(META_DIR)/$(tgt)/$(GOFILES_META).stamp \ + $(gofiles__$(tgt)) \ + )) \ +) + +# Unilaterally remove any leftovers from previous runs. +$(shell rm -f $(META_DIR)/$(DEFAULTER_GEN)*.todo) + +# How to regenerate defaulter code. This is a little slow to run, so we batch +# it up and trigger the batch from the 'generated_files' target. +$(DEFAULTER_FILES): $(DEFAULTER_GEN) + mkdir -p $$(dirname $(META_DIR)/$(DEFAULTER_GEN)) + echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(DEFAULTER_GEN).todo + +# This calculates the dependencies for the generator tool, so we only rebuild +# it when needed. It is PHONY so that it always runs, but it only updates the +# file if the contents have actually changed. We 'sinclude' this later. +.PHONY: $(META_DIR)/$(DEFAULTER_GEN).mk +$(META_DIR)/$(DEFAULTER_GEN).mk: + mkdir -p $(@D); \ + (echo -n "$(DEFAULTER_GEN): "; \ + DIRECT=$$(go list -f '{{.Dir}} {{.Dir}}/*.go' \ + ./cmd/libs/go2idl/defaulter-gen); \ + INDIRECT=$$(go list \ + -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ + ./cmd/libs/go2idl/defaulter-gen \ + | grep --color=never "^$(PRJ_SRC_PATH)" \ + | sed 's|^$(PRJ_SRC_PATH)|./|' \ + | xargs go list -f '{{.Dir}} {{.Dir}}/*.go'); \ + echo $$DIRECT $$INDIRECT \ + | sed 's/ / \\=,/g' \ + | tr '=,' '\n\t'; \ + ) | sed "s|$$(pwd -P)/||" > $@.tmp; \ + cmp -s $@.tmp $@ || cat $@.tmp > $@ && rm -f $@.tmp + +# Include dependency info for the generator tool. This will cause the rule of +# the same name to be considered and if it is updated, make will restart. +sinclude $(META_DIR)/$(DEFAULTER_GEN).mk + +# How to build the generator tool. The deps for this are defined in +# the $(DEFAULTER_GEN).mk, above. +# +# A word on the need to touch: This rule might trigger if, for example, a +# non-Go file was added or deleted from a directory on which this depends. +# This target needs to be reconsidered, but Go realizes it doesn't actually +# have to be rebuilt. In that case, make will forever see the dependency as +# newer than the binary, and try to rebuild it over and over. So we touch it, +# and make is happy. +$(DEFAULTER_GEN): + hack/make-rules/build.sh cmd/libs/go2idl/defaulter-gen + touch $@ + # # Open-api generation # @@ -427,7 +567,7 @@ gen_conversion: $(CONVERSION_FILES) if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ ./hack/run-in-gopath.sh $(CONVERSION_GEN) \ --v $(KUBE_VERBOSE) \ - --logtostderr \ + --logtostderr \ -i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \ -O $(CONVERSION_BASENAME); \ fi From 4324e39393cbbf797c616c8f8c4119e2d8b9d3ef Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 17:25:43 -0400 Subject: [PATCH 07/15] Flag all packages as needing defaulters --- federation/apis/federation/v1beta1/doc.go | 1 + pkg/api/unversioned/doc.go | 1 + pkg/api/v1/doc.go | 1 + pkg/apis/apps/v1alpha1/doc.go | 1 + pkg/apis/authentication/v1beta1/doc.go | 1 + pkg/apis/authorization/v1beta1/doc.go | 1 + pkg/apis/autoscaling/v1/doc.go | 1 + pkg/apis/batch/v1/doc.go | 1 + pkg/apis/batch/v2alpha1/doc.go | 1 + pkg/apis/certificates/v1alpha1/doc.go | 1 + pkg/apis/componentconfig/v1alpha1/doc.go | 1 + pkg/apis/extensions/v1beta1/doc.go | 1 + pkg/apis/imagepolicy/v1alpha1/doc.go | 1 + pkg/apis/policy/v1alpha1/doc.go | 1 + pkg/apis/rbac/v1alpha1/doc.go | 1 + pkg/apis/storage/v1beta1/doc.go | 1 + 16 files changed, 16 insertions(+) diff --git a/federation/apis/federation/v1beta1/doc.go b/federation/apis/federation/v1beta1/doc.go index 7f62d4cd5f1..7382fb5b8e7 100644 --- a/federation/apis/federation/v1beta1/doc.go +++ b/federation/apis/federation/v1beta1/doc.go @@ -17,4 +17,5 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/federation/apis/federation // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1beta1 // import "k8s.io/kubernetes/federation/apis/federation/v1beta1" diff --git a/pkg/api/unversioned/doc.go b/pkg/api/unversioned/doc.go index c08dc3e1931..2bc11a625be 100644 --- a/pkg/api/unversioned/doc.go +++ b/pkg/api/unversioned/doc.go @@ -16,5 +16,6 @@ limitations under the License. // +k8s:deepcopy-gen=package // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package unversioned // import "k8s.io/kubernetes/pkg/api/unversioned" diff --git a/pkg/api/v1/doc.go b/pkg/api/v1/doc.go index d9680b63de1..e97948d4919 100644 --- a/pkg/api/v1/doc.go +++ b/pkg/api/v1/doc.go @@ -17,6 +17,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/api // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta // Package v1 is the v1 version of the API. package v1 // import "k8s.io/kubernetes/pkg/api/v1" diff --git a/pkg/apis/apps/v1alpha1/doc.go b/pkg/apis/apps/v1alpha1/doc.go index 16c1b593010..71203b782f4 100644 --- a/pkg/apis/apps/v1alpha1/doc.go +++ b/pkg/apis/apps/v1alpha1/doc.go @@ -17,5 +17,6 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/apps // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/apps/v1alpha1" diff --git a/pkg/apis/authentication/v1beta1/doc.go b/pkg/apis/authentication/v1beta1/doc.go index bfb6aabc7b6..3815862e62f 100644 --- a/pkg/apis/authentication/v1beta1/doc.go +++ b/pkg/apis/authentication/v1beta1/doc.go @@ -18,4 +18,5 @@ limitations under the License. // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/authentication // +groupName=authentication.k8s.io // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1beta1 // import "k8s.io/kubernetes/pkg/apis/authentication/v1beta1" diff --git a/pkg/apis/authorization/v1beta1/doc.go b/pkg/apis/authorization/v1beta1/doc.go index b51da351d48..1007e6b1823 100644 --- a/pkg/apis/authorization/v1beta1/doc.go +++ b/pkg/apis/authorization/v1beta1/doc.go @@ -17,6 +17,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/authorization // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta // +groupName=authorization.k8s.io package v1beta1 // import "k8s.io/kubernetes/pkg/apis/authorization/v1beta1" diff --git a/pkg/apis/autoscaling/v1/doc.go b/pkg/apis/autoscaling/v1/doc.go index e8cacc8c869..678ebf1bae4 100644 --- a/pkg/apis/autoscaling/v1/doc.go +++ b/pkg/apis/autoscaling/v1/doc.go @@ -17,5 +17,6 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/autoscaling // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1 // import "k8s.io/kubernetes/pkg/apis/autoscaling/v1" diff --git a/pkg/apis/batch/v1/doc.go b/pkg/apis/batch/v1/doc.go index 32ae7506354..787717b2139 100644 --- a/pkg/apis/batch/v1/doc.go +++ b/pkg/apis/batch/v1/doc.go @@ -17,5 +17,6 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/batch // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1 // import "k8s.io/kubernetes/pkg/apis/batch/v1" diff --git a/pkg/apis/batch/v2alpha1/doc.go b/pkg/apis/batch/v2alpha1/doc.go index edf699838be..fb00a5be9ef 100644 --- a/pkg/apis/batch/v2alpha1/doc.go +++ b/pkg/apis/batch/v2alpha1/doc.go @@ -17,5 +17,6 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/batch // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v2alpha1 // import "k8s.io/kubernetes/pkg/apis/batch/v2alpha1" diff --git a/pkg/apis/certificates/v1alpha1/doc.go b/pkg/apis/certificates/v1alpha1/doc.go index 601cddcea22..a6409ce26cb 100644 --- a/pkg/apis/certificates/v1alpha1/doc.go +++ b/pkg/apis/certificates/v1alpha1/doc.go @@ -17,6 +17,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/certificates // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta // +groupName=certificates.k8s.io package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/certificates/v1alpha1" diff --git a/pkg/apis/componentconfig/v1alpha1/doc.go b/pkg/apis/componentconfig/v1alpha1/doc.go index d0049c6fe62..f8d91738be8 100644 --- a/pkg/apis/componentconfig/v1alpha1/doc.go +++ b/pkg/apis/componentconfig/v1alpha1/doc.go @@ -17,5 +17,6 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/componentconfig // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1" diff --git a/pkg/apis/extensions/v1beta1/doc.go b/pkg/apis/extensions/v1beta1/doc.go index 51e577ae829..f4e544e67d4 100644 --- a/pkg/apis/extensions/v1beta1/doc.go +++ b/pkg/apis/extensions/v1beta1/doc.go @@ -19,5 +19,6 @@ limitations under the License. // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/autoscaling // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/batch // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1beta1 // import "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" diff --git a/pkg/apis/imagepolicy/v1alpha1/doc.go b/pkg/apis/imagepolicy/v1alpha1/doc.go index f0877a485a6..87873724b62 100644 --- a/pkg/apis/imagepolicy/v1alpha1/doc.go +++ b/pkg/apis/imagepolicy/v1alpha1/doc.go @@ -17,6 +17,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/imagepolicy // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta // +groupName=imagepolicy.k8s.io package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/imagepolicy/v1alpha1" diff --git a/pkg/apis/policy/v1alpha1/doc.go b/pkg/apis/policy/v1alpha1/doc.go index b5f2a064a35..510c600f323 100644 --- a/pkg/apis/policy/v1alpha1/doc.go +++ b/pkg/apis/policy/v1alpha1/doc.go @@ -16,6 +16,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/policy +// +k8s:defaulter-gen=TypeMeta // Package policy is for any kind of policy object. Suitable examples, even if // they aren't all here, are PodDisruptionBudget, PodSecurityPolicy, diff --git a/pkg/apis/rbac/v1alpha1/doc.go b/pkg/apis/rbac/v1alpha1/doc.go index 5249e6e3f9a..3e22c9a0653 100644 --- a/pkg/apis/rbac/v1alpha1/doc.go +++ b/pkg/apis/rbac/v1alpha1/doc.go @@ -17,6 +17,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/rbac // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta // +groupName=rbac.authorization.k8s.io package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/rbac/v1alpha1" diff --git a/pkg/apis/storage/v1beta1/doc.go b/pkg/apis/storage/v1beta1/doc.go index ccd5598dbac..b0be7644e09 100644 --- a/pkg/apis/storage/v1beta1/doc.go +++ b/pkg/apis/storage/v1beta1/doc.go @@ -18,4 +18,5 @@ limitations under the License. // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/storage // +groupName=storage.k8s.io // +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta package v1beta1 // import "k8s.io/kubernetes/pkg/apis/storage/v1beta1" From 745690a2d46a1b0e3091b038a08d4ae30317139f Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 17:39:18 -0400 Subject: [PATCH 08/15] generated: Defaulters --- pkg/api/v1/zz_generated.defaults.go | 539 +++++++++++++++++ .../apps/v1alpha1/zz_generated.defaults.go | 159 +++++ .../autoscaling/v1/zz_generated.defaults.go | 47 ++ pkg/apis/batch/v1/zz_generated.defaults.go | 155 +++++ .../batch/v2alpha1/zz_generated.defaults.go | 390 +++++++++++++ .../v1alpha1/zz_generated.defaults.go | 48 ++ .../v1beta1/zz_generated.defaults.go | 549 ++++++++++++++++++ .../rbac/v1alpha1/zz_generated.conversion.go | 2 + .../rbac/v1alpha1/zz_generated.defaults.go | 58 ++ 9 files changed, 1947 insertions(+) create mode 100644 pkg/api/v1/zz_generated.defaults.go create mode 100644 pkg/apis/apps/v1alpha1/zz_generated.defaults.go create mode 100644 pkg/apis/autoscaling/v1/zz_generated.defaults.go create mode 100644 pkg/apis/batch/v1/zz_generated.defaults.go create mode 100644 pkg/apis/batch/v2alpha1/zz_generated.defaults.go create mode 100644 pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go create mode 100644 pkg/apis/extensions/v1beta1/zz_generated.defaults.go create mode 100644 pkg/apis/rbac/v1alpha1/zz_generated.defaults.go diff --git a/pkg/api/v1/zz_generated.defaults.go b/pkg/api/v1/zz_generated.defaults.go new file mode 100644 index 00000000000..0b5e32bca22 --- /dev/null +++ b/pkg/api/v1/zz_generated.defaults.go @@ -0,0 +1,539 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1 + +import ( + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&ConfigMap{}, func(obj interface{}) { SetObjectDefaults_ConfigMap(obj.(*ConfigMap)) }) + scheme.AddTypeDefaultingFunc(&ConfigMapList{}, func(obj interface{}) { SetObjectDefaults_ConfigMapList(obj.(*ConfigMapList)) }) + scheme.AddTypeDefaultingFunc(&Endpoints{}, func(obj interface{}) { SetObjectDefaults_Endpoints(obj.(*Endpoints)) }) + scheme.AddTypeDefaultingFunc(&EndpointsList{}, func(obj interface{}) { SetObjectDefaults_EndpointsList(obj.(*EndpointsList)) }) + scheme.AddTypeDefaultingFunc(&LimitRange{}, func(obj interface{}) { SetObjectDefaults_LimitRange(obj.(*LimitRange)) }) + scheme.AddTypeDefaultingFunc(&LimitRangeList{}, func(obj interface{}) { SetObjectDefaults_LimitRangeList(obj.(*LimitRangeList)) }) + scheme.AddTypeDefaultingFunc(&Namespace{}, func(obj interface{}) { SetObjectDefaults_Namespace(obj.(*Namespace)) }) + scheme.AddTypeDefaultingFunc(&NamespaceList{}, func(obj interface{}) { SetObjectDefaults_NamespaceList(obj.(*NamespaceList)) }) + scheme.AddTypeDefaultingFunc(&Node{}, func(obj interface{}) { SetObjectDefaults_Node(obj.(*Node)) }) + scheme.AddTypeDefaultingFunc(&NodeList{}, func(obj interface{}) { SetObjectDefaults_NodeList(obj.(*NodeList)) }) + scheme.AddTypeDefaultingFunc(&PersistentVolume{}, func(obj interface{}) { SetObjectDefaults_PersistentVolume(obj.(*PersistentVolume)) }) + scheme.AddTypeDefaultingFunc(&PersistentVolumeClaim{}, func(obj interface{}) { SetObjectDefaults_PersistentVolumeClaim(obj.(*PersistentVolumeClaim)) }) + scheme.AddTypeDefaultingFunc(&PersistentVolumeClaimList{}, func(obj interface{}) { SetObjectDefaults_PersistentVolumeClaimList(obj.(*PersistentVolumeClaimList)) }) + scheme.AddTypeDefaultingFunc(&PersistentVolumeList{}, func(obj interface{}) { SetObjectDefaults_PersistentVolumeList(obj.(*PersistentVolumeList)) }) + scheme.AddTypeDefaultingFunc(&Pod{}, func(obj interface{}) { SetObjectDefaults_Pod(obj.(*Pod)) }) + scheme.AddTypeDefaultingFunc(&PodAttachOptions{}, func(obj interface{}) { SetObjectDefaults_PodAttachOptions(obj.(*PodAttachOptions)) }) + scheme.AddTypeDefaultingFunc(&PodExecOptions{}, func(obj interface{}) { SetObjectDefaults_PodExecOptions(obj.(*PodExecOptions)) }) + scheme.AddTypeDefaultingFunc(&PodList{}, func(obj interface{}) { SetObjectDefaults_PodList(obj.(*PodList)) }) + scheme.AddTypeDefaultingFunc(&PodTemplate{}, func(obj interface{}) { SetObjectDefaults_PodTemplate(obj.(*PodTemplate)) }) + scheme.AddTypeDefaultingFunc(&PodTemplateList{}, func(obj interface{}) { SetObjectDefaults_PodTemplateList(obj.(*PodTemplateList)) }) + scheme.AddTypeDefaultingFunc(&ReplicationController{}, func(obj interface{}) { SetObjectDefaults_ReplicationController(obj.(*ReplicationController)) }) + scheme.AddTypeDefaultingFunc(&ReplicationControllerList{}, func(obj interface{}) { SetObjectDefaults_ReplicationControllerList(obj.(*ReplicationControllerList)) }) + scheme.AddTypeDefaultingFunc(&Secret{}, func(obj interface{}) { SetObjectDefaults_Secret(obj.(*Secret)) }) + scheme.AddTypeDefaultingFunc(&SecretList{}, func(obj interface{}) { SetObjectDefaults_SecretList(obj.(*SecretList)) }) + scheme.AddTypeDefaultingFunc(&Service{}, func(obj interface{}) { SetObjectDefaults_Service(obj.(*Service)) }) + scheme.AddTypeDefaultingFunc(&ServiceList{}, func(obj interface{}) { SetObjectDefaults_ServiceList(obj.(*ServiceList)) }) + return nil +} + +func SetObjectDefaults_ConfigMap(in *ConfigMap) { + SetDefaults_ConfigMap(in) +} + +func SetObjectDefaults_ConfigMapList(in *ConfigMapList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_ConfigMap(a) + } +} + +func SetObjectDefaults_Endpoints(in *Endpoints) { + SetDefaults_Endpoints(in) +} + +func SetObjectDefaults_EndpointsList(in *EndpointsList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Endpoints(a) + } +} + +func SetObjectDefaults_LimitRange(in *LimitRange) { + for i := range in.Spec.Limits { + a := &in.Spec.Limits[i] + SetDefaults_LimitRangeItem(a) + } +} + +func SetObjectDefaults_LimitRangeList(in *LimitRangeList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_LimitRange(a) + } +} + +func SetObjectDefaults_Namespace(in *Namespace) { + SetDefaults_NamespaceStatus(&in.Status) +} + +func SetObjectDefaults_NamespaceList(in *NamespaceList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Namespace(a) + } +} + +func SetObjectDefaults_Node(in *Node) { + SetDefaults_Node(in) + SetDefaults_NodeStatus(&in.Status) +} + +func SetObjectDefaults_NodeList(in *NodeList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Node(a) + } +} + +func SetObjectDefaults_PersistentVolume(in *PersistentVolume) { + SetDefaults_PersistentVolume(in) + if in.Spec.PersistentVolumeSource.RBD != nil { + SetDefaults_RBDVolumeSource(in.Spec.PersistentVolumeSource.RBD) + } + if in.Spec.PersistentVolumeSource.ISCSI != nil { + SetDefaults_ISCSIVolumeSource(in.Spec.PersistentVolumeSource.ISCSI) + } + if in.Spec.PersistentVolumeSource.AzureDisk != nil { + SetDefaults_AzureDiskVolumeSource(in.Spec.PersistentVolumeSource.AzureDisk) + } +} + +func SetObjectDefaults_PersistentVolumeClaim(in *PersistentVolumeClaim) { + SetDefaults_PersistentVolumeClaim(in) +} + +func SetObjectDefaults_PersistentVolumeClaimList(in *PersistentVolumeClaimList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_PersistentVolumeClaim(a) + } +} + +func SetObjectDefaults_PersistentVolumeList(in *PersistentVolumeList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_PersistentVolume(a) + } +} + +func SetObjectDefaults_Pod(in *Pod) { + SetDefaults_Pod(in) + SetDefaults_PodSpec(&in.Spec) + for i := range in.Spec.Volumes { + a := &in.Spec.Volumes[i] + SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.InitContainers { + a := &in.Spec.InitContainers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Containers { + a := &in.Spec.Containers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_PodAttachOptions(in *PodAttachOptions) { + SetDefaults_PodAttachOptions(in) +} + +func SetObjectDefaults_PodExecOptions(in *PodExecOptions) { + SetDefaults_PodExecOptions(in) +} + +func SetObjectDefaults_PodList(in *PodList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Pod(a) + } +} + +func SetObjectDefaults_PodTemplate(in *PodTemplate) { + SetDefaults_PodSpec(&in.Template.Spec) + for i := range in.Template.Spec.Volumes { + a := &in.Template.Spec.Volumes[i] + SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Template.Spec.InitContainers { + a := &in.Template.Spec.InitContainers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Template.Spec.Containers { + a := &in.Template.Spec.Containers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_PodTemplateList(in *PodTemplateList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_PodTemplate(a) + } +} + +func SetObjectDefaults_ReplicationController(in *ReplicationController) { + SetDefaults_ReplicationController(in) + if in.Spec.Template != nil { + SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + } +} + +func SetObjectDefaults_ReplicationControllerList(in *ReplicationControllerList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_ReplicationController(a) + } +} + +func SetObjectDefaults_Secret(in *Secret) { + SetDefaults_Secret(in) +} + +func SetObjectDefaults_SecretList(in *SecretList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Secret(a) + } +} + +func SetObjectDefaults_Service(in *Service) { + SetDefaults_ServiceSpec(&in.Spec) +} + +func SetObjectDefaults_ServiceList(in *ServiceList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Service(a) + } +} diff --git a/pkg/apis/apps/v1alpha1/zz_generated.defaults.go b/pkg/apis/apps/v1alpha1/zz_generated.defaults.go new file mode 100644 index 00000000000..6dd3b23ad5a --- /dev/null +++ b/pkg/apis/apps/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,159 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1alpha1 + +import ( + v1 "k8s.io/kubernetes/pkg/api/v1" + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&PetSet{}, func(obj interface{}) { SetObjectDefaults_PetSet(obj.(*PetSet)) }) + scheme.AddTypeDefaultingFunc(&PetSetList{}, func(obj interface{}) { SetObjectDefaults_PetSetList(obj.(*PetSetList)) }) + return nil +} + +func SetObjectDefaults_PetSet(in *PetSet) { + SetDefaults_PetSet(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.VolumeClaimTemplates { + a := &in.Spec.VolumeClaimTemplates[i] + v1.SetDefaults_PersistentVolumeClaim(a) + } +} + +func SetObjectDefaults_PetSetList(in *PetSetList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_PetSet(a) + } +} diff --git a/pkg/apis/autoscaling/v1/zz_generated.defaults.go b/pkg/apis/autoscaling/v1/zz_generated.defaults.go new file mode 100644 index 00000000000..6d43b1a244b --- /dev/null +++ b/pkg/apis/autoscaling/v1/zz_generated.defaults.go @@ -0,0 +1,47 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1 + +import ( + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&HorizontalPodAutoscaler{}, func(obj interface{}) { SetObjectDefaults_HorizontalPodAutoscaler(obj.(*HorizontalPodAutoscaler)) }) + scheme.AddTypeDefaultingFunc(&HorizontalPodAutoscalerList{}, func(obj interface{}) { + SetObjectDefaults_HorizontalPodAutoscalerList(obj.(*HorizontalPodAutoscalerList)) + }) + return nil +} + +func SetObjectDefaults_HorizontalPodAutoscaler(in *HorizontalPodAutoscaler) { + SetDefaults_HorizontalPodAutoscaler(in) +} + +func SetObjectDefaults_HorizontalPodAutoscalerList(in *HorizontalPodAutoscalerList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_HorizontalPodAutoscaler(a) + } +} diff --git a/pkg/apis/batch/v1/zz_generated.defaults.go b/pkg/apis/batch/v1/zz_generated.defaults.go new file mode 100644 index 00000000000..b6022156b1a --- /dev/null +++ b/pkg/apis/batch/v1/zz_generated.defaults.go @@ -0,0 +1,155 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1 + +import ( + api_v1 "k8s.io/kubernetes/pkg/api/v1" + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&Job{}, func(obj interface{}) { SetObjectDefaults_Job(obj.(*Job)) }) + scheme.AddTypeDefaultingFunc(&JobList{}, func(obj interface{}) { SetObjectDefaults_JobList(obj.(*JobList)) }) + return nil +} + +func SetObjectDefaults_Job(in *Job) { + SetDefaults_Job(in) + api_v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + api_v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + api_v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + api_v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + api_v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + api_v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + api_v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + api_v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + api_v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + api_v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + api_v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + api_v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + api_v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + api_v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + api_v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + api_v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + api_v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + api_v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + api_v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + api_v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_JobList(in *JobList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Job(a) + } +} diff --git a/pkg/apis/batch/v2alpha1/zz_generated.defaults.go b/pkg/apis/batch/v2alpha1/zz_generated.defaults.go new file mode 100644 index 00000000000..106390ffead --- /dev/null +++ b/pkg/apis/batch/v2alpha1/zz_generated.defaults.go @@ -0,0 +1,390 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v2alpha1 + +import ( + v1 "k8s.io/kubernetes/pkg/api/v1" + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&Job{}, func(obj interface{}) { SetObjectDefaults_Job(obj.(*Job)) }) + scheme.AddTypeDefaultingFunc(&JobList{}, func(obj interface{}) { SetObjectDefaults_JobList(obj.(*JobList)) }) + scheme.AddTypeDefaultingFunc(&JobTemplate{}, func(obj interface{}) { SetObjectDefaults_JobTemplate(obj.(*JobTemplate)) }) + scheme.AddTypeDefaultingFunc(&ScheduledJob{}, func(obj interface{}) { SetObjectDefaults_ScheduledJob(obj.(*ScheduledJob)) }) + scheme.AddTypeDefaultingFunc(&ScheduledJobList{}, func(obj interface{}) { SetObjectDefaults_ScheduledJobList(obj.(*ScheduledJobList)) }) + return nil +} + +func SetObjectDefaults_Job(in *Job) { + SetDefaults_Job(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_JobList(in *JobList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Job(a) + } +} + +func SetObjectDefaults_JobTemplate(in *JobTemplate) { + v1.SetDefaults_PodSpec(&in.Template.Spec.Template.Spec) + for i := range in.Template.Spec.Template.Spec.Volumes { + a := &in.Template.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Template.Spec.Template.Spec.InitContainers { + a := &in.Template.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Template.Spec.Template.Spec.Containers { + a := &in.Template.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_ScheduledJob(in *ScheduledJob) { + SetDefaults_ScheduledJob(in) + v1.SetDefaults_PodSpec(&in.Spec.JobTemplate.Spec.Template.Spec) + for i := range in.Spec.JobTemplate.Spec.Template.Spec.Volumes { + a := &in.Spec.JobTemplate.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.JobTemplate.Spec.Template.Spec.InitContainers { + a := &in.Spec.JobTemplate.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.JobTemplate.Spec.Template.Spec.Containers { + a := &in.Spec.JobTemplate.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_ScheduledJobList(in *ScheduledJobList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_ScheduledJob(a) + } +} diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go new file mode 100644 index 00000000000..a0cf834df51 --- /dev/null +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,48 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1alpha1 + +import ( + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&KubeProxyConfiguration{}, func(obj interface{}) { SetObjectDefaults_KubeProxyConfiguration(obj.(*KubeProxyConfiguration)) }) + scheme.AddTypeDefaultingFunc(&KubeSchedulerConfiguration{}, func(obj interface{}) { SetObjectDefaults_KubeSchedulerConfiguration(obj.(*KubeSchedulerConfiguration)) }) + scheme.AddTypeDefaultingFunc(&KubeletConfiguration{}, func(obj interface{}) { SetObjectDefaults_KubeletConfiguration(obj.(*KubeletConfiguration)) }) + return nil +} + +func SetObjectDefaults_KubeProxyConfiguration(in *KubeProxyConfiguration) { + SetDefaults_KubeProxyConfiguration(in) +} + +func SetObjectDefaults_KubeSchedulerConfiguration(in *KubeSchedulerConfiguration) { + SetDefaults_KubeSchedulerConfiguration(in) + SetDefaults_LeaderElectionConfiguration(&in.LeaderElection) +} + +func SetObjectDefaults_KubeletConfiguration(in *KubeletConfiguration) { + SetDefaults_KubeletConfiguration(in) +} diff --git a/pkg/apis/extensions/v1beta1/zz_generated.defaults.go b/pkg/apis/extensions/v1beta1/zz_generated.defaults.go new file mode 100644 index 00000000000..ab8ec14069d --- /dev/null +++ b/pkg/apis/extensions/v1beta1/zz_generated.defaults.go @@ -0,0 +1,549 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1beta1 + +import ( + v1 "k8s.io/kubernetes/pkg/api/v1" + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&DaemonSet{}, func(obj interface{}) { SetObjectDefaults_DaemonSet(obj.(*DaemonSet)) }) + scheme.AddTypeDefaultingFunc(&DaemonSetList{}, func(obj interface{}) { SetObjectDefaults_DaemonSetList(obj.(*DaemonSetList)) }) + scheme.AddTypeDefaultingFunc(&Deployment{}, func(obj interface{}) { SetObjectDefaults_Deployment(obj.(*Deployment)) }) + scheme.AddTypeDefaultingFunc(&DeploymentList{}, func(obj interface{}) { SetObjectDefaults_DeploymentList(obj.(*DeploymentList)) }) + scheme.AddTypeDefaultingFunc(&HorizontalPodAutoscaler{}, func(obj interface{}) { SetObjectDefaults_HorizontalPodAutoscaler(obj.(*HorizontalPodAutoscaler)) }) + scheme.AddTypeDefaultingFunc(&HorizontalPodAutoscalerList{}, func(obj interface{}) { + SetObjectDefaults_HorizontalPodAutoscalerList(obj.(*HorizontalPodAutoscalerList)) + }) + scheme.AddTypeDefaultingFunc(&Job{}, func(obj interface{}) { SetObjectDefaults_Job(obj.(*Job)) }) + scheme.AddTypeDefaultingFunc(&JobList{}, func(obj interface{}) { SetObjectDefaults_JobList(obj.(*JobList)) }) + scheme.AddTypeDefaultingFunc(&NetworkPolicy{}, func(obj interface{}) { SetObjectDefaults_NetworkPolicy(obj.(*NetworkPolicy)) }) + scheme.AddTypeDefaultingFunc(&NetworkPolicyList{}, func(obj interface{}) { SetObjectDefaults_NetworkPolicyList(obj.(*NetworkPolicyList)) }) + scheme.AddTypeDefaultingFunc(&ReplicaSet{}, func(obj interface{}) { SetObjectDefaults_ReplicaSet(obj.(*ReplicaSet)) }) + scheme.AddTypeDefaultingFunc(&ReplicaSetList{}, func(obj interface{}) { SetObjectDefaults_ReplicaSetList(obj.(*ReplicaSetList)) }) + return nil +} + +func SetObjectDefaults_DaemonSet(in *DaemonSet) { + SetDefaults_DaemonSet(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_DaemonSetList(in *DaemonSetList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_DaemonSet(a) + } +} + +func SetObjectDefaults_Deployment(in *Deployment) { + SetDefaults_Deployment(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_DeploymentList(in *DeploymentList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Deployment(a) + } +} + +func SetObjectDefaults_HorizontalPodAutoscaler(in *HorizontalPodAutoscaler) { + SetDefaults_HorizontalPodAutoscaler(in) +} + +func SetObjectDefaults_HorizontalPodAutoscalerList(in *HorizontalPodAutoscalerList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_HorizontalPodAutoscaler(a) + } +} + +func SetObjectDefaults_Job(in *Job) { + SetDefaults_Job(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_JobList(in *JobList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_Job(a) + } +} + +func SetObjectDefaults_NetworkPolicy(in *NetworkPolicy) { + SetDefaults_NetworkPolicy(in) +} + +func SetObjectDefaults_NetworkPolicyList(in *NetworkPolicyList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_NetworkPolicy(a) + } +} + +func SetObjectDefaults_ReplicaSet(in *ReplicaSet) { + SetDefaults_ReplicaSet(in) + v1.SetDefaults_PodSpec(&in.Spec.Template.Spec) + for i := range in.Spec.Template.Spec.Volumes { + a := &in.Spec.Template.Spec.Volumes[i] + v1.SetDefaults_Volume(a) + if a.VolumeSource.Secret != nil { + v1.SetDefaults_SecretVolumeSource(a.VolumeSource.Secret) + } + if a.VolumeSource.ISCSI != nil { + v1.SetDefaults_ISCSIVolumeSource(a.VolumeSource.ISCSI) + } + if a.VolumeSource.RBD != nil { + v1.SetDefaults_RBDVolumeSource(a.VolumeSource.RBD) + } + if a.VolumeSource.DownwardAPI != nil { + v1.SetDefaults_DownwardAPIVolumeSource(a.VolumeSource.DownwardAPI) + for j := range a.VolumeSource.DownwardAPI.Items { + b := &a.VolumeSource.DownwardAPI.Items[j] + if b.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.FieldRef) + } + } + } + if a.VolumeSource.ConfigMap != nil { + v1.SetDefaults_ConfigMapVolumeSource(a.VolumeSource.ConfigMap) + } + if a.VolumeSource.AzureDisk != nil { + v1.SetDefaults_AzureDiskVolumeSource(a.VolumeSource.AzureDisk) + } + } + for i := range in.Spec.Template.Spec.InitContainers { + a := &in.Spec.Template.Spec.InitContainers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } + for i := range in.Spec.Template.Spec.Containers { + a := &in.Spec.Template.Spec.Containers[i] + v1.SetDefaults_Container(a) + for j := range a.Ports { + b := &a.Ports[j] + v1.SetDefaults_ContainerPort(b) + } + for j := range a.Env { + b := &a.Env[j] + if b.ValueFrom != nil { + if b.ValueFrom.FieldRef != nil { + v1.SetDefaults_ObjectFieldSelector(b.ValueFrom.FieldRef) + } + } + } + if a.LivenessProbe != nil { + v1.SetDefaults_Probe(a.LivenessProbe) + if a.LivenessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.LivenessProbe.Handler.HTTPGet) + } + } + if a.ReadinessProbe != nil { + v1.SetDefaults_Probe(a.ReadinessProbe) + if a.ReadinessProbe.Handler.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.ReadinessProbe.Handler.HTTPGet) + } + } + if a.Lifecycle != nil { + if a.Lifecycle.PostStart != nil { + if a.Lifecycle.PostStart.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PostStart.HTTPGet) + } + } + if a.Lifecycle.PreStop != nil { + if a.Lifecycle.PreStop.HTTPGet != nil { + v1.SetDefaults_HTTPGetAction(a.Lifecycle.PreStop.HTTPGet) + } + } + } + } +} + +func SetObjectDefaults_ReplicaSetList(in *ReplicaSetList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_ReplicaSet(a) + } +} diff --git a/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go b/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go index 95a777ea240..4caebc2674a 100644 --- a/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go @@ -113,6 +113,7 @@ func Convert_rbac_ClusterRole_To_v1alpha1_ClusterRole(in *rbac.ClusterRole, out } func autoConvert_v1alpha1_ClusterRoleBinding_To_rbac_ClusterRoleBinding(in *ClusterRoleBinding, out *rbac.ClusterRoleBinding, s conversion.Scope) error { + SetDefaults_ClusterRoleBinding(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -355,6 +356,7 @@ func Convert_rbac_Role_To_v1alpha1_Role(in *rbac.Role, out *Role, s conversion.S } func autoConvert_v1alpha1_RoleBinding_To_rbac_RoleBinding(in *RoleBinding, out *rbac.RoleBinding, s conversion.Scope) error { + SetDefaults_RoleBinding(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/rbac/v1alpha1/zz_generated.defaults.go b/pkg/apis/rbac/v1alpha1/zz_generated.defaults.go new file mode 100644 index 00000000000..05e68f657ba --- /dev/null +++ b/pkg/apis/rbac/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,58 @@ +// +build !ignore_autogenerated + +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by defaulter-gen. Do not edit it manually! + +package v1alpha1 + +import ( + runtime "k8s.io/kubernetes/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&ClusterRoleBinding{}, func(obj interface{}) { SetObjectDefaults_ClusterRoleBinding(obj.(*ClusterRoleBinding)) }) + scheme.AddTypeDefaultingFunc(&ClusterRoleBindingList{}, func(obj interface{}) { SetObjectDefaults_ClusterRoleBindingList(obj.(*ClusterRoleBindingList)) }) + scheme.AddTypeDefaultingFunc(&RoleBinding{}, func(obj interface{}) { SetObjectDefaults_RoleBinding(obj.(*RoleBinding)) }) + scheme.AddTypeDefaultingFunc(&RoleBindingList{}, func(obj interface{}) { SetObjectDefaults_RoleBindingList(obj.(*RoleBindingList)) }) + return nil +} + +func SetObjectDefaults_ClusterRoleBinding(in *ClusterRoleBinding) { + SetDefaults_ClusterRoleBinding(in) +} + +func SetObjectDefaults_ClusterRoleBindingList(in *ClusterRoleBindingList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_ClusterRoleBinding(a) + } +} + +func SetObjectDefaults_RoleBinding(in *RoleBinding) { + SetDefaults_RoleBinding(in) +} + +func SetObjectDefaults_RoleBindingList(in *RoleBindingList) { + for i := range in.Items { + a := &in.Items[i] + SetObjectDefaults_RoleBinding(a) + } +} From 89b3a0d863c0b033e963387034f56a973cff6f69 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 21:59:32 -0400 Subject: [PATCH 09/15] Register new defaulting functions --- pkg/api/v1/defaults.go | 1 + pkg/apis/apps/v1alpha1/defaults.go | 1 + pkg/apis/autoscaling/v1/defaults.go | 1 + pkg/apis/batch/v1/defaults.go | 1 + pkg/apis/batch/v2alpha1/defaults.go | 1 + pkg/apis/componentconfig/v1alpha1/defaults.go | 1 + pkg/apis/extensions/v1beta1/defaults.go | 1 + pkg/apis/rbac/v1alpha1/defaults.go | 1 + 8 files changed, 8 insertions(+) diff --git a/pkg/api/v1/defaults.go b/pkg/api/v1/defaults.go index 64120bfd8dd..2c910ec95fe 100644 --- a/pkg/api/v1/defaults.go +++ b/pkg/api/v1/defaults.go @@ -24,6 +24,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_PodExecOptions, SetDefaults_PodAttachOptions, diff --git a/pkg/apis/apps/v1alpha1/defaults.go b/pkg/apis/apps/v1alpha1/defaults.go index 63a02c9c9b6..7658c644327 100644 --- a/pkg/apis/apps/v1alpha1/defaults.go +++ b/pkg/apis/apps/v1alpha1/defaults.go @@ -22,6 +22,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_PetSet, ) diff --git a/pkg/apis/autoscaling/v1/defaults.go b/pkg/apis/autoscaling/v1/defaults.go index e374add3ba3..e81d9549056 100644 --- a/pkg/apis/autoscaling/v1/defaults.go +++ b/pkg/apis/autoscaling/v1/defaults.go @@ -21,6 +21,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_HorizontalPodAutoscaler, ) diff --git a/pkg/apis/batch/v1/defaults.go b/pkg/apis/batch/v1/defaults.go index 5b8e10a2e4f..46685ef8a91 100644 --- a/pkg/apis/batch/v1/defaults.go +++ b/pkg/apis/batch/v1/defaults.go @@ -21,6 +21,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_Job, ) diff --git a/pkg/apis/batch/v2alpha1/defaults.go b/pkg/apis/batch/v2alpha1/defaults.go index 1c06e66a4ea..af403692cf9 100644 --- a/pkg/apis/batch/v2alpha1/defaults.go +++ b/pkg/apis/batch/v2alpha1/defaults.go @@ -21,6 +21,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_Job, SetDefaults_ScheduledJob, diff --git a/pkg/apis/componentconfig/v1alpha1/defaults.go b/pkg/apis/componentconfig/v1alpha1/defaults.go index 164ac8fa062..48525b2fb67 100644 --- a/pkg/apis/componentconfig/v1alpha1/defaults.go +++ b/pkg/apis/componentconfig/v1alpha1/defaults.go @@ -51,6 +51,7 @@ const ( var zeroDuration = unversioned.Duration{} func addDefaultingFuncs(scheme *kruntime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_KubeProxyConfiguration, SetDefaults_KubeSchedulerConfiguration, diff --git a/pkg/apis/extensions/v1beta1/defaults.go b/pkg/apis/extensions/v1beta1/defaults.go index 1591808ca13..256c748dae3 100644 --- a/pkg/apis/extensions/v1beta1/defaults.go +++ b/pkg/apis/extensions/v1beta1/defaults.go @@ -23,6 +23,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_DaemonSet, SetDefaults_Deployment, diff --git a/pkg/apis/rbac/v1alpha1/defaults.go b/pkg/apis/rbac/v1alpha1/defaults.go index 2e0b17277c1..f7e46b818b3 100644 --- a/pkg/apis/rbac/v1alpha1/defaults.go +++ b/pkg/apis/rbac/v1alpha1/defaults.go @@ -21,6 +21,7 @@ import ( ) func addDefaultingFuncs(scheme *runtime.Scheme) error { + RegisterDefaults(scheme) return scheme.AddDefaultingFuncs( SetDefaults_ClusterRoleBinding, SetDefaults_RoleBinding, From 4f8d1a86e57395a93610f8421a3ed41aa20b1564 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 24 Sep 2016 23:25:31 -0400 Subject: [PATCH 10/15] Add a defaulting test that verifies old and new defaults are equivalent --- pkg/api/defaulting_test.go | 124 +++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 pkg/api/defaulting_test.go diff --git a/pkg/api/defaulting_test.go b/pkg/api/defaulting_test.go new file mode 100644 index 00000000000..77144b8da97 --- /dev/null +++ b/pkg/api/defaulting_test.go @@ -0,0 +1,124 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api_test + +import ( + "math/rand" + "reflect" + "sort" + "testing" + + "github.com/google/gofuzz" + + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/unversioned" + apiv1 "k8s.io/kubernetes/pkg/api/v1" + extensionsv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" + "k8s.io/kubernetes/pkg/runtime" + "k8s.io/kubernetes/pkg/util/diff" +) + +type orderedGroupVersionKinds []unversioned.GroupVersionKind + +func (o orderedGroupVersionKinds) Len() int { return len(o) } +func (o orderedGroupVersionKinds) Swap(i, j int) { o[i], o[j] = o[j], o[i] } +func (o orderedGroupVersionKinds) Less(i, j int) bool { + return o[i].String() < o[j].String() +} + +// TODO: add a reflexive test that verifies that all SetDefaults functions are registered + +// TODO: once we remove defaulting from conversion, convert this test to ensuring +// that all objects that say they have defaulting are verified to mutate the originating +// object. +func TestDefaulting(t *testing.T) { + f := fuzz.New().NilChance(.5).NumElements(1, 1) + f.RandSource(rand.NewSource(1)) + f.Funcs( + func(s *runtime.RawExtension, c fuzz.Continue) {}, + func(s *unversioned.LabelSelector, c fuzz.Continue) { + c.FuzzNoCustom(s) + s.MatchExpressions = nil // need to fuzz this specially + }, + func(s *apiv1.ListOptions, c fuzz.Continue) { + c.FuzzNoCustom(s) + s.LabelSelector = "" // need to fuzz requirement strings specially + s.FieldSelector = "" // need to fuzz requirement strings specially + }, + // No longer necessary when we remove defaulting from conversion + func(s *apiv1.Secret, c fuzz.Continue) { + c.FuzzNoCustom(s) + s.StringData = nil // is mapped into Data, which cannot easily be tested + }, + func(s *extensionsv1beta1.ListOptions, c fuzz.Continue) { + c.FuzzNoCustom(s) + s.LabelSelector = "" // need to fuzz requirement strings specially + s.FieldSelector = "" // need to fuzz requirement strings specially + }, + func(s *extensionsv1beta1.ScaleStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) + s.TargetSelector = "" // need to fuzz requirement strings specially + }, + ) + + scheme := api.Scheme + var testTypes orderedGroupVersionKinds + for gvk := range scheme.AllKnownTypes() { + if gvk.Version == runtime.APIVersionInternal { + continue + } + testTypes = append(testTypes, gvk) + } + sort.Sort(testTypes) + + for _, gvk := range testTypes { + for i := 0; i < *fuzzIters; i++ { + src, err := scheme.New(gvk) + if err != nil { + t.Fatal(err) + } + f.Fuzz(src) + + src.GetObjectKind().SetGroupVersionKind(unversioned.GroupVersionKind{}) + + original, _ := scheme.DeepCopy(src) + + // get internal + copied, _ := scheme.DeepCopy(src) + scheme.Default(copied.(runtime.Object)) + + // get expected + // TODO: this relies on the side effect behavior of defaulters applying to the external + // object + if _, err = scheme.UnsafeConvertToVersion(src, runtime.InternalGroupVersioner); err != nil { + t.Errorf("[%v] unable to convert: %v", gvk, err) + continue + } + src.GetObjectKind().SetGroupVersionKind(unversioned.GroupVersionKind{}) + + existingChanged := !reflect.DeepEqual(original, src) + newChanged := !reflect.DeepEqual(original, copied) + if existingChanged != newChanged { + t.Errorf("[%v] mismatched changes: old=%t new=%t", gvk, existingChanged, newChanged) + } + + if !reflect.DeepEqual(src, copied) { + t.Errorf("[%v] changed: %s", gvk, diff.ObjectReflectDiff(src, copied)) + } + } + } +} From f294175d60ac90845d73cd9bde7bfcb47105be1a Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 25 Sep 2016 12:08:19 -0400 Subject: [PATCH 11/15] Make defaulting optional during conversion generation Set the Kubernetes default to "no defaulting" --- .../go2idl/conversion-gen/generators/conversion.go | 14 +++++++++++--- cmd/libs/go2idl/conversion-gen/main.go | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/libs/go2idl/conversion-gen/generators/conversion.go b/cmd/libs/go2idl/conversion-gen/generators/conversion.go index f557f759fba..e1c62c247b0 100644 --- a/cmd/libs/go2idl/conversion-gen/generators/conversion.go +++ b/cmd/libs/go2idl/conversion-gen/generators/conversion.go @@ -36,6 +36,10 @@ import ( // generator. type CustomArgs struct { ExtraPeerDirs []string // Always consider these as last-ditch possibilities for conversions. + // SkipDefaulters indicates whether defaulter functions should be a part of conversion + // This field was introduced to ease the transition to removing defaulters from conversion. + // It will be removed in 1.6. + SkipDefaulters bool } // This is the comment tag that carries parameters for conversion generation. @@ -242,10 +246,12 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat glog.V(5).Infof(" no tag") continue } + skipDefaulters := false if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { if len(customArgs.ExtraPeerDirs) > 0 { peerPkgs = append(peerPkgs, customArgs.ExtraPeerDirs...) } + skipDefaulters = customArgs.SkipDefaulters } // Make sure our peer-packages are added and fully parsed. for _, pp := range peerPkgs { @@ -261,7 +267,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat HeaderText: header, GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { return []generator.Generator{ - NewGenConversion(arguments.OutputFileBaseName, pkg.Path, manualConversions, manualDefaults, peerPkgs), + NewGenConversion(arguments.OutputFileBaseName, pkg.Path, manualConversions, manualDefaults, peerPkgs, !skipDefaulters), } }, FilterFunc: func(c *generator.Context, t *types.Type) bool { @@ -307,9 +313,10 @@ type genConversion struct { imports namer.ImportTracker types []*types.Type skippedFields map[*types.Type][]string + includeDefaulters bool } -func NewGenConversion(sanitizedName, targetPackage string, manualConversions conversionFuncMap, manualDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator { +func NewGenConversion(sanitizedName, targetPackage string, manualConversions conversionFuncMap, manualDefaulters defaulterFuncMap, peerPkgs []string, includeDefaulters bool) generator.Generator { return &genConversion{ DefaultGen: generator.DefaultGen{ OptionalName: sanitizedName, @@ -321,6 +328,7 @@ func NewGenConversion(sanitizedName, targetPackage string, manualConversions con imports: generator.NewImportTracker(), types: []*types.Type{}, skippedFields: map[*types.Type][]string{}, + includeDefaulters: includeDefaulters, } } @@ -470,7 +478,7 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene sw.Do("func auto"+nameTmpl+"(in *$.inType|raw$, out *$.outType|raw$, s $.Scope|raw$) error {\n", args) // if no defaulter of form SetDefaults_XXX is defined, do not inline a check for defaulting. - if function, ok := g.manualDefaulters[inType]; ok { + if function, ok := g.manualDefaulters[inType]; ok && g.includeDefaulters { sw.Do("$.|raw$(in)\n", function) } g.generateFor(inType, outType, sw) diff --git a/cmd/libs/go2idl/conversion-gen/main.go b/cmd/libs/go2idl/conversion-gen/main.go index 79f515e5ad0..097c0ea8dba 100644 --- a/cmd/libs/go2idl/conversion-gen/main.go +++ b/cmd/libs/go2idl/conversion-gen/main.go @@ -60,6 +60,7 @@ func main() { "k8s.io/kubernetes/pkg/conversion", "k8s.io/kubernetes/pkg/runtime", }, + SkipDefaulters: true, } pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs, "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.") From 742fb698d4dd2c68284201a505b1976138cc931a Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 25 Sep 2016 12:09:15 -0400 Subject: [PATCH 12/15] generated: Remove defaulting from conversion --- pkg/api/v1/zz_generated.conversion.go | 27 ------------------- .../apps/v1alpha1/zz_generated.conversion.go | 1 - .../autoscaling/v1/zz_generated.conversion.go | 1 - pkg/apis/batch/v1/zz_generated.conversion.go | 1 - .../batch/v2alpha1/zz_generated.conversion.go | 2 -- .../v1alpha1/zz_generated.conversion.go | 4 --- .../v1beta1/zz_generated.conversion.go | 6 ----- .../rbac/v1alpha1/zz_generated.conversion.go | 2 -- 8 files changed, 44 deletions(-) diff --git a/pkg/api/v1/zz_generated.conversion.go b/pkg/api/v1/zz_generated.conversion.go index 24c5f828195..040de9a3418 100644 --- a/pkg/api/v1/zz_generated.conversion.go +++ b/pkg/api/v1/zz_generated.conversion.go @@ -502,7 +502,6 @@ func Convert_api_AvoidPods_To_v1_AvoidPods(in *api.AvoidPods, out *AvoidPods, s } func autoConvert_v1_AzureDiskVolumeSource_To_api_AzureDiskVolumeSource(in *AzureDiskVolumeSource, out *api.AzureDiskVolumeSource, s conversion.Scope) error { - SetDefaults_AzureDiskVolumeSource(in) out.DiskName = in.DiskName out.DataDiskURI = in.DataDiskURI if in.CachingMode != nil { @@ -839,7 +838,6 @@ func Convert_api_ComponentStatusList_To_v1_ComponentStatusList(in *api.Component } func autoConvert_v1_ConfigMap_To_api_ConfigMap(in *ConfigMap, out *api.ConfigMap, s conversion.Scope) error { - SetDefaults_ConfigMap(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -944,7 +942,6 @@ func Convert_api_ConfigMapList_To_v1_ConfigMapList(in *api.ConfigMapList, out *C } func autoConvert_v1_ConfigMapVolumeSource_To_api_ConfigMapVolumeSource(in *ConfigMapVolumeSource, out *api.ConfigMapVolumeSource, s conversion.Scope) error { - SetDefaults_ConfigMapVolumeSource(in) if err := Convert_v1_LocalObjectReference_To_api_LocalObjectReference(&in.LocalObjectReference, &out.LocalObjectReference, s); err != nil { return err } @@ -991,7 +988,6 @@ func Convert_api_ConfigMapVolumeSource_To_v1_ConfigMapVolumeSource(in *api.Confi } func autoConvert_v1_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error { - SetDefaults_Container(in) out.Name = in.Name out.Image = in.Image out.Command = in.Command @@ -1192,7 +1188,6 @@ func Convert_api_ContainerImage_To_v1_ContainerImage(in *api.ContainerImage, out } func autoConvert_v1_ContainerPort_To_api_ContainerPort(in *ContainerPort, out *api.ContainerPort, s conversion.Scope) error { - SetDefaults_ContainerPort(in) out.Name = in.Name out.HostPort = in.HostPort out.ContainerPort = in.ContainerPort @@ -1527,7 +1522,6 @@ func Convert_api_DownwardAPIVolumeFile_To_v1_DownwardAPIVolumeFile(in *api.Downw } func autoConvert_v1_DownwardAPIVolumeSource_To_api_DownwardAPIVolumeSource(in *DownwardAPIVolumeSource, out *api.DownwardAPIVolumeSource, s conversion.Scope) error { - SetDefaults_DownwardAPIVolumeSource(in) if in.Items != nil { in, out := &in.Items, &out.Items *out = make([]api.DownwardAPIVolumeFile, len(*in)) @@ -1730,7 +1724,6 @@ func Convert_api_EndpointSubset_To_v1_EndpointSubset(in *api.EndpointSubset, out } func autoConvert_v1_Endpoints_To_api_Endpoints(in *Endpoints, out *api.Endpoints, s conversion.Scope) error { - SetDefaults_Endpoints(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -2285,7 +2278,6 @@ func Convert_api_GlusterfsVolumeSource_To_v1_GlusterfsVolumeSource(in *api.Glust } func autoConvert_v1_HTTPGetAction_To_api_HTTPGetAction(in *HTTPGetAction, out *api.HTTPGetAction, s conversion.Scope) error { - SetDefaults_HTTPGetAction(in) out.Path = in.Path if err := api.Convert_intstr_IntOrString_To_intstr_IntOrString(&in.Port, &out.Port, s); err != nil { return err @@ -2444,7 +2436,6 @@ func Convert_api_HostPathVolumeSource_To_v1_HostPathVolumeSource(in *api.HostPat } func autoConvert_v1_ISCSIVolumeSource_To_api_ISCSIVolumeSource(in *ISCSIVolumeSource, out *api.ISCSIVolumeSource, s conversion.Scope) error { - SetDefaults_ISCSIVolumeSource(in) out.TargetPortal = in.TargetPortal out.IQN = in.IQN out.Lun = in.Lun @@ -2581,7 +2572,6 @@ func Convert_api_LimitRange_To_v1_LimitRange(in *api.LimitRange, out *LimitRange } func autoConvert_v1_LimitRangeItem_To_api_LimitRangeItem(in *LimitRangeItem, out *api.LimitRangeItem, s conversion.Scope) error { - SetDefaults_LimitRangeItem(in) out.Type = api.LimitType(in.Type) if err := Convert_v1_ResourceList_To_api_ResourceList(&in.Max, &out.Max, s); err != nil { return err @@ -3080,7 +3070,6 @@ func Convert_api_NamespaceSpec_To_v1_NamespaceSpec(in *api.NamespaceSpec, out *N } func autoConvert_v1_NamespaceStatus_To_api_NamespaceStatus(in *NamespaceStatus, out *api.NamespaceStatus, s conversion.Scope) error { - SetDefaults_NamespaceStatus(in) out.Phase = api.NamespacePhase(in.Phase) return nil } @@ -3099,7 +3088,6 @@ func Convert_api_NamespaceStatus_To_v1_NamespaceStatus(in *api.NamespaceStatus, } func autoConvert_v1_Node_To_api_Node(in *Node, out *api.Node, s conversion.Scope) error { - SetDefaults_Node(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -3470,7 +3458,6 @@ func Convert_api_NodeSpec_To_v1_NodeSpec(in *api.NodeSpec, out *NodeSpec, s conv } func autoConvert_v1_NodeStatus_To_api_NodeStatus(in *NodeStatus, out *api.NodeStatus, s conversion.Scope) error { - SetDefaults_NodeStatus(in) if err := Convert_v1_ResourceList_To_api_ResourceList(&in.Capacity, &out.Capacity, s); err != nil { return err } @@ -3675,7 +3662,6 @@ func Convert_api_NodeSystemInfo_To_v1_NodeSystemInfo(in *api.NodeSystemInfo, out } func autoConvert_v1_ObjectFieldSelector_To_api_ObjectFieldSelector(in *ObjectFieldSelector, out *api.ObjectFieldSelector, s conversion.Scope) error { - SetDefaults_ObjectFieldSelector(in) out.APIVersion = in.APIVersion out.FieldPath = in.FieldPath return nil @@ -3822,7 +3808,6 @@ func Convert_api_OwnerReference_To_v1_OwnerReference(in *api.OwnerReference, out } func autoConvert_v1_PersistentVolume_To_api_PersistentVolume(in *PersistentVolume, out *api.PersistentVolume, s conversion.Scope) error { - SetDefaults_PersistentVolume(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -3863,7 +3848,6 @@ func Convert_api_PersistentVolume_To_v1_PersistentVolume(in *api.PersistentVolum } func autoConvert_v1_PersistentVolumeClaim_To_api_PersistentVolumeClaim(in *PersistentVolumeClaim, out *api.PersistentVolumeClaim, s conversion.Scope) error { - SetDefaults_PersistentVolumeClaim(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -4522,7 +4506,6 @@ func Convert_api_PersistentVolumeStatus_To_v1_PersistentVolumeStatus(in *api.Per } func autoConvert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error { - SetDefaults_Pod(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -4697,7 +4680,6 @@ func Convert_api_PodAntiAffinity_To_v1_PodAntiAffinity(in *api.PodAntiAffinity, } func autoConvert_v1_PodAttachOptions_To_api_PodAttachOptions(in *PodAttachOptions, out *api.PodAttachOptions, s conversion.Scope) error { - SetDefaults_PodAttachOptions(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -4766,7 +4748,6 @@ func Convert_api_PodCondition_To_v1_PodCondition(in *api.PodCondition, out *PodC } func autoConvert_v1_PodExecOptions_To_api_PodExecOptions(in *PodExecOptions, out *api.PodExecOptions, s conversion.Scope) error { - SetDefaults_PodExecOptions(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -4984,7 +4965,6 @@ func Convert_api_PodSignature_To_v1_PodSignature(in *api.PodSignature, out *PodS } func autoConvert_v1_PodSpec_To_api_PodSpec(in *PodSpec, out *api.PodSpec, s conversion.Scope) error { - SetDefaults_PodSpec(in) if in.Volumes != nil { in, out := &in.Volumes, &out.Volumes *out = make([]api.Volume, len(*in)) @@ -5419,7 +5399,6 @@ func Convert_api_PreferredSchedulingTerm_To_v1_PreferredSchedulingTerm(in *api.P } func autoConvert_v1_Probe_To_api_Probe(in *Probe, out *api.Probe, s conversion.Scope) error { - SetDefaults_Probe(in) if err := Convert_v1_Handler_To_api_Handler(&in.Handler, &out.Handler, s); err != nil { return err } @@ -5478,7 +5457,6 @@ func Convert_api_QuobyteVolumeSource_To_v1_QuobyteVolumeSource(in *api.QuobyteVo } func autoConvert_v1_RBDVolumeSource_To_api_RBDVolumeSource(in *RBDVolumeSource, out *api.RBDVolumeSource, s conversion.Scope) error { - SetDefaults_RBDVolumeSource(in) out.CephMonitors = in.CephMonitors out.RBDImage = in.RBDImage out.FSType = in.FSType @@ -5563,7 +5541,6 @@ func Convert_api_RangeAllocation_To_v1_RangeAllocation(in *api.RangeAllocation, } func autoConvert_v1_ReplicationController_To_api_ReplicationController(in *ReplicationController, out *api.ReplicationController, s conversion.Scope) error { - SetDefaults_ReplicationController(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -6060,7 +6037,6 @@ func Convert_api_SELinuxOptions_To_v1_SELinuxOptions(in *api.SELinuxOptions, out } func autoConvert_v1_Secret_To_api_Secret(in *Secret, out *api.Secret, s conversion.Scope) error { - SetDefaults_Secret(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -6164,7 +6140,6 @@ func Convert_api_SecretList_To_v1_SecretList(in *api.SecretList, out *SecretList } func autoConvert_v1_SecretVolumeSource_To_api_SecretVolumeSource(in *SecretVolumeSource, out *api.SecretVolumeSource, s conversion.Scope) error { - SetDefaults_SecretVolumeSource(in) out.SecretName = in.SecretName if in.Items != nil { in, out := &in.Items, &out.Items @@ -6561,7 +6536,6 @@ func Convert_api_ServiceProxyOptions_To_v1_ServiceProxyOptions(in *api.ServicePr } func autoConvert_v1_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *api.ServiceSpec, s conversion.Scope) error { - SetDefaults_ServiceSpec(in) if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]api.ServicePort, len(*in)) @@ -6699,7 +6673,6 @@ func Convert_api_Toleration_To_v1_Toleration(in *api.Toleration, out *Toleration } func autoConvert_v1_Volume_To_api_Volume(in *Volume, out *api.Volume, s conversion.Scope) error { - SetDefaults_Volume(in) out.Name = in.Name if err := Convert_v1_VolumeSource_To_api_VolumeSource(&in.VolumeSource, &out.VolumeSource, s); err != nil { return err diff --git a/pkg/apis/apps/v1alpha1/zz_generated.conversion.go b/pkg/apis/apps/v1alpha1/zz_generated.conversion.go index cd86c59f72b..aa939068f12 100644 --- a/pkg/apis/apps/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/apps/v1alpha1/zz_generated.conversion.go @@ -48,7 +48,6 @@ func RegisterConversions(scheme *runtime.Scheme) error { } func autoConvert_v1alpha1_PetSet_To_apps_PetSet(in *PetSet, out *apps.PetSet, s conversion.Scope) error { - SetDefaults_PetSet(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/autoscaling/v1/zz_generated.conversion.go b/pkg/apis/autoscaling/v1/zz_generated.conversion.go index 8a6c6c2e6ce..57337f19ec5 100644 --- a/pkg/apis/autoscaling/v1/zz_generated.conversion.go +++ b/pkg/apis/autoscaling/v1/zz_generated.conversion.go @@ -77,7 +77,6 @@ func Convert_autoscaling_CrossVersionObjectReference_To_v1_CrossVersionObjectRef } func autoConvert_v1_HorizontalPodAutoscaler_To_autoscaling_HorizontalPodAutoscaler(in *HorizontalPodAutoscaler, out *autoscaling.HorizontalPodAutoscaler, s conversion.Scope) error { - SetDefaults_HorizontalPodAutoscaler(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/batch/v1/zz_generated.conversion.go b/pkg/apis/batch/v1/zz_generated.conversion.go index 3dc90d06668..2c6049e5247 100644 --- a/pkg/apis/batch/v1/zz_generated.conversion.go +++ b/pkg/apis/batch/v1/zz_generated.conversion.go @@ -55,7 +55,6 @@ func RegisterConversions(scheme *runtime.Scheme) error { } func autoConvert_v1_Job_To_batch_Job(in *Job, out *batch.Job, s conversion.Scope) error { - SetDefaults_Job(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/batch/v2alpha1/zz_generated.conversion.go b/pkg/apis/batch/v2alpha1/zz_generated.conversion.go index 862b2921f4c..0d5c33fbe2d 100644 --- a/pkg/apis/batch/v2alpha1/zz_generated.conversion.go +++ b/pkg/apis/batch/v2alpha1/zz_generated.conversion.go @@ -67,7 +67,6 @@ func RegisterConversions(scheme *runtime.Scheme) error { } func autoConvert_v2alpha1_Job_To_batch_Job(in *Job, out *batch.Job, s conversion.Scope) error { - SetDefaults_Job(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -412,7 +411,6 @@ func Convert_unversioned_LabelSelectorRequirement_To_v2alpha1_LabelSelectorRequi } func autoConvert_v2alpha1_ScheduledJob_To_batch_ScheduledJob(in *ScheduledJob, out *batch.ScheduledJob, s conversion.Scope) error { - SetDefaults_ScheduledJob(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go index ea00f46195a..be154db3acb 100644 --- a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go @@ -48,7 +48,6 @@ func RegisterConversions(scheme *runtime.Scheme) error { } func autoConvert_v1alpha1_KubeProxyConfiguration_To_componentconfig_KubeProxyConfiguration(in *KubeProxyConfiguration, out *componentconfig.KubeProxyConfiguration, s conversion.Scope) error { - SetDefaults_KubeProxyConfiguration(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -109,7 +108,6 @@ func Convert_componentconfig_KubeProxyConfiguration_To_v1alpha1_KubeProxyConfigu } func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_componentconfig_KubeSchedulerConfiguration(in *KubeSchedulerConfiguration, out *componentconfig.KubeSchedulerConfiguration, s conversion.Scope) error { - SetDefaults_KubeSchedulerConfiguration(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -164,7 +162,6 @@ func Convert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedule } func autoConvert_v1alpha1_KubeletConfiguration_To_componentconfig_KubeletConfiguration(in *KubeletConfiguration, out *componentconfig.KubeletConfiguration, s conversion.Scope) error { - SetDefaults_KubeletConfiguration(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -527,7 +524,6 @@ func Convert_componentconfig_KubeletConfiguration_To_v1alpha1_KubeletConfigurati } func autoConvert_v1alpha1_LeaderElectionConfiguration_To_componentconfig_LeaderElectionConfiguration(in *LeaderElectionConfiguration, out *componentconfig.LeaderElectionConfiguration, s conversion.Scope) error { - SetDefaults_LeaderElectionConfiguration(in) if err := api.Convert_Pointer_bool_To_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil { return err } diff --git a/pkg/apis/extensions/v1beta1/zz_generated.conversion.go b/pkg/apis/extensions/v1beta1/zz_generated.conversion.go index 7043f183224..bacaa4b4e80 100644 --- a/pkg/apis/extensions/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/extensions/v1beta1/zz_generated.conversion.go @@ -319,7 +319,6 @@ func Convert_extensions_CustomMetricTargetList_To_v1beta1_CustomMetricTargetList } func autoConvert_v1beta1_DaemonSet_To_extensions_DaemonSet(in *DaemonSet, out *extensions.DaemonSet, s conversion.Scope) error { - SetDefaults_DaemonSet(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -476,7 +475,6 @@ func Convert_extensions_DaemonSetStatus_To_v1beta1_DaemonSetStatus(in *extension } func autoConvert_v1beta1_Deployment_To_extensions_Deployment(in *Deployment, out *extensions.Deployment, s conversion.Scope) error { - SetDefaults_Deployment(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -851,7 +849,6 @@ func Convert_extensions_HTTPIngressRuleValue_To_v1beta1_HTTPIngressRuleValue(in } func autoConvert_v1beta1_HorizontalPodAutoscaler_To_autoscaling_HorizontalPodAutoscaler(in *HorizontalPodAutoscaler, out *autoscaling.HorizontalPodAutoscaler, s conversion.Scope) error { - SetDefaults_HorizontalPodAutoscaler(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -1322,7 +1319,6 @@ func Convert_extensions_IngressTLS_To_v1beta1_IngressTLS(in *extensions.IngressT } func autoConvert_v1beta1_Job_To_batch_Job(in *Job, out *batch.Job, s conversion.Scope) error { - SetDefaults_Job(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -1601,7 +1597,6 @@ func Convert_unversioned_LabelSelectorRequirement_To_v1beta1_LabelSelectorRequir } func autoConvert_v1beta1_NetworkPolicy_To_extensions_NetworkPolicy(in *NetworkPolicy, out *extensions.NetworkPolicy, s conversion.Scope) error { - SetDefaults_NetworkPolicy(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -2106,7 +2101,6 @@ func Convert_extensions_PodSecurityPolicySpec_To_v1beta1_PodSecurityPolicySpec(i } func autoConvert_v1beta1_ReplicaSet_To_extensions_ReplicaSet(in *ReplicaSet, out *extensions.ReplicaSet, s conversion.Scope) error { - SetDefaults_ReplicaSet(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } diff --git a/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go b/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go index 4caebc2674a..95a777ea240 100644 --- a/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/rbac/v1alpha1/zz_generated.conversion.go @@ -113,7 +113,6 @@ func Convert_rbac_ClusterRole_To_v1alpha1_ClusterRole(in *rbac.ClusterRole, out } func autoConvert_v1alpha1_ClusterRoleBinding_To_rbac_ClusterRoleBinding(in *ClusterRoleBinding, out *rbac.ClusterRoleBinding, s conversion.Scope) error { - SetDefaults_ClusterRoleBinding(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -356,7 +355,6 @@ func Convert_rbac_Role_To_v1alpha1_Role(in *rbac.Role, out *Role, s conversion.S } func autoConvert_v1alpha1_RoleBinding_To_rbac_RoleBinding(in *RoleBinding, out *rbac.RoleBinding, s conversion.Scope) error { - SetDefaults_RoleBinding(in) if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } From 1694cfb72dc70fdab57ad84c43b4f1a981c1d98a Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 25 Sep 2016 12:09:52 -0400 Subject: [PATCH 13/15] Make defaulting part of versioning codec Most normal codec use should perform defaulting. DirectCodecs should not perform defaulting. Update the defaulting_test to fuzz the list of known defaulters. Use the new versioning.NewDefaultingCodec() method. --- pkg/api/defaulting_test.go | 150 +++++++++++++----- .../clientcmd/api/latest/latest.go | 2 +- pkg/runtime/codec.go | 18 +++ pkg/runtime/interfaces.go | 6 + pkg/runtime/serializer/codec_factory.go | 4 +- .../serializer/versioning/versioning.go | 47 +++++- .../serializer/versioning/versioning_test.go | 6 +- plugin/pkg/scheduler/api/latest/latest.go | 2 +- test/integration/framework/serializer.go | 4 +- 9 files changed, 191 insertions(+), 48 deletions(-) diff --git a/pkg/api/defaulting_test.go b/pkg/api/defaulting_test.go index 77144b8da97..6988b68a243 100644 --- a/pkg/api/defaulting_test.go +++ b/pkg/api/defaulting_test.go @@ -1,5 +1,5 @@ /* -Copyright 2015 The Kubernetes Authors. +Copyright 2016 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/unversioned" apiv1 "k8s.io/kubernetes/pkg/api/v1" + batchv2alpha1 "k8s.io/kubernetes/pkg/apis/batch/v2alpha1" extensionsv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/util/diff" @@ -40,14 +41,73 @@ func (o orderedGroupVersionKinds) Less(i, j int) bool { return o[i].String() < o[j].String() } -// TODO: add a reflexive test that verifies that all SetDefaults functions are registered +func TestVerifyDefaulting(t *testing.T) { + job := &batchv2alpha1.JobTemplate{} + batchv2alpha1.SetObjectDefaults_JobTemplate(job) + if job.Template.Spec.Template.Spec.DNSPolicy != apiv1.DNSClusterFirst { + t.Errorf("unexpected defaulting: %#v", job) + } +} -// TODO: once we remove defaulting from conversion, convert this test to ensuring -// that all objects that say they have defaulting are verified to mutate the originating -// object. +// TODO: add a reflexive test that verifies that all SetDefaults functions are registered func TestDefaulting(t *testing.T) { - f := fuzz.New().NilChance(.5).NumElements(1, 1) - f.RandSource(rand.NewSource(1)) + // these are the known types with defaulters - you must add to this list if you add a top level defaulter + typesWithDefaulting := map[unversioned.GroupVersionKind]struct{}{ + {Group: "", Version: "v1", Kind: "ConfigMap"}: {}, + {Group: "", Version: "v1", Kind: "ConfigMapList"}: {}, + {Group: "", Version: "v1", Kind: "Endpoints"}: {}, + {Group: "", Version: "v1", Kind: "EndpointsList"}: {}, + {Group: "", Version: "v1", Kind: "Namespace"}: {}, + {Group: "", Version: "v1", Kind: "NamespaceList"}: {}, + {Group: "", Version: "v1", Kind: "Node"}: {}, + {Group: "", Version: "v1", Kind: "NodeList"}: {}, + {Group: "", Version: "v1", Kind: "PersistentVolume"}: {}, + {Group: "", Version: "v1", Kind: "PersistentVolumeList"}: {}, + {Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}: {}, + {Group: "", Version: "v1", Kind: "PersistentVolumeClaimList"}: {}, + {Group: "", Version: "v1", Kind: "PodAttachOptions"}: {}, + {Group: "", Version: "v1", Kind: "PodExecOptions"}: {}, + {Group: "", Version: "v1", Kind: "Pod"}: {}, + {Group: "", Version: "v1", Kind: "PodList"}: {}, + {Group: "", Version: "v1", Kind: "PodTemplate"}: {}, + {Group: "", Version: "v1", Kind: "PodTemplateList"}: {}, + {Group: "", Version: "v1", Kind: "ReplicationController"}: {}, + {Group: "", Version: "v1", Kind: "ReplicationControllerList"}: {}, + {Group: "", Version: "v1", Kind: "Secret"}: {}, + {Group: "", Version: "v1", Kind: "SecretList"}: {}, + {Group: "", Version: "v1", Kind: "Service"}: {}, + {Group: "", Version: "v1", Kind: "ServiceList"}: {}, + {Group: "apps", Version: "v1alpha1", Kind: "PetSet"}: {}, + {Group: "apps", Version: "v1alpha1", Kind: "PetSetList"}: {}, + {Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"}: {}, + {Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscalerList"}: {}, + {Group: "batch", Version: "v1", Kind: "Job"}: {}, + {Group: "batch", Version: "v1", Kind: "JobList"}: {}, + {Group: "batch", Version: "v2alpha1", Kind: "Job"}: {}, + {Group: "batch", Version: "v2alpha1", Kind: "JobList"}: {}, + {Group: "batch", Version: "v2alpha1", Kind: "JobTemplate"}: {}, + {Group: "batch", Version: "v2alpha1", Kind: "ScheduledJob"}: {}, + {Group: "batch", Version: "v2alpha1", Kind: "ScheduledJobList"}: {}, + {Group: "componentconfig", Version: "v1alpha1", Kind: "KubeProxyConfiguration"}: {}, + {Group: "componentconfig", Version: "v1alpha1", Kind: "KubeSchedulerConfiguration"}: {}, + {Group: "componentconfig", Version: "v1alpha1", Kind: "KubeletConfiguration"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "DaemonSet"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "DaemonSetList"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "Deployment"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "DeploymentList"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "HorizontalPodAutoscaler"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "HorizontalPodAutoscalerList"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "Job"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "JobList"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "ReplicaSet"}: {}, + {Group: "extensions", Version: "v1beta1", Kind: "ReplicaSetList"}: {}, + {Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "ClusterRoleBinding"}: {}, + {Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "ClusterRoleBindingList"}: {}, + {Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "RoleBinding"}: {}, + {Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "RoleBindingList"}: {}, + } + + f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1)) f.Funcs( func(s *runtime.RawExtension, c fuzz.Continue) {}, func(s *unversioned.LabelSelector, c fuzz.Continue) { @@ -59,16 +119,6 @@ func TestDefaulting(t *testing.T) { s.LabelSelector = "" // need to fuzz requirement strings specially s.FieldSelector = "" // need to fuzz requirement strings specially }, - // No longer necessary when we remove defaulting from conversion - func(s *apiv1.Secret, c fuzz.Continue) { - c.FuzzNoCustom(s) - s.StringData = nil // is mapped into Data, which cannot easily be tested - }, - func(s *extensionsv1beta1.ListOptions, c fuzz.Continue) { - c.FuzzNoCustom(s) - s.LabelSelector = "" // need to fuzz requirement strings specially - s.FieldSelector = "" // need to fuzz requirement strings specially - }, func(s *extensionsv1beta1.ScaleStatus, c fuzz.Continue) { c.FuzzNoCustom(s) s.TargetSelector = "" // need to fuzz requirement strings specially @@ -86,7 +136,23 @@ func TestDefaulting(t *testing.T) { sort.Sort(testTypes) for _, gvk := range testTypes { - for i := 0; i < *fuzzIters; i++ { + _, expectedChanged := typesWithDefaulting[gvk] + iter := 0 + changedOnce := false + for { + if iter > *fuzzIters { + if !expectedChanged || changedOnce { + break + } + if iter > 200 { + t.Errorf("expected %s to trigger defaulting due to fuzzing", gvk) + break + } + // if we expected defaulting, continue looping until the fuzzer gives us one + // at worst, we will timeout + } + iter++ + src, err := scheme.New(gvk) if err != nil { t.Fatal(err) @@ -95,30 +161,38 @@ func TestDefaulting(t *testing.T) { src.GetObjectKind().SetGroupVersionKind(unversioned.GroupVersionKind{}) - original, _ := scheme.DeepCopy(src) + original, err := scheme.DeepCopy(src) + if err != nil { + t.Fatal(err) + } // get internal - copied, _ := scheme.DeepCopy(src) - scheme.Default(copied.(runtime.Object)) + withDefaults, _ := scheme.DeepCopy(src) + scheme.Default(withDefaults.(runtime.Object)) - // get expected - // TODO: this relies on the side effect behavior of defaulters applying to the external - // object - if _, err = scheme.UnsafeConvertToVersion(src, runtime.InternalGroupVersioner); err != nil { - t.Errorf("[%v] unable to convert: %v", gvk, err) - continue - } - src.GetObjectKind().SetGroupVersionKind(unversioned.GroupVersionKind{}) - - existingChanged := !reflect.DeepEqual(original, src) - newChanged := !reflect.DeepEqual(original, copied) - if existingChanged != newChanged { - t.Errorf("[%v] mismatched changes: old=%t new=%t", gvk, existingChanged, newChanged) - } - - if !reflect.DeepEqual(src, copied) { - t.Errorf("[%v] changed: %s", gvk, diff.ObjectReflectDiff(src, copied)) + if !reflect.DeepEqual(original, withDefaults) { + changedOnce = true + if !expectedChanged { + t.Errorf("{Group: \"%s\", Version: \"%s\", Kind: \"%s\"} did not expect defaults to be set - update expected or check defaulter registering: %s", gvk.Group, gvk.Version, gvk.Kind, diff.ObjectReflectDiff(original, withDefaults)) + } } } } } + +func BenchmarkPodDefaulting(b *testing.B) { + f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1)) + items := make([]apiv1.Pod, 100) + for i := range items { + f.Fuzz(&items[i]) + } + + scheme := api.Scheme + b.ResetTimer() + for i := 0; i < b.N; i++ { + pod := &items[i%len(items)] + + scheme.Default(pod) + } + b.StopTimer() +} diff --git a/pkg/client/unversioned/clientcmd/api/latest/latest.go b/pkg/client/unversioned/clientcmd/api/latest/latest.go index a32b251c77c..40a08a434e7 100644 --- a/pkg/client/unversioned/clientcmd/api/latest/latest.go +++ b/pkg/client/unversioned/clientcmd/api/latest/latest.go @@ -56,7 +56,7 @@ func init() { panic(err) } yamlSerializer := json.NewYAMLSerializer(json.DefaultMetaFactory, Scheme, Scheme) - Codec = versioning.NewCodecForScheme( + Codec = versioning.NewDefaultingCodecForScheme( Scheme, yamlSerializer, yamlSerializer, diff --git a/pkg/runtime/codec.go b/pkg/runtime/codec.go index 9077f0fcd73..d359787a1ea 100644 --- a/pkg/runtime/codec.go +++ b/pkg/runtime/codec.go @@ -76,6 +76,24 @@ func EncodeOrDie(e Encoder, obj Object) string { return string(bytes) } +// DefaultingSerializer invokes defaulting after decoding. +type DefaultingSerializer struct { + Defaulter ObjectDefaulter + Decoder Decoder + // Encoder is optional to allow this type to be used as both a Decoder and an Encoder + Encoder +} + +// Decode performs a decode and then allows the defaulter to act on the provided object. +func (d DefaultingSerializer) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, into Object) (Object, *unversioned.GroupVersionKind, error) { + obj, gvk, err := d.Decoder.Decode(data, defaultGVK, into) + if err != nil { + return obj, gvk, err + } + d.Defaulter.Default(obj) + return obj, gvk, nil +} + // UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or // invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object. func UseOrCreateObject(t ObjectTyper, c ObjectCreater, gvk unversioned.GroupVersionKind, obj Object) (Object, error) { diff --git a/pkg/runtime/interfaces.go b/pkg/runtime/interfaces.go index 07f77ca1b9f..22b129300df 100644 --- a/pkg/runtime/interfaces.go +++ b/pkg/runtime/interfaces.go @@ -169,6 +169,12 @@ type NestedObjectDecoder interface { /////////////////////////////////////////////////////////////////////////////// // Non-codec interfaces +type ObjectDefaulter interface { + // Default takes an object (must be a pointer) and applies any default values. + // Defaulters may not error. + Default(in Object) +} + type ObjectVersioner interface { ConvertToVersion(in Object, gv GroupVersioner) (out Object, err error) } diff --git a/pkg/runtime/serializer/codec_factory.go b/pkg/runtime/serializer/codec_factory.go index afccae5a6ea..d274c3381f8 100644 --- a/pkg/runtime/serializer/codec_factory.go +++ b/pkg/runtime/serializer/codec_factory.go @@ -196,7 +196,7 @@ func (f CodecFactory) SupportedStreamingMediaTypes() []string { // TODO: make this call exist only in pkg/api, and initialize it with the set of default versions. // All other callers will be forced to request a Codec directly. func (f CodecFactory) LegacyCodec(version ...unversioned.GroupVersion) runtime.Codec { - return versioning.NewCodecForScheme(f.scheme, f.legacySerializer, f.universal, unversioned.GroupVersions(version), runtime.InternalGroupVersioner) + return versioning.NewDefaultingCodecForScheme(f.scheme, f.legacySerializer, f.universal, unversioned.GroupVersions(version), runtime.InternalGroupVersioner) } // UniversalDeserializer can convert any stored data recognized by this factory into a Go object that satisfies @@ -235,7 +235,7 @@ func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime. if decode == nil { decode = runtime.InternalGroupVersioner } - return versioning.NewCodecForScheme(f.scheme, encoder, decoder, encode, decode) + return versioning.NewDefaultingCodecForScheme(f.scheme, encoder, decoder, encode, decode) } // DecoderToVersion returns a decoder that targets the provided group version. diff --git a/pkg/runtime/serializer/versioning/versioning.go b/pkg/runtime/serializer/versioning/versioning.go index b3a165a5379..c82460e4a49 100644 --- a/pkg/runtime/serializer/versioning/versioning.go +++ b/pkg/runtime/serializer/versioning/versioning.go @@ -21,6 +21,7 @@ import ( "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/runtime" + utilruntime "k8s.io/kubernetes/pkg/util/runtime" ) // NewCodecForScheme is a convenience method for callers that are using a scheme. @@ -32,7 +33,19 @@ func NewCodecForScheme( encodeVersion runtime.GroupVersioner, decodeVersion runtime.GroupVersioner, ) runtime.Codec { - return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, scheme, encodeVersion, decodeVersion) + return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, scheme, nil, encodeVersion, decodeVersion) +} + +// NewDefaultingCodecForScheme is a convenience method for callers that are using a scheme. +func NewDefaultingCodecForScheme( + // TODO: I should be a scheme interface? + scheme *runtime.Scheme, + encoder runtime.Encoder, + decoder runtime.Decoder, + encodeVersion runtime.GroupVersioner, + decodeVersion runtime.GroupVersioner, +) runtime.Codec { + return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, scheme, scheme, encodeVersion, decodeVersion) } // NewCodec takes objects in their internal versions and converts them to external versions before @@ -45,6 +58,7 @@ func NewCodec( creater runtime.ObjectCreater, copier runtime.ObjectCopier, typer runtime.ObjectTyper, + defaulter runtime.ObjectDefaulter, encodeVersion runtime.GroupVersioner, decodeVersion runtime.GroupVersioner, ) runtime.Codec { @@ -55,6 +69,7 @@ func NewCodec( creater: creater, copier: copier, typer: typer, + defaulter: defaulter, encodeVersion: encodeVersion, decodeVersion: decodeVersion, @@ -69,6 +84,7 @@ type codec struct { creater runtime.ObjectCreater copier runtime.ObjectCopier typer runtime.ObjectTyper + defaulter runtime.ObjectDefaulter encodeVersion runtime.GroupVersioner decodeVersion runtime.GroupVersioner @@ -102,11 +118,31 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in } return into, gvk, nil } + + // perform defaulting if requested + if c.defaulter != nil { + // create a copy to ensure defaulting is not applied to the original versioned objects + if isVersioned { + copied, err := c.copier.Copy(obj) + if err != nil { + utilruntime.HandleError(err) + copied = obj + } + versioned.Objects = []runtime.Object{copied} + } + c.defaulter.Default(obj) + } else { + if isVersioned { + versioned.Objects = []runtime.Object{obj} + } + } + if err := c.convertor.Convert(obj, into, c.decodeVersion); err != nil { return nil, gvk, err } + if isVersioned { - versioned.Objects = []runtime.Object{obj, into} + versioned.Objects = append(versioned.Objects, into) return versioned, gvk, nil } return into, gvk, nil @@ -117,10 +153,17 @@ func (c *codec) Decode(data []byte, defaultGVK *unversioned.GroupVersionKind, in // create a copy, because ConvertToVersion does not guarantee non-mutation of objects copied, err := c.copier.Copy(obj) if err != nil { + utilruntime.HandleError(err) copied = obj } versioned.Objects = []runtime.Object{copied} } + + // perform defaulting if requested + if c.defaulter != nil { + c.defaulter.Default(obj) + } + out, err := c.convertor.ConvertToVersion(obj, c.decodeVersion) if err != nil { return nil, gvk, err diff --git a/pkg/runtime/serializer/versioning/versioning_test.go b/pkg/runtime/serializer/versioning/versioning_test.go index ce5d944d1e8..4e91e8ca906 100644 --- a/pkg/runtime/serializer/versioning/versioning_test.go +++ b/pkg/runtime/serializer/versioning/versioning_test.go @@ -64,7 +64,7 @@ func (d *testNestedDecodable) DecodeNestedObjects(_ runtime.Decoder) error { func TestNestedDecode(t *testing.T) { n := &testNestedDecodable{nestedErr: fmt.Errorf("unable to decode")} decoder := &mockSerializer{obj: n} - codec := NewCodec(nil, decoder, nil, nil, nil, nil, nil, nil) + codec := NewCodec(nil, decoder, nil, nil, nil, nil, nil, nil, nil) if _, _, err := codec.Decode([]byte(`{}`), nil, n); err != n.nestedErr { t.Errorf("unexpected error: %v", err) } @@ -82,6 +82,7 @@ func TestNestedEncode(t *testing.T) { &checkConvertor{obj: n2, groupVersion: unversioned.GroupVersion{Group: "other"}}, nil, nil, &mockTyper{gvks: []unversioned.GroupVersionKind{{Kind: "test"}}}, + nil, unversioned.GroupVersion{Group: "other"}, nil, ) if err := codec.Encode(n, ioutil.Discard); err != n2.nestedErr { @@ -105,6 +106,7 @@ func TestDecode(t *testing.T) { creater runtime.ObjectCreater copier runtime.ObjectCopier typer runtime.ObjectTyper + defaulter runtime.ObjectDefaulter yaml bool pretty bool @@ -235,7 +237,7 @@ func TestDecode(t *testing.T) { for i, test := range testCases { t.Logf("%d", i) - s := NewCodec(test.serializer, test.serializer, test.convertor, test.creater, test.copier, test.typer, test.encodes, test.decodes) + s := NewCodec(test.serializer, test.serializer, test.convertor, test.creater, test.copier, test.typer, test.defaulter, test.encodes, test.decodes) obj, gvk, err := s.Decode([]byte(`{}`), test.defaultGVK, test.into) if !reflect.DeepEqual(test.expectedGVK, gvk) { diff --git a/plugin/pkg/scheduler/api/latest/latest.go b/plugin/pkg/scheduler/api/latest/latest.go index 9eec37e2e7b..ab60711dcbc 100644 --- a/plugin/pkg/scheduler/api/latest/latest.go +++ b/plugin/pkg/scheduler/api/latest/latest.go @@ -43,7 +43,7 @@ var Codec runtime.Codec func init() { jsonSerializer := json.NewSerializer(json.DefaultMetaFactory, api.Scheme, api.Scheme, true) - Codec = versioning.NewCodecForScheme( + Codec = versioning.NewDefaultingCodecForScheme( api.Scheme, jsonSerializer, jsonSerializer, diff --git a/test/integration/framework/serializer.go b/test/integration/framework/serializer.go index 3a72ca82d02..7808d9976cd 100644 --- a/test/integration/framework/serializer.go +++ b/test/integration/framework/serializer.go @@ -58,9 +58,9 @@ func (s *wrappedSerializer) UniversalDeserializer() runtime.Decoder { } func (s *wrappedSerializer) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder { - return versioning.NewCodec(encoder, nil, s.scheme, s.scheme, s.scheme, s.scheme, gv, nil) + return versioning.NewCodec(encoder, nil, s.scheme, s.scheme, s.scheme, s.scheme, s.scheme, gv, nil) } func (s *wrappedSerializer) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder { - return versioning.NewCodec(nil, decoder, s.scheme, s.scheme, s.scheme, s.scheme, nil, gv) + return versioning.NewCodec(nil, decoder, s.scheme, s.scheme, s.scheme, s.scheme, s.scheme, nil, gv) } From 3ee591d7ab1c2594d1743121413ad6fc0038df44 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Thu, 29 Sep 2016 23:09:48 -0400 Subject: [PATCH 14/15] Invoke init container defaulting in conversion Because annotations... Remove old references to DefaultingInterface in manual conversions. --- pkg/api/v1/conversion.go | 23 +++++------------------ pkg/apis/batch/v2alpha1/conversion.go | 7 ------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index 635f64777c4..aab9d6a48c3 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -269,9 +269,6 @@ func addConversionFuncs(scheme *runtime.Scheme) error { } func Convert_v1_ReplicationController_to_extensions_ReplicaSet(in *ReplicationController, out *extensions.ReplicaSet, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*ReplicationController))(in) - } if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -288,9 +285,6 @@ func Convert_v1_ReplicationController_to_extensions_ReplicaSet(in *ReplicationCo } func Convert_v1_ReplicationControllerSpec_to_extensions_ReplicaSetSpec(in *ReplicationControllerSpec, out *extensions.ReplicaSetSpec, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*ReplicationControllerSpec))(in) - } out.Replicas = *in.Replicas if in.Selector != nil { api.Convert_map_to_unversioned_LabelSelector(&in.Selector, out.Selector, s) @@ -304,9 +298,6 @@ func Convert_v1_ReplicationControllerSpec_to_extensions_ReplicaSetSpec(in *Repli } func Convert_v1_ReplicationControllerStatus_to_extensions_ReplicaSetStatus(in *ReplicationControllerStatus, out *extensions.ReplicaSetStatus, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*ReplicationControllerStatus))(in) - } out.Replicas = in.Replicas out.FullyLabeledReplicas = in.FullyLabeledReplicas out.ReadyReplicas = in.ReadyReplicas @@ -316,9 +307,6 @@ func Convert_v1_ReplicationControllerStatus_to_extensions_ReplicaSetStatus(in *R } func Convert_extensions_ReplicaSet_to_v1_ReplicationController(in *extensions.ReplicaSet, out *ReplicationController, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*extensions.ReplicaSet))(in) - } if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil { return err } @@ -342,9 +330,6 @@ func Convert_extensions_ReplicaSet_to_v1_ReplicationController(in *extensions.Re } func Convert_extensions_ReplicaSetSpec_to_v1_ReplicationControllerSpec(in *extensions.ReplicaSetSpec, out *ReplicationControllerSpec, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*extensions.ReplicaSetSpec))(in) - } out.Replicas = new(int32) *out.Replicas = in.Replicas out.MinReadySeconds = in.MinReadySeconds @@ -360,9 +345,6 @@ func Convert_extensions_ReplicaSetSpec_to_v1_ReplicationControllerSpec(in *exten } func Convert_extensions_ReplicaSetStatus_to_v1_ReplicationControllerStatus(in *extensions.ReplicaSetStatus, out *ReplicationControllerStatus, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*extensions.ReplicaSetStatus))(in) - } out.Replicas = in.Replicas out.FullyLabeledReplicas = in.FullyLabeledReplicas out.ReadyReplicas = in.ReadyReplicas @@ -646,6 +628,11 @@ func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error // taking responsibility to ensure mutation of in is not exposed // back to the caller. in.Spec.InitContainers = values + // Call defaulters explicitly until annotations are removed + for i := range in.Spec.InitContainers { + c := &in.Spec.InitContainers[i] + SetDefaults_Container(c) + } } // If there is a beta annotation, copy to alpha key. // See commit log for PR #31026 for why we do this. diff --git a/pkg/apis/batch/v2alpha1/conversion.go b/pkg/apis/batch/v2alpha1/conversion.go index 0ac589de889..4884d9334be 100644 --- a/pkg/apis/batch/v2alpha1/conversion.go +++ b/pkg/apis/batch/v2alpha1/conversion.go @@ -18,7 +18,6 @@ package v2alpha1 import ( "fmt" - "reflect" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/unversioned" @@ -57,9 +56,6 @@ func addConversionFuncs(scheme *runtime.Scheme) error { } func Convert_batch_JobSpec_To_v2alpha1_JobSpec(in *batch.JobSpec, out *JobSpec, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*batch.JobSpec))(in) - } out.Parallelism = in.Parallelism out.Completions = in.Completions out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds @@ -86,9 +82,6 @@ func Convert_batch_JobSpec_To_v2alpha1_JobSpec(in *batch.JobSpec, out *JobSpec, } func Convert_v2alpha1_JobSpec_To_batch_JobSpec(in *JobSpec, out *batch.JobSpec, s conversion.Scope) error { - if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { - defaulting.(func(*JobSpec))(in) - } out.Parallelism = in.Parallelism out.Completions = in.Completions out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds From 957c0955aa0ca0dc4eb6b220def556525b9d880c Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 30 Sep 2016 17:39:47 -0400 Subject: [PATCH 15/15] Run defaulting on the scheduler startup --- cmd/kube-proxy/app/options/options.go | 4 +++- cmd/kubelet/app/options/options.go | 4 +++- cmd/kubelet/app/server.go | 1 + pkg/kubemark/hollow_kubelet.go | 1 + plugin/cmd/kube-scheduler/app/options/options.go | 4 +++- test/e2e_node/dynamic_kubelet_configuration_test.go | 2 ++ 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/kube-proxy/app/options/options.go b/cmd/kube-proxy/app/options/options.go index 40d89e3ea9f..a7fa9439f67 100644 --- a/cmd/kube-proxy/app/options/options.go +++ b/cmd/kube-proxy/app/options/options.go @@ -50,8 +50,10 @@ type ProxyServerConfig struct { } func NewProxyConfig() *ProxyServerConfig { + versioned := &v1alpha1.KubeProxyConfiguration{} + api.Scheme.Default(versioned) cfg := componentconfig.KubeProxyConfiguration{} - api.Scheme.Convert(&v1alpha1.KubeProxyConfiguration{}, &cfg, nil) + api.Scheme.Convert(versioned, &cfg, nil) return &ProxyServerConfig{ KubeProxyConfiguration: cfg, ContentType: "application/vnd.kubernetes.protobuf", diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index 85ca9771ff9..282cf24d071 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -64,8 +64,10 @@ type KubeletServer struct { // NewKubeletServer will create a new KubeletServer with default values. func NewKubeletServer() *KubeletServer { + versioned := &v1alpha1.KubeletConfiguration{} + api.Scheme.Default(versioned) config := componentconfig.KubeletConfiguration{} - api.Scheme.Convert(&v1alpha1.KubeletConfiguration{}, &config, nil) + api.Scheme.Convert(versioned, &config, nil) return &KubeletServer{ KubeConfig: flag.NewStringFlag("/var/lib/kubelet/kubeconfig"), RequireKubeConfig: false, // in 1.5, default to true diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 05f1279bc15..0a696b25c1f 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -246,6 +246,7 @@ func initKubeletConfigSync(s *options.KubeletServer) (*componentconfig.KubeletCo if err != nil { return nil, err } + api.Scheme.Default(&extKC) kc := componentconfig.KubeletConfiguration{} err = api.Scheme.Convert(&extKC, &kc, nil) if err != nil { diff --git a/pkg/kubemark/hollow_kubelet.go b/pkg/kubemark/hollow_kubelet.go index 672f5685509..30feba4cc91 100644 --- a/pkg/kubemark/hollow_kubelet.go +++ b/pkg/kubemark/hollow_kubelet.go @@ -103,6 +103,7 @@ func GetHollowKubeletConfig( // Do the external -> internal conversion to make sure that defaults // are set for fields not overridden in NewHollowKubelet. tmp := &v1alpha1.KubeletConfiguration{} + api.Scheme.Default(tmp) c := &componentconfig.KubeletConfiguration{} api.Scheme.Convert(tmp, c, nil) diff --git a/plugin/cmd/kube-scheduler/app/options/options.go b/plugin/cmd/kube-scheduler/app/options/options.go index 5a352cf61d0..43a38ca5528 100644 --- a/plugin/cmd/kube-scheduler/app/options/options.go +++ b/plugin/cmd/kube-scheduler/app/options/options.go @@ -42,8 +42,10 @@ type SchedulerServer struct { // NewSchedulerServer creates a new SchedulerServer with default parameters func NewSchedulerServer() *SchedulerServer { + versioned := &v1alpha1.KubeSchedulerConfiguration{} + api.Scheme.Default(versioned) cfg := componentconfig.KubeSchedulerConfiguration{} - api.Scheme.Convert(&v1alpha1.KubeSchedulerConfiguration{}, &cfg, nil) + api.Scheme.Convert(versioned, &cfg, nil) cfg.LeaderElection.LeaderElect = true s := SchedulerServer{ KubeSchedulerConfiguration: cfg, diff --git a/test/e2e_node/dynamic_kubelet_configuration_test.go b/test/e2e_node/dynamic_kubelet_configuration_test.go index 036d44755b0..674022b1fd5 100644 --- a/test/e2e_node/dynamic_kubelet_configuration_test.go +++ b/test/e2e_node/dynamic_kubelet_configuration_test.go @@ -142,6 +142,8 @@ func decodeConfigz(resp *http.Response) (*componentconfig.KubeletConfiguration, return nil, err } + api.Scheme.Default(&configz.ComponentConfig) + err = api.Scheme.Convert(&configz.ComponentConfig, &kubeCfg, nil) if err != nil { return nil, err