Skip to content

Commit

Permalink
Merge pull request #18 from mfojtik/rebase
Browse files Browse the repository at this point in the history
Pick down release 1.2 stable 20160411
  • Loading branch information
deads2k committed May 10, 2016
2 parents f88b290 + 2c6e844 commit c2cc7fd
Show file tree
Hide file tree
Showing 89 changed files with 2,921 additions and 288 deletions.
23 changes: 13 additions & 10 deletions cmd/kube-apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ func NewAPIServer() *APIServer {
AuthorizationMode: "AlwaysAllow",
DeleteCollectionWorkers: 1,
EnableLogsSupport: true,
EnableProfiling: true,
EnableWatchCache: true,
EtcdConfig: etcdstorage.EtcdConfig{
Prefix: genericapiserver.DefaultEtcdPathPrefix,
},
EventTTL: 1 * time.Hour,
MasterCount: 1,
MasterServiceNamespace: api.NamespaceDefault,
MinRequestTimeout: 1800,
RuntimeConfig: make(config.ConfigurationMap),
StorageVersions: registered.AllPreferredGroupVersions(),
DefaultStorageVersions: registered.AllPreferredGroupVersions(),
Expand Down Expand Up @@ -242,17 +245,17 @@ func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
fs.IntVar(&s.MasterCount, "apiserver-count", s.MasterCount, "The number of apiservers running in the cluster")
fs.IntVar(&s.DeleteCollectionWorkers, "delete-collection-workers", s.DeleteCollectionWorkers, "Number of workers spawned for DeleteCollection call. These are used to speed up namespace cleanup.")
fs.Var(&s.RuntimeConfig, "runtime-config", "A set of key=value pairs that describe runtime configuration that may be passed to apiserver. apis/<groupVersion> key can be used to turn on/off specific api versions. apis/<groupVersion>/<resource> can be used to turn on/off specific resources. api/all and api/legacy are special keys to control all and legacy api versions respectively.")
fs.BoolVar(&s.EnableProfiling, "profiling", true, "Enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, "Enable profiling via web interface host:port/debug/pprof/")
// TODO: enable cache in integration tests.
fs.BoolVar(&s.EnableWatchCache, "watch-cache", true, "Enable watch caching in the apiserver")
fs.BoolVar(&s.EnableWatchCache, "watch-cache", s.EnableWatchCache, "Enable watch caching in the apiserver")
fs.BoolVar(&s.EnableSwaggerUI, "enable-swagger-ui", false, "Enables swagger ui on the apiserver at /swagger-ui")
fs.StringVar(&s.ExternalHost, "external-hostname", "", "The hostname to use when generating externalized URLs for this master (e.g. Swagger API Docs.)")
fs.IntVar(&s.MaxRequestsInFlight, "max-requests-inflight", 400, "The maximum number of requests in flight at a given time. When the server exceeds this, it rejects requests. Zero for no limit.")
fs.IntVar(&s.MinRequestTimeout, "min-request-timeout", 1800, "An optional field indicating the minimum number of seconds a handler must keep a request open before timing it out. Currently only honored by the watch request handler, which picks a randomized value above this number as the connection timeout, to spread out load.")
fs.StringVar(&s.ExternalHost, "external-hostname", s.ExternalHost, "The hostname to use when generating externalized URLs for this master (e.g. Swagger API Docs.)")
fs.IntVar(&s.MaxRequestsInFlight, "max-requests-inflight", s.MaxRequestsInFlight, "The maximum number of requests in flight at a given time. When the server exceeds this, it rejects requests. Zero for no limit.")
fs.IntVar(&s.MinRequestTimeout, "min-request-timeout", s.MinRequestTimeout, "An optional field indicating the minimum number of seconds a handler must keep a request open before timing it out. Currently only honored by the watch request handler, which picks a randomized value above this number as the connection timeout, to spread out load.")
fs.StringVar(&s.LongRunningRequestRE, "long-running-request-regexp", s.LongRunningRequestRE, "A regular expression matching long running requests which should be excluded from maximum inflight request handling.")
fs.StringVar(&s.SSHUser, "ssh-user", "", "If non-empty, use secure SSH proxy to the nodes, using this user name")
fs.StringVar(&s.SSHKeyfile, "ssh-keyfile", "", "If non-empty, use secure SSH proxy to the nodes, using this user keyfile")
fs.Int64Var(&s.MaxConnectionBytesPerSec, "max-connection-bytes-per-sec", 0, "If non-zero, throttle each user connection to this number of bytes/sec. Currently only applies to long-running requests")
fs.StringVar(&s.SSHUser, "ssh-user", s.SSHUser, "If non-empty, use secure SSH proxy to the nodes, using this user name")
fs.StringVar(&s.SSHKeyfile, "ssh-keyfile", s.SSHKeyfile, "If non-empty, use secure SSH proxy to the nodes, using this user keyfile")
fs.Int64Var(&s.MaxConnectionBytesPerSec, "max-connection-bytes-per-sec", s.MaxConnectionBytesPerSec, "If non-zero, throttle each user connection to this number of bytes/sec. Currently only applies to long-running requests")
// Kubelet related flags:
fs.BoolVar(&s.KubeletConfig.EnableHttps, "kubelet-https", s.KubeletConfig.EnableHttps, "Use https for kubelet connections")
fs.UintVar(&s.KubeletConfig.Port, "kubelet-port", s.KubeletConfig.Port, "Kubelet port")
Expand All @@ -262,8 +265,8 @@ func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.KubeletConfig.KeyFile, "kubelet-client-key", s.KubeletConfig.KeyFile, "Path to a client key file for TLS.")
fs.StringVar(&s.KubeletConfig.CAFile, "kubelet-certificate-authority", s.KubeletConfig.CAFile, "Path to a cert. file for the certificate authority.")
// See #14282 for details on how to test/try this option out. TODO remove this comment once this option is tested in CI.
fs.IntVar(&s.KubernetesServiceNodePort, "kubernetes-service-node-port", 0, "If non-zero, the Kubernetes master service (which apiserver creates/maintains) will be of type NodePort, using this as the value of the port. If zero, the Kubernetes master service will be of type ClusterIP.")
fs.IntVar(&s.KubernetesServiceNodePort, "kubernetes-service-node-port", s.KubernetesServiceNodePort, "If non-zero, the Kubernetes master service (which apiserver creates/maintains) will be of type NodePort, using this as the value of the port. If zero, the Kubernetes master service will be of type ClusterIP.")
// TODO: delete this flag as soon as we identify and fix all clients that send malformed updates, like #14126.
fs.BoolVar(&validation.RepairMalformedUpdates, "repair-malformed-updates", true, "If true, server will do its best to fix the update request to pass the validation, e.g., setting empty UID in update request to its existing value. This flag can be turned off after we fix all the clients that send malformed updates.")
fs.BoolVar(&validation.RepairMalformedUpdates, "repair-malformed-updates", validation.RepairMalformedUpdates, "If true, server will do its best to fix the update request to pass the validation, e.g., setting empty UID in update request to its existing value. This flag can be turned off after we fix all the clients that send malformed updates.")
fs.StringSliceVar(&s.WatchCacheSizes, "watch-cache-sizes", s.WatchCacheSizes, "List of watch cache sizes for every resource (pods, nodes, etc.), comma separated. The individual override format: resource#size, where size is a number. It takes effect when watch-cache is enabled.")
}
48 changes: 26 additions & 22 deletions cmd/libs/go2idl/conversion-gen/generators/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ type genConversion struct {
preexisting conversions
imports namer.ImportTracker
typesForInit []conversionType

globalVariables map[string]interface{}
}

func NewGenConversion(sanitizedName, targetPackage string, preexisting conversions) generator.Generator {
Expand Down Expand Up @@ -365,12 +367,6 @@ func (g *genConversion) isOtherPackage(pkg string) bool {

func (g *genConversion) Imports(c *generator.Context) (imports []string) {
importLines := []string{"reflect \"reflect\""}
if g.isOtherPackage(apiPackagePath) {
importLines = append(importLines, "api \""+apiPackagePath+"\"")
}
if g.isOtherPackage(conversionPackagePath) {
importLines = append(importLines, "conversion \""+conversionPackagePath+"\"")
}
for _, singleImport := range g.imports.ImportLines() {
if g.isOtherPackage(singleImport) {
importLines = append(importLines, singleImport)
Expand All @@ -379,7 +375,16 @@ func (g *genConversion) Imports(c *generator.Context) (imports []string) {
return importLines
}

func argsFromType(inType, outType *types.Type) interface{} {
func (g *genConversion) withGlobals(args map[string]interface{}) map[string]interface{} {
for k, v := range g.globalVariables {
if _, ok := args[k]; !ok {
args[k] = v
}
}
return args
}

func argsFromType(inType, outType *types.Type) map[string]interface{} {
return map[string]interface{}{
"inType": inType,
"outType": outType,
Expand All @@ -399,13 +404,20 @@ func (g *genConversion) preexists(inType, outType *types.Type) (*types.Type, boo
}

func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
scheme := c.Universe.Variable(types.Name{Package: apiPackagePath, Name: "Scheme"})
g.imports.AddType(scheme)
scope := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Scope"})
g.imports.AddType(scope)
g.globalVariables = map[string]interface{}{
"scheme": scheme,
"Scope": scope,
}

sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil)
if g.targetPackage == apiPackagePath {
sw.Do("if err := Scheme.AddGeneratedConversionFuncs(\n", nil)
} else {
sw.Do("if err := api.Scheme.AddGeneratedConversionFuncs(\n", nil)
}
sw.Do("if err := $.scheme|raw$.AddGeneratedConversionFuncs(\n", map[string]interface{}{
"scheme": scheme,
})
for _, conv := range g.typesForInit {
funcName := g.funcNameTmpl(conv.inType, conv.outType)
sw.Do(fmt.Sprintf("%s,\n", funcName), argsFromType(conv.inType, conv.outType))
Expand All @@ -432,11 +444,7 @@ func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.W

func (g *genConversion) generateConversion(inType, outType *types.Type, sw *generator.SnippetWriter) {
funcName := g.funcNameTmpl(inType, outType)
if g.targetPackage == conversionPackagePath {
sw.Do(fmt.Sprintf("func auto%s(in *$.inType|raw$, out *$.outType|raw$, s Scope) error {\n", funcName), argsFromType(inType, outType))
} else {
sw.Do(fmt.Sprintf("func auto%s(in *$.inType|raw$, out *$.outType|raw$, s conversion.Scope) error {\n", funcName), argsFromType(inType, outType))
}
sw.Do(fmt.Sprintf("func auto%s(in *$.inType|raw$, out *$.outType|raw$, s $.Scope|raw$) error {\n", funcName), g.withGlobals(argsFromType(inType, outType)))
sw.Do("if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {\n", nil)
sw.Do("defaulting.(func(*$.|raw$))(in)\n", inType)
sw.Do("}\n", nil)
Expand All @@ -446,11 +454,7 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene

// If there is no public preexisting Convert method, generate it.
if _, ok := g.preexists(inType, outType); !ok {
if g.targetPackage == conversionPackagePath {
sw.Do(fmt.Sprintf("func %s(in *$.inType|raw$, out *$.outType|raw$, s Scope) error {\n", funcName), argsFromType(inType, outType))
} else {
sw.Do(fmt.Sprintf("func %s(in *$.inType|raw$, out *$.outType|raw$, s conversion.Scope) error {\n", funcName), argsFromType(inType, outType))
}
sw.Do(fmt.Sprintf("func %s(in *$.inType|raw$, out *$.outType|raw$, s $.Scope|raw$) error {\n", funcName), g.withGlobals(argsFromType(inType, outType)))
sw.Do(fmt.Sprintf("return auto%s(in, out, s)\n", funcName), argsFromType(inType, outType))
sw.Do("}\n\n", nil)
}
Expand Down
47 changes: 26 additions & 21 deletions cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
for _, p := range context.Universe {
copyableType := false
for _, t := range p.Types {
if copyableWithinPackage(t) {
if copyableWithinPackage(t) && inputs.Has(t.Name.Package) {
copyableType = true
}
}
Expand Down Expand Up @@ -115,6 +115,8 @@ type genDeepCopy struct {
imports namer.ImportTracker
typesForInit []*types.Type
generateInitFunc bool

globalVariables map[string]interface{}
}

func NewGenDeepCopy(sanitizedName, targetPackage string, generateInitFunc bool) generator.Generator {
Expand Down Expand Up @@ -144,9 +146,6 @@ func (g *genDeepCopy) Filter(c *generator.Context, t *types.Type) bool {
}

func copyableWithinPackage(t *types.Type) bool {
if !strings.HasPrefix(t.Name.Package, "k8s.io/kubernetes/") {
return false
}
if types.ExtractCommentTags("+", t.CommentLines)["gencopy"] == "false" {
return false
}
Expand All @@ -173,12 +172,6 @@ func (g *genDeepCopy) isOtherPackage(pkg string) bool {

func (g *genDeepCopy) Imports(c *generator.Context) (imports []string) {
importLines := []string{}
if g.isOtherPackage(apiPackagePath) && g.generateInitFunc {
importLines = append(importLines, "api \""+apiPackagePath+"\"")
}
if g.isOtherPackage(conversionPackagePath) {
importLines = append(importLines, "conversion \""+conversionPackagePath+"\"")
}
for _, singleImport := range g.imports.ImportLines() {
if g.isOtherPackage(singleImport) {
importLines = append(importLines, singleImport)
Expand All @@ -187,7 +180,16 @@ func (g *genDeepCopy) Imports(c *generator.Context) (imports []string) {
return importLines
}

func argsFromType(t *types.Type) interface{} {
func (g *genDeepCopy) withGlobals(args map[string]interface{}) map[string]interface{} {
for k, v := range g.globalVariables {
if _, ok := args[k]; !ok {
args[k] = v
}
}
return args
}

func argsFromType(t *types.Type) map[string]interface{} {
return map[string]interface{}{
"type": t,
}
Expand All @@ -203,19 +205,26 @@ func (g *genDeepCopy) funcNameTmpl(t *types.Type) string {
}

func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"})
g.imports.AddType(cloner)
g.globalVariables = map[string]interface{}{
"Cloner": cloner,
}
if !g.generateInitFunc {
// TODO: We should come up with a solution to register all generated
// deep-copy functions. However, for now, to avoid import cycles
// we register only those explicitly requested.
return nil
}
scheme := c.Universe.Variable(types.Name{Package: apiPackagePath, Name: "Scheme"})
g.imports.AddType(scheme)
g.globalVariables["scheme"] = scheme

sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil)
if g.targetPackage == apiPackagePath {
sw.Do("if err := Scheme.AddGeneratedDeepCopyFuncs(\n", nil)
} else {
sw.Do("if err := api.Scheme.AddGeneratedDeepCopyFuncs(\n", nil)
}
sw.Do("if err := $.scheme|raw$.AddGeneratedDeepCopyFuncs(\n", map[string]interface{}{
"scheme": scheme,
})
for _, t := range g.typesForInit {
sw.Do(fmt.Sprintf("%s,\n", g.funcNameTmpl(t)), argsFromType(t))
}
Expand All @@ -230,11 +239,7 @@ func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
func (g *genDeepCopy) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
funcName := g.funcNameTmpl(t)
if g.targetPackage == conversionPackagePath {
sw.Do(fmt.Sprintf("func %s(in $.type|raw$, out *$.type|raw$, c *Cloner) error {\n", funcName), argsFromType(t))
} else {
sw.Do(fmt.Sprintf("func %s(in $.type|raw$, out *$.type|raw$, c *conversion.Cloner) error {\n", funcName), argsFromType(t))
}
sw.Do(fmt.Sprintf("func %s(in $.type|raw$, out *$.type|raw$, c *$.Cloner|raw$) error {\n", funcName), g.withGlobals(argsFromType(t)))
g.generateFor(t, sw)
sw.Do("return nil\n", nil)
sw.Do("}\n\n", nil)
Expand Down
10 changes: 5 additions & 5 deletions pkg/admission/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (
)

type attributesRecord struct {
kind unversioned.GroupKind
kind unversioned.GroupVersionKind
namespace string
name string
resource unversioned.GroupResource
resource unversioned.GroupVersionResource
subresource string
operation Operation
object runtime.Object
userInfo user.Info
}

func NewAttributesRecord(object runtime.Object, kind unversioned.GroupKind, namespace, name string, resource unversioned.GroupResource, subresource string, operation Operation, userInfo user.Info) Attributes {
func NewAttributesRecord(object runtime.Object, kind unversioned.GroupVersionKind, namespace, name string, resource unversioned.GroupVersionResource, subresource string, operation Operation, userInfo user.Info) Attributes {
return &attributesRecord{
kind: kind,
namespace: namespace,
Expand All @@ -46,7 +46,7 @@ func NewAttributesRecord(object runtime.Object, kind unversioned.GroupKind, name
}
}

func (record *attributesRecord) GetKind() unversioned.GroupKind {
func (record *attributesRecord) GetKind() unversioned.GroupVersionKind {
return record.kind
}

Expand All @@ -58,7 +58,7 @@ func (record *attributesRecord) GetName() string {
return record.name
}

func (record *attributesRecord) GetResource() unversioned.GroupResource {
func (record *attributesRecord) GetResource() unversioned.GroupVersionResource {
return record.resource
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/admission/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestAdmit(t *testing.T) {
},
}
for _, test := range tests {
err := test.chain.Admit(NewAttributesRecord(nil, unversioned.GroupKind{}, "", "", unversioned.GroupResource{}, "", test.operation, nil))
err := test.chain.Admit(NewAttributesRecord(nil, unversioned.GroupVersionKind{}, "", "", unversioned.GroupVersionResource{}, "", test.operation, nil))
accepted := (err == nil)
if accepted != test.accept {
t.Errorf("%s: unexpected result of admit call: %v\n", test.name, accepted)
Expand Down
2 changes: 1 addition & 1 deletion pkg/admission/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func extractResourceName(a Attributes) (name string, resource unversioned.GroupResource, err error) {
name = "Unknown"
resource = a.GetResource()
resource = a.GetResource().GroupResource()
obj := a.GetObject()
if obj != nil {
accessor, err := meta.Accessor(obj)
Expand Down
4 changes: 2 additions & 2 deletions pkg/admission/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Attributes interface {
// GetNamespace is the namespace associated with the request (if any)
GetNamespace() string
// GetResource is the name of the resource being requested. This is not the kind. For example: pods
GetResource() unversioned.GroupResource
GetResource() unversioned.GroupVersionResource
// GetSubresource is the name of the subresource being requested. This is a different resource, scoped to the parent resource, but it may have a different kind.
// For instance, /pods has the resource "pods" and the kind "Pod", while /pods/foo/status has the resource "pods", the sub resource "status", and the kind "Pod"
// (because status operates on pods). The binding resource for a pod though may be /pods/foo/binding, which has resource "pods", subresource "binding", and kind "Binding".
Expand All @@ -42,7 +42,7 @@ type Attributes interface {
// GetObject is the object from the incoming request prior to default values being applied
GetObject() runtime.Object
// GetKind is the type of object being manipulated. For example: Pod
GetKind() unversioned.GroupKind
GetKind() unversioned.GroupVersionKind
// GetUserInfo is information about the requesting user
GetUserInfo() user.Info
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/admission/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ func RegisterPlugin(name string, plugin Factory) {
plugins[name] = plugin
}

// GetPlugin creates an instance of the named plugin, or nil if the name is not
// known. The error is returned only when the named provider was known but failed
// to initialize. The config parameter specifies the io.Reader handler of the
// configuration file for the cloud provider, or nil for no configuration.
func GetPlugin(name string, client clientset.Interface, config io.Reader) (Interface, error) {
// getPlugin creates an instance of the named plugin. It returns `false` if the
// the name is not known. The error is returned only when the named provider was
// known but failed to initialize. The config parameter specifies the io.Reader
// handler of the configuration file for the cloud provider, or nil for no configuration.
func getPlugin(name string, client clientset.Interface, config io.Reader) (Interface, bool, error) {
pluginsMutex.Lock()
defer pluginsMutex.Unlock()
f, found := plugins[name]
if !found {
return nil, nil
return nil, false, nil
}
return f(client, config)
ret, err := f(client, config)
return ret, true, err
}

// InitPlugin creates an instance of the named interface.
Expand All @@ -99,11 +100,11 @@ func InitPlugin(name string, client clientset.Interface, configFilePath string)
defer config.Close()
}

plugin, err := GetPlugin(name, client, config)
plugin, found, err := getPlugin(name, client, config)
if err != nil {
glog.Fatalf("Couldn't init admission plugin %q: %v", name, err)
}
if plugin == nil {
if !found {
glog.Fatalf("Unknown admission plugin: %s", name)
}

Expand Down
Loading

0 comments on commit c2cc7fd

Please sign in to comment.