Merge pull request #1332 from bg-chun/update_cri_for_hugepages

update cri-plugin to parse hugepages limit
This commit is contained in:
Mike Brown 2020-02-12 10:05:01 -06:00 committed by GitHub
commit cf0e0a1e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1058 additions and 761 deletions

View File

@ -423,10 +423,11 @@ func WithResources(resources *runtime.LinuxContainerResources) oci.SpecOpts {
s.Linux.Resources.Memory = &runtimespec.LinuxMemory{} s.Linux.Resources.Memory = &runtimespec.LinuxMemory{}
} }
var ( var (
p = uint64(resources.GetCpuPeriod()) p = uint64(resources.GetCpuPeriod())
q = resources.GetCpuQuota() q = resources.GetCpuQuota()
shares = uint64(resources.GetCpuShares()) shares = uint64(resources.GetCpuShares())
limit = resources.GetMemoryLimitInBytes() limit = resources.GetMemoryLimitInBytes()
hugepages = resources.GetHugepageLimits()
) )
if p != 0 { if p != 0 {
@ -447,6 +448,12 @@ func WithResources(resources *runtime.LinuxContainerResources) oci.SpecOpts {
if limit != 0 { if limit != 0 {
s.Linux.Resources.Memory.Limit = &limit s.Linux.Resources.Memory.Limit = &limit
} }
for _, limit := range hugepages {
s.Linux.Resources.HugepageLimits = append(s.Linux.Resources.HugepageLimits, runtimespec.LinuxHugepageLimit{
Pagesize: limit.PageSize,
Limit: limit.Limit,
})
}
return nil return nil
} }
} }

View File

@ -60,13 +60,13 @@ github.com/cilium/ebpf 60c3aa43f488292fe2ee50fb8b833b383ca8ebbb
# kubernetes dependencies # kubernetes dependencies
sigs.k8s.io/yaml fd68e9863619f6ec2fdd8625fe1f02e7c877e480 # v1.1.0 sigs.k8s.io/yaml fd68e9863619f6ec2fdd8625fe1f02e7c877e480 # v1.1.0
k8s.io/utils e782cd3c129fc98ee807f3c889c0f26eb7c9daf5 k8s.io/utils e782cd3c129fc98ee807f3c889c0f26eb7c9daf5
k8s.io/kubernetes v1.17.1 k8s.io/kubernetes v1.18.0-alpha.1
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/cri-api kubernetes-1.17.1 k8s.io/cri-api kubernetes-1.18.0-alpha.1
k8s.io/client-go kubernetes-1.17.1 k8s.io/client-go kubernetes-1.18.0-alpha.1
k8s.io/api kubernetes-1.17.1 k8s.io/api kubernetes-1.18.0-alpha.1
k8s.io/apiserver kubernetes-1.17.1 k8s.io/apiserver kubernetes-1.18.0-alpha.1
k8s.io/apimachinery kubernetes-1.17.1 k8s.io/apimachinery kubernetes-1.18.0-alpha.1
gopkg.in/yaml.v2 53403b58ad1b561927d19068c655246f2db79d48 # v2.2.8 gopkg.in/yaml.v2 53403b58ad1b561927d19068c655246f2db79d48 # v2.2.8
gopkg.in/inf.v0 v0.9.1 gopkg.in/inf.v0 v0.9.1
golang.org/x/time 9d24e82272b4f38b78bc8cff74fa936d31ccd8ef golang.org/x/time 9d24e82272b4f38b78bc8cff74fa936d31ccd8ef

View File

@ -41,6 +41,14 @@ func (self *ResourceList) Memory() *resource.Quantity {
return &resource.Quantity{Format: resource.BinarySI} return &resource.Quantity{Format: resource.BinarySI}
} }
// Returns the Storage limit if specified.
func (self *ResourceList) Storage() *resource.Quantity {
if val, ok := (*self)[ResourceStorage]; ok {
return &val
}
return &resource.Quantity{Format: resource.BinarySI}
}
func (self *ResourceList) Pods() *resource.Quantity { func (self *ResourceList) Pods() *resource.Quantity {
if val, ok := (*self)[ResourcePods]; ok { if val, ok := (*self)[ResourcePods]; ok {
return &val return &val

6
vendor/k8s.io/api/go.mod generated vendored
View File

@ -2,16 +2,16 @@
module k8s.io/api module k8s.io/api
go 1.12 go 1.13
require ( require (
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
k8s.io/apimachinery v0.17.1 k8s.io/apimachinery v0.18.0-alpha.1
) )
replace ( replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13 golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/apimachinery => k8s.io/apimachinery v0.17.1 k8s.io/apimachinery => k8s.io/apimachinery v0.18.0-alpha.1
) )

2
vendor/k8s.io/apimachinery/go.mod generated vendored
View File

@ -2,7 +2,7 @@
module k8s.io/apimachinery module k8s.io/apimachinery
go 1.12 go 1.13
require ( require (
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1

View File

@ -47,19 +47,6 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
if err := scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{}); err != nil { if err := scheme.AddIgnoredConversionType(&metav1.TypeMeta{}, &metav1.TypeMeta{}); err != nil {
return err return err
} }
err := scheme.AddConversionFuncs(
metav1.Convert_string_To_labels_Selector,
metav1.Convert_labels_Selector_To_string,
metav1.Convert_string_To_fields_Selector,
metav1.Convert_fields_Selector_To_string,
metav1.Convert_Map_string_To_string_To_v1_LabelSelector,
metav1.Convert_v1_LabelSelector_To_Map_string_To_string,
)
if err != nil {
return err
}
// ListOptions is the only options struct which needs conversion (it exposes labels and fields // ListOptions is the only options struct which needs conversion (it exposes labels and fields
// as selectors for convenience). The other types have only a single representation today. // as selectors for convenience). The other types have only a single representation today.
scheme.AddKnownTypes(SchemeGroupVersion, scheme.AddKnownTypes(SchemeGroupVersion,
@ -71,8 +58,8 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
&metav1.UpdateOptions{}, &metav1.UpdateOptions{},
) )
scheme.AddKnownTypes(SchemeGroupVersion, scheme.AddKnownTypes(SchemeGroupVersion,
&metav1beta1.Table{}, &metav1.Table{},
&metav1beta1.TableOptions{}, &metav1.TableOptions{},
&metav1beta1.PartialObjectMetadata{}, &metav1beta1.PartialObjectMetadata{},
&metav1beta1.PartialObjectMetadataList{}, &metav1beta1.PartialObjectMetadataList{},
) )
@ -87,6 +74,7 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
&metav1.DeleteOptions{}, &metav1.DeleteOptions{},
&metav1.CreateOptions{}, &metav1.CreateOptions{},
&metav1.UpdateOptions{}) &metav1.UpdateOptions{})
metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion) metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion)
return nil return nil
} }
@ -95,5 +83,4 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
// the logic for conversion private. // the logic for conversion private.
func init() { func init() {
localSchemeBuilder.Register(addToGroupVersion) localSchemeBuilder.Register(addToGroupVersion)
localSchemeBuilder.Register(metav1.RegisterConversions)
} }

View File

@ -26,69 +26,10 @@ import (
"k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
) )
func AddConversionFuncs(scheme *runtime.Scheme) error {
return scheme.AddConversionFuncs(
Convert_v1_TypeMeta_To_v1_TypeMeta,
Convert_v1_ListMeta_To_v1_ListMeta,
Convert_v1_DeleteOptions_To_v1_DeleteOptions,
Convert_intstr_IntOrString_To_intstr_IntOrString,
Convert_Pointer_intstr_IntOrString_To_intstr_IntOrString,
Convert_intstr_IntOrString_To_Pointer_intstr_IntOrString,
Convert_Pointer_v1_Duration_To_v1_Duration,
Convert_v1_Duration_To_Pointer_v1_Duration,
Convert_Slice_string_To_v1_Time,
Convert_Slice_string_To_Pointer_v1_Time,
Convert_v1_Time_To_v1_Time,
Convert_v1_MicroTime_To_v1_MicroTime,
Convert_resource_Quantity_To_resource_Quantity,
Convert_string_To_labels_Selector,
Convert_labels_Selector_To_string,
Convert_string_To_fields_Selector,
Convert_fields_Selector_To_string,
Convert_Pointer_bool_To_bool,
Convert_bool_To_Pointer_bool,
Convert_Pointer_string_To_string,
Convert_string_To_Pointer_string,
Convert_Pointer_int64_To_int,
Convert_int_To_Pointer_int64,
Convert_Pointer_int32_To_int32,
Convert_int32_To_Pointer_int32,
Convert_Pointer_int64_To_int64,
Convert_int64_To_Pointer_int64,
Convert_Pointer_float64_To_float64,
Convert_float64_To_Pointer_float64,
Convert_Map_string_To_string_To_v1_LabelSelector,
Convert_v1_LabelSelector_To_Map_string_To_string,
Convert_Slice_string_To_Slice_int32,
Convert_Slice_string_To_Pointer_v1_DeletionPropagation,
Convert_Slice_string_To_v1_IncludeObjectPolicy,
)
}
func Convert_Pointer_float64_To_float64(in **float64, out *float64, s conversion.Scope) error { func Convert_Pointer_float64_To_float64(in **float64, out *float64, s conversion.Scope) error {
if *in == nil { if *in == nil {
*out = 0 *out = 0

View File

@ -53,15 +53,6 @@ var scheme = runtime.NewScheme()
// ParameterCodec knows about query parameters used with the meta v1 API spec. // ParameterCodec knows about query parameters used with the meta v1 API spec.
var ParameterCodec = runtime.NewParameterCodec(scheme) var ParameterCodec = runtime.NewParameterCodec(scheme)
func addEventConversionFuncs(scheme *runtime.Scheme) error {
return scheme.AddConversionFuncs(
Convert_v1_WatchEvent_To_watch_Event,
Convert_v1_InternalEvent_To_v1_WatchEvent,
Convert_watch_Event_To_v1_WatchEvent,
Convert_v1_WatchEvent_To_v1_InternalEvent,
)
}
var optionsTypes = []runtime.Object{ var optionsTypes = []runtime.Object{
&ListOptions{}, &ListOptions{},
&ExportOptions{}, &ExportOptions{},
@ -90,10 +81,8 @@ func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
&APIResourceList{}, &APIResourceList{},
) )
utilruntime.Must(addEventConversionFuncs(scheme))
// register manually. This usually goes through the SchemeBuilder, which we cannot use here. // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
utilruntime.Must(AddConversionFuncs(scheme)) utilruntime.Must(RegisterConversions(scheme))
utilruntime.Must(RegisterDefaults(scheme)) utilruntime.Must(RegisterDefaults(scheme))
} }
@ -106,9 +95,7 @@ func AddMetaToScheme(scheme *runtime.Scheme) error {
&PartialObjectMetadataList{}, &PartialObjectMetadataList{},
) )
return scheme.AddConversionFuncs( return nil
Convert_Slice_string_To_v1_IncludeObjectPolicy,
)
} }
func init() { func init() {

View File

@ -81,28 +81,27 @@ func init() {
} }
var fileDescriptor_90ec10f86b91f9a8 = []byte{ var fileDescriptor_90ec10f86b91f9a8 = []byte{
// 321 bytes of a gzipped FileDescriptorProto // 317 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x41, 0x4b, 0xf3, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x41, 0x4b, 0xf3, 0x30,
0x18, 0xc7, 0x9b, 0xf7, 0x65, 0x38, 0x3a, 0x04, 0xd9, 0x69, 0xee, 0x90, 0x0d, 0x4f, 0xf3, 0xb0, 0x1c, 0xc6, 0x9b, 0xf7, 0x65, 0x38, 0x3a, 0x04, 0xd9, 0x69, 0xee, 0x90, 0x0d, 0x4f, 0xf3, 0xb0,
0x84, 0x0d, 0x11, 0xc1, 0xdb, 0x6e, 0x82, 0xa2, 0xec, 0x28, 0x1e, 0x4c, 0xbb, 0xc7, 0x2e, 0xd6, 0x84, 0x0d, 0x11, 0xc1, 0xdb, 0x6e, 0x82, 0xa2, 0xec, 0x28, 0x1e, 0x4c, 0xbb, 0xbf, 0x5d, 0xac,
0x34, 0x25, 0x79, 0x3a, 0xf0, 0xe6, 0x47, 0xf0, 0x63, 0xed, 0xb8, 0xe3, 0x40, 0x18, 0xae, 0x7e, 0x69, 0x4a, 0xf2, 0xef, 0xc0, 0x9b, 0x1f, 0xc1, 0x8f, 0xb5, 0xe3, 0x8e, 0x03, 0x61, 0xb8, 0xf8,
0x11, 0x49, 0x57, 0x45, 0xa6, 0x62, 0x6f, 0x79, 0xfe, 0xe1, 0xf7, 0xcb, 0x3f, 0x89, 0x3f, 0x8e, 0x45, 0x24, 0x5d, 0x15, 0x19, 0x0a, 0xbb, 0xf5, 0x79, 0xca, 0xef, 0x97, 0x27, 0x24, 0x1c, 0xa7,
0x4f, 0x2c, 0x93, 0x9a, 0xc7, 0x59, 0x00, 0x26, 0x01, 0x04, 0xcb, 0x67, 0x90, 0x4c, 0xb4, 0xe1, 0x67, 0x96, 0x49, 0xcd, 0xd3, 0x22, 0x02, 0x93, 0x01, 0x82, 0xe5, 0x33, 0xc8, 0x26, 0xda, 0xf0,
0xe5, 0x86, 0x48, 0xa5, 0x12, 0xe1, 0x54, 0x26, 0x60, 0x1e, 0x79, 0x1a, 0x47, 0x2e, 0xb0, 0x5c, 0xea, 0x87, 0xc8, 0xa5, 0x12, 0xf1, 0x54, 0x66, 0x60, 0x9e, 0x79, 0x9e, 0x26, 0xbe, 0xb0, 0x5c,
0x01, 0x0a, 0x3e, 0x1b, 0x04, 0x80, 0x62, 0xc0, 0x23, 0x48, 0xc0, 0x08, 0x84, 0x09, 0x4b, 0x8d, 0x01, 0x0a, 0x3e, 0x1b, 0x44, 0x80, 0x62, 0xc0, 0x13, 0xc8, 0xc0, 0x08, 0x84, 0x09, 0xcb, 0x8d,
0x46, 0xdd, 0x3c, 0xdc, 0xa0, 0xec, 0x2b, 0xca, 0xd2, 0x38, 0x72, 0x81, 0x65, 0x0e, 0x65, 0x25, 0x46, 0xdd, 0x3c, 0xde, 0xa0, 0xec, 0x27, 0xca, 0xf2, 0x34, 0xf1, 0x85, 0x65, 0x1e, 0x65, 0x15,
0xda, 0xee, 0x47, 0x12, 0xa7, 0x59, 0xc0, 0x42, 0xad, 0x78, 0xa4, 0x23, 0xcd, 0x0b, 0x43, 0x90, 0xda, 0xee, 0x27, 0x12, 0xa7, 0x45, 0xc4, 0x62, 0xad, 0x78, 0xa2, 0x13, 0xcd, 0x4b, 0x43, 0x54,
0xdd, 0x15, 0x53, 0x31, 0x14, 0xab, 0x8d, 0xb9, 0x7d, 0x54, 0xa5, 0xd4, 0x76, 0x9f, 0xf6, 0xaf, 0x3c, 0x94, 0xa9, 0x0c, 0xe5, 0xd7, 0xc6, 0xdc, 0x3e, 0xd9, 0x65, 0xd4, 0xf6, 0x9e, 0xf6, 0xe9,
0x57, 0x31, 0x59, 0x82, 0x52, 0xc1, 0x37, 0xe0, 0xf8, 0x2f, 0xc0, 0x86, 0x53, 0x50, 0x62, 0x9b, 0x5f, 0x94, 0x29, 0x32, 0x94, 0x0a, 0xb8, 0x8d, 0xa7, 0xa0, 0xc4, 0x36, 0x77, 0xf4, 0x46, 0xc2,
0x3b, 0x78, 0x21, 0xfe, 0xfe, 0x95, 0x30, 0x28, 0xc5, 0xc3, 0x65, 0x70, 0x0f, 0x21, 0x5e, 0x00, 0xc3, 0x1b, 0x61, 0x50, 0x8a, 0xa7, 0xeb, 0xe8, 0x11, 0x62, 0xbc, 0x02, 0x14, 0x13, 0x81, 0xe2,
0x8a, 0x89, 0x40, 0x71, 0x2e, 0x2d, 0x36, 0x6f, 0xfc, 0xba, 0x2a, 0xe7, 0xd6, 0xbf, 0x2e, 0xe9, 0x52, 0x5a, 0x6c, 0xde, 0x85, 0x75, 0x55, 0xe5, 0xd6, 0xbf, 0x2e, 0xe9, 0x35, 0x86, 0x8c, 0xed,
0x35, 0x86, 0x8c, 0x55, 0x79, 0x29, 0xe6, 0x68, 0x67, 0x1a, 0xed, 0xcd, 0x57, 0x1d, 0x2f, 0x5f, 0x72, 0x71, 0xe6, 0x69, 0x6f, 0x1a, 0x1d, 0xcc, 0x57, 0x9d, 0xc0, 0xad, 0x3a, 0xf5, 0xaf, 0x66,
0x75, 0xea, 0x1f, 0xc9, 0xf8, 0xd3, 0xd8, 0xbc, 0xf5, 0x6b, 0x12, 0x41, 0xd9, 0x16, 0xe9, 0xfe, 0xfc, 0x6d, 0x6c, 0xde, 0x87, 0x35, 0x89, 0xa0, 0x6c, 0x8b, 0x74, 0xff, 0xf7, 0x1a, 0xc3, 0xf3,
0xef, 0x35, 0x86, 0xa7, 0xd5, 0xd4, 0x3f, 0xb6, 0x1d, 0xed, 0x96, 0xe7, 0xd4, 0xce, 0x9c, 0x71, 0xdd, 0xd4, 0xbf, 0xae, 0x1d, 0xed, 0x57, 0xe7, 0xd4, 0x2e, 0xbc, 0x71, 0xbc, 0x11, 0x8f, 0xfa,
0xbc, 0x11, 0x8f, 0xfa, 0xf3, 0x35, 0xf5, 0x16, 0x6b, 0xea, 0x2d, 0xd7, 0xd4, 0x7b, 0xca, 0x29, 0xf3, 0x35, 0x0d, 0x16, 0x6b, 0x1a, 0x2c, 0xd7, 0x34, 0x78, 0x71, 0x94, 0xcc, 0x1d, 0x25, 0x0b,
0x99, 0xe7, 0x94, 0x2c, 0x72, 0x4a, 0x96, 0x39, 0x25, 0xaf, 0x39, 0x25, 0xcf, 0x6f, 0xd4, 0xbb, 0x47, 0xc9, 0xd2, 0x51, 0xf2, 0xee, 0x28, 0x79, 0xfd, 0xa0, 0xc1, 0xed, 0x5e, 0xf5, 0x52, 0x9f,
0xde, 0x29, 0xbf, 0xf6, 0x3d, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x7e, 0x00, 0x08, 0x5a, 0x02, 0x00, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x82, 0x5b, 0x80, 0x29, 0x02, 0x00, 0x00,
0x00,
} }
func (m *PartialObjectMetadataList) Marshal() (dAtA []byte, err error) { func (m *PartialObjectMetadataList) Marshal() (dAtA []byte, err error) {

View File

@ -22,7 +22,6 @@ syntax = 'proto2';
package k8s.io.apimachinery.pkg.apis.meta.v1beta1; package k8s.io.apimachinery.pkg.apis.meta.v1beta1;
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";
// Package-wide variables from generator "generated". // Package-wide variables from generator "generated".

View File

@ -19,7 +19,6 @@ package v1beta1
import ( import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
) )
// GroupName is the group name for this API. // GroupName is the group name for this API.
@ -33,12 +32,6 @@ func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind() return SchemeGroupVersion.WithKind(kind).GroupKind()
} }
// scheme is the registry for the common types that adhere to the meta v1beta1 API spec.
var scheme = runtime.NewScheme()
// ParameterCodec knows about query parameters used with the meta v1beta1 API spec.
var ParameterCodec = runtime.NewParameterCodec(scheme)
// AddMetaToScheme registers base meta types into schemas. // AddMetaToScheme registers base meta types into schemas.
func AddMetaToScheme(scheme *runtime.Scheme) error { func AddMetaToScheme(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion, scheme.AddKnownTypes(SchemeGroupVersion,
@ -48,14 +41,5 @@ func AddMetaToScheme(scheme *runtime.Scheme) error {
&PartialObjectMetadataList{}, &PartialObjectMetadataList{},
) )
return scheme.AddConversionFuncs( return nil
Convert_Slice_string_To_v1beta1_IncludeObjectPolicy,
)
}
func init() {
utilruntime.Must(AddMetaToScheme(scheme))
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
utilruntime.Must(RegisterDefaults(scheme))
} }

View File

@ -54,7 +54,8 @@ type Converter struct {
generatedConversionFuncs ConversionFuncs generatedConversionFuncs ConversionFuncs
// Set of conversions that should be treated as a no-op // Set of conversions that should be treated as a no-op
ignoredConversions map[typePair]struct{} ignoredConversions map[typePair]struct{}
ignoredUntypedConversions map[typePair]struct{}
// This is a map from a source field type and name, to a list of destination // This is a map from a source field type and name, to a list of destination
// field type and name. // field type and name.
@ -83,17 +84,23 @@ type Converter struct {
// NewConverter creates a new Converter object. // NewConverter creates a new Converter object.
func NewConverter(nameFn NameFunc) *Converter { func NewConverter(nameFn NameFunc) *Converter {
c := &Converter{ c := &Converter{
conversionFuncs: NewConversionFuncs(), conversionFuncs: NewConversionFuncs(),
generatedConversionFuncs: NewConversionFuncs(), generatedConversionFuncs: NewConversionFuncs(),
ignoredConversions: make(map[typePair]struct{}), ignoredConversions: make(map[typePair]struct{}),
nameFunc: nameFn, ignoredUntypedConversions: make(map[typePair]struct{}),
structFieldDests: make(map[typeNamePair][]typeNamePair), nameFunc: nameFn,
structFieldSources: make(map[typeNamePair][]typeNamePair), structFieldDests: make(map[typeNamePair][]typeNamePair),
structFieldSources: make(map[typeNamePair][]typeNamePair),
inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc), inputFieldMappingFuncs: make(map[reflect.Type]FieldMappingFunc),
inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags), inputDefaultFlags: make(map[reflect.Type]FieldMatchingFlags),
} }
c.RegisterConversionFunc(Convert_Slice_byte_To_Slice_byte) c.RegisterUntypedConversionFunc(
(*[]byte)(nil), (*[]byte)(nil),
func(a, b interface{}, s Scope) error {
return Convert_Slice_byte_To_Slice_byte(a.(*[]byte), b.(*[]byte), s)
},
)
return c return c
} }
@ -153,31 +160,14 @@ type FieldMappingFunc func(key string, sourceTag, destTag reflect.StructTag) (so
func NewConversionFuncs() ConversionFuncs { func NewConversionFuncs() ConversionFuncs {
return ConversionFuncs{ return ConversionFuncs{
fns: make(map[typePair]reflect.Value),
untyped: make(map[typePair]ConversionFunc), untyped: make(map[typePair]ConversionFunc),
} }
} }
type ConversionFuncs struct { type ConversionFuncs struct {
fns map[typePair]reflect.Value
untyped map[typePair]ConversionFunc untyped map[typePair]ConversionFunc
} }
// Add adds the provided conversion functions to the lookup table - they must have the signature
// `func(type1, type2, Scope) error`. Functions are added in the order passed and will override
// previously registered pairs.
func (c ConversionFuncs) Add(fns ...interface{}) error {
for _, fn := range fns {
fv := reflect.ValueOf(fn)
ft := fv.Type()
if err := verifyConversionFunctionSignature(ft); err != nil {
return err
}
c.fns[typePair{ft.In(0).Elem(), ft.In(1).Elem()}] = fv
}
return nil
}
// AddUntyped adds the provided conversion function to the lookup table for the types that are // AddUntyped adds the provided conversion function to the lookup table for the types that are
// supplied as a and b. a and b must be pointers or an error is returned. This method overwrites // supplied as a and b. a and b must be pointers or an error is returned. This method overwrites
// previously defined functions. // previously defined functions.
@ -197,12 +187,6 @@ func (c ConversionFuncs) AddUntyped(a, b interface{}, fn ConversionFunc) error {
// both other and c, with other conversions taking precedence. // both other and c, with other conversions taking precedence.
func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs { func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs {
merged := NewConversionFuncs() merged := NewConversionFuncs()
for k, v := range c.fns {
merged.fns[k] = v
}
for k, v := range other.fns {
merged.fns[k] = v
}
for k, v := range c.untyped { for k, v := range c.untyped {
merged.untyped[k] = v merged.untyped[k] = v
} }
@ -360,29 +344,6 @@ func verifyConversionFunctionSignature(ft reflect.Type) error {
return nil return nil
} }
// RegisterConversionFunc registers a conversion func with the
// Converter. conversionFunc must take three parameters: a pointer to the input
// type, a pointer to the output type, and a conversion.Scope (which should be
// used if recursive conversion calls are desired). It must return an error.
//
// Example:
// c.RegisterConversionFunc(
// func(in *Pod, out *v1.Pod, s Scope) error {
// // conversion logic...
// return nil
// })
// DEPRECATED: Will be removed in favor of RegisterUntypedConversionFunc
func (c *Converter) RegisterConversionFunc(conversionFunc interface{}) error {
return c.conversionFuncs.Add(conversionFunc)
}
// Similar to RegisterConversionFunc, but registers conversion function that were
// automatically generated.
// DEPRECATED: Will be removed in favor of RegisterGeneratedUntypedConversionFunc
func (c *Converter) RegisterGeneratedConversionFunc(conversionFunc interface{}) error {
return c.generatedConversionFuncs.Add(conversionFunc)
}
// RegisterUntypedConversionFunc registers a function that converts between a and b by passing objects of those // RegisterUntypedConversionFunc registers a function that converts between a and b by passing objects of those
// types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce // types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
// any other guarantee. // any other guarantee.
@ -409,6 +370,7 @@ func (c *Converter) RegisterIgnoredConversion(from, to interface{}) error {
return fmt.Errorf("expected pointer arg for 'to' param 1, got: %v", typeTo) return fmt.Errorf("expected pointer arg for 'to' param 1, got: %v", typeTo)
} }
c.ignoredConversions[typePair{typeFrom.Elem(), typeTo.Elem()}] = struct{}{} c.ignoredConversions[typePair{typeFrom.Elem(), typeTo.Elem()}] = struct{}{}
c.ignoredUntypedConversions[typePair{typeFrom, typeTo}] = struct{}{}
return nil return nil
} }
@ -491,6 +453,11 @@ func (c *Converter) doConversion(src, dest interface{}, flags FieldMatchingFlags
flags: flags, flags: flags,
meta: meta, meta: meta,
} }
// ignore conversions of this type
if _, ok := c.ignoredUntypedConversions[pair]; ok {
return nil
}
if fn, ok := c.conversionFuncs.untyped[pair]; ok { if fn, ok := c.conversionFuncs.untyped[pair]; ok {
return fn(src, dest, scope) return fn(src, dest, scope)
} }
@ -517,33 +484,20 @@ func (c *Converter) doConversion(src, dest interface{}, flags FieldMatchingFlags
return f(sv, dv, scope) return f(sv, dv, scope)
} }
// callCustom calls 'custom' with sv & dv. custom must be a conversion function. // callUntyped calls predefined conversion func.
func (c *Converter) callCustom(sv, dv, custom reflect.Value, scope *scope) error { func (c *Converter) callUntyped(sv, dv reflect.Value, f ConversionFunc, scope *scope) error {
if !sv.CanAddr() {
sv2 := reflect.New(sv.Type())
sv2.Elem().Set(sv)
sv = sv2
} else {
sv = sv.Addr()
}
if !dv.CanAddr() { if !dv.CanAddr() {
if !dv.CanSet() { return scope.errorf("cant addr dest")
return scope.errorf("can't addr or set dest.") }
} var svPointer reflect.Value
dvOrig := dv if sv.CanAddr() {
dv := reflect.New(dvOrig.Type()) svPointer = sv.Addr()
defer func() { dvOrig.Set(dv) }()
} else { } else {
dv = dv.Addr() svPointer = reflect.New(sv.Type())
svPointer.Elem().Set(sv)
} }
args := []reflect.Value{sv, dv, reflect.ValueOf(scope)} dvPointer := dv.Addr()
ret := custom.Call(args)[0].Interface() return f(svPointer.Interface(), dvPointer.Interface(), scope)
// This convolution is necessary because nil interfaces won't convert
// to errors.
if ret == nil {
return nil
}
return ret.(error)
} }
// convert recursively copies sv into dv, calling an appropriate conversion function if // convert recursively copies sv into dv, calling an appropriate conversion function if
@ -561,17 +515,12 @@ func (c *Converter) convert(sv, dv reflect.Value, scope *scope) error {
} }
// Convert sv to dv. // Convert sv to dv.
if fv, ok := c.conversionFuncs.fns[pair]; ok { pair = typePair{reflect.PtrTo(sv.Type()), reflect.PtrTo(dv.Type())}
if c.Debug != nil { if f, ok := c.conversionFuncs.untyped[pair]; ok {
c.Debug.Logf("Calling custom conversion of '%v' to '%v'", st, dt) return c.callUntyped(sv, dv, f, scope)
}
return c.callCustom(sv, dv, fv, scope)
} }
if fv, ok := c.generatedConversionFuncs.fns[pair]; ok { if f, ok := c.generatedConversionFuncs.untyped[pair]; ok {
if c.Debug != nil { return c.callUntyped(sv, dv, f, scope)
c.Debug.Logf("Calling generated conversion of '%v' to '%v'", st, dt)
}
return c.callCustom(sv, dv, fv, scope)
} }
return c.defaultConvert(sv, dv, scope) return c.defaultConvert(sv, dv, scope)

View File

@ -53,14 +53,6 @@ func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, st
return key, key return key, key
} }
// DefaultStringConversions are helpers for converting []string and string to real values.
var DefaultStringConversions = []interface{}{
Convert_Slice_string_To_string,
Convert_Slice_string_To_int,
Convert_Slice_string_To_bool,
Convert_Slice_string_To_int64,
}
func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error { func Convert_Slice_string_To_string(in *[]string, out *string, s conversion.Scope) error {
if len(*in) == 0 { if len(*in) == 0 {
*out = "" *out = ""
@ -178,3 +170,27 @@ func Convert_Slice_string_To_Pointer_int64(in *[]string, out **int64, s conversi
*out = &i *out = &i
return nil return nil
} }
func RegisterStringConversions(s *Scheme) error {
if err := s.AddConversionFunc((*[]string)(nil), (*string)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_Slice_string_To_string(a.(*[]string), b.(*string), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*[]string)(nil), (*int)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_Slice_string_To_int(a.(*[]string), b.(*int), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*[]string)(nil), (*bool)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_Slice_string_To_bool(a.(*[]string), b.(*bool), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*[]string)(nil), (*int64)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_Slice_string_To_int64(a.(*[]string), b.(*int64), scope)
}); err != nil {
return err
}
return nil
}

View File

@ -134,9 +134,16 @@ func Convert_runtime_RawExtension_To_runtime_Object(in *RawExtension, out *Objec
return nil return nil
} }
func DefaultEmbeddedConversions() []interface{} { func RegisterEmbeddedConversions(s *Scheme) error {
return []interface{}{ if err := s.AddConversionFunc((*Object)(nil), (*RawExtension)(nil), func(a, b interface{}, scope conversion.Scope) error {
Convert_runtime_Object_To_runtime_RawExtension, return Convert_runtime_Object_To_runtime_RawExtension(a.(*Object), b.(*RawExtension), scope)
Convert_runtime_RawExtension_To_runtime_Object, }); err != nil {
return err
} }
if err := s.AddConversionFunc((*RawExtension)(nil), (*Object)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_runtime_RawExtension_To_runtime_Object(a.(*RawExtension), b.(*Object), scope)
}); err != nil {
return err
}
return nil
} }

View File

@ -102,10 +102,10 @@ func NewScheme() *Scheme {
} }
s.converter = conversion.NewConverter(s.nameFunc) s.converter = conversion.NewConverter(s.nameFunc)
utilruntime.Must(s.AddConversionFuncs(DefaultEmbeddedConversions()...)) // Enable couple default conversions by default.
utilruntime.Must(RegisterEmbeddedConversions(s))
utilruntime.Must(RegisterStringConversions(s))
// Enable map[string][]string conversions by default
utilruntime.Must(s.AddConversionFuncs(DefaultStringConversions...))
utilruntime.Must(s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields)) utilruntime.Must(s.RegisterInputDefaults(&map[string][]string{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
utilruntime.Must(s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields)) utilruntime.Must(s.RegisterInputDefaults(&url.Values{}, JSONKeyMapper, conversion.AllowDifferentFieldTypeNames|conversion.IgnoreMissingFields))
return s return s
@ -308,45 +308,6 @@ func (s *Scheme) AddIgnoredConversionType(from, to interface{}) error {
return s.converter.RegisterIgnoredConversion(from, to) return s.converter.RegisterIgnoredConversion(from, to)
} }
// AddConversionFuncs adds functions to the list of conversion functions. The given
// functions should know how to convert between two of your API objects, or their
// sub-objects. We deduce how to call these functions from the types of their two
// parameters; see the comment for Converter.Register.
//
// Note that, if you need to copy sub-objects that didn't change, you can use the
// conversion.Scope object that will be passed to your conversion function.
// Additionally, all conversions started by Scheme will set the SrcVersion and
// DestVersion fields on the Meta object. Example:
//
// s.AddConversionFuncs(
// func(in *InternalObject, out *ExternalObject, scope conversion.Scope) error {
// // You can depend on Meta() being non-nil, and this being set to
// // the source version, e.g., ""
// s.Meta().SrcVersion
// // You can depend on this being set to the destination version,
// // e.g., "v1".
// s.Meta().DestVersion
// // Call scope.Convert to copy sub-fields.
// s.Convert(&in.SubFieldThatMoved, &out.NewLocation.NewName, 0)
// return nil
// },
// )
//
// (For more detail about conversion functions, see Converter.Register's comment.)
//
// Also note that the default behavior, if you don't add a conversion function, is to
// sanely copy fields that have the same names and same type names. It's OK if the
// destination type has extra fields, but it must not remove any. So you only need to
// add conversion functions for things with changed/removed fields.
func (s *Scheme) AddConversionFuncs(conversionFuncs ...interface{}) error {
for _, f := range conversionFuncs {
if err := s.converter.RegisterConversionFunc(f); err != nil {
return err
}
}
return nil
}
// AddConversionFunc registers a function that converts between a and b by passing objects of those // AddConversionFunc registers a function that converts between a and b by passing objects of those
// types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce // types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
// any other guarantee. // any other guarantee.

View File

@ -52,23 +52,26 @@ func (RealClock) Since(ts time.Time) time.Duration {
return time.Since(ts) return time.Since(ts)
} }
// Same as time.After(d). // After is the same as time.After(d).
func (RealClock) After(d time.Duration) <-chan time.Time { func (RealClock) After(d time.Duration) <-chan time.Time {
return time.After(d) return time.After(d)
} }
// NewTimer returns a new Timer.
func (RealClock) NewTimer(d time.Duration) Timer { func (RealClock) NewTimer(d time.Duration) Timer {
return &realTimer{ return &realTimer{
timer: time.NewTimer(d), timer: time.NewTimer(d),
} }
} }
// NewTicker returns a new Ticker.
func (RealClock) NewTicker(d time.Duration) Ticker { func (RealClock) NewTicker(d time.Duration) Ticker {
return &realTicker{ return &realTicker{
ticker: time.NewTicker(d), ticker: time.NewTicker(d),
} }
} }
// Sleep pauses the RealClock for duration d.
func (RealClock) Sleep(d time.Duration) { func (RealClock) Sleep(d time.Duration) {
time.Sleep(d) time.Sleep(d)
} }
@ -94,12 +97,14 @@ type fakeClockWaiter struct {
destChan chan time.Time destChan chan time.Time
} }
// NewFakePassiveClock returns a new FakePassiveClock.
func NewFakePassiveClock(t time.Time) *FakePassiveClock { func NewFakePassiveClock(t time.Time) *FakePassiveClock {
return &FakePassiveClock{ return &FakePassiveClock{
time: t, time: t,
} }
} }
// NewFakeClock returns a new FakeClock
func NewFakeClock(t time.Time) *FakeClock { func NewFakeClock(t time.Time) *FakeClock {
return &FakeClock{ return &FakeClock{
FakePassiveClock: *NewFakePassiveClock(t), FakePassiveClock: *NewFakePassiveClock(t),
@ -120,14 +125,14 @@ func (f *FakePassiveClock) Since(ts time.Time) time.Duration {
return f.time.Sub(ts) return f.time.Sub(ts)
} }
// Sets the time. // SetTime sets the time on the FakePassiveClock.
func (f *FakePassiveClock) SetTime(t time.Time) { func (f *FakePassiveClock) SetTime(t time.Time) {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
f.time = t f.time = t
} }
// Fake version of time.After(d). // After is the Fake version of time.After(d).
func (f *FakeClock) After(d time.Duration) <-chan time.Time { func (f *FakeClock) After(d time.Duration) <-chan time.Time {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
@ -140,7 +145,7 @@ func (f *FakeClock) After(d time.Duration) <-chan time.Time {
return ch return ch
} }
// Fake version of time.NewTimer(d). // NewTimer is the Fake version of time.NewTimer(d).
func (f *FakeClock) NewTimer(d time.Duration) Timer { func (f *FakeClock) NewTimer(d time.Duration) Timer {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
@ -157,6 +162,7 @@ func (f *FakeClock) NewTimer(d time.Duration) Timer {
return timer return timer
} }
// NewTicker returns a new Ticker.
func (f *FakeClock) NewTicker(d time.Duration) Ticker { func (f *FakeClock) NewTicker(d time.Duration) Ticker {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
@ -174,14 +180,14 @@ func (f *FakeClock) NewTicker(d time.Duration) Ticker {
} }
} }
// Move clock by Duration, notify anyone that's called After, Tick, or NewTimer // Step moves clock by Duration, notifies anyone that's called After, Tick, or NewTimer
func (f *FakeClock) Step(d time.Duration) { func (f *FakeClock) Step(d time.Duration) {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
f.setTimeLocked(f.time.Add(d)) f.setTimeLocked(f.time.Add(d))
} }
// Sets the time. // SetTime sets the time on a FakeClock.
func (f *FakeClock) SetTime(t time.Time) { func (f *FakeClock) SetTime(t time.Time) {
f.lock.Lock() f.lock.Lock()
defer f.lock.Unlock() defer f.lock.Unlock()
@ -219,7 +225,7 @@ func (f *FakeClock) setTimeLocked(t time.Time) {
f.waiters = newWaiters f.waiters = newWaiters
} }
// Returns true if After has been called on f but not yet satisfied (so you can // HasWaiters returns true if After has been called on f but not yet satisfied (so you can
// write race-free tests). // write race-free tests).
func (f *FakeClock) HasWaiters() bool { func (f *FakeClock) HasWaiters() bool {
f.lock.RLock() f.lock.RLock()
@ -227,6 +233,7 @@ func (f *FakeClock) HasWaiters() bool {
return len(f.waiters) > 0 return len(f.waiters) > 0
} }
// Sleep pauses the FakeClock for duration d.
func (f *FakeClock) Sleep(d time.Duration) { func (f *FakeClock) Sleep(d time.Duration) {
f.Step(d) f.Step(d)
} }
@ -248,24 +255,25 @@ func (i *IntervalClock) Since(ts time.Time) time.Duration {
return i.Time.Sub(ts) return i.Time.Sub(ts)
} }
// Unimplemented, will panic. // After is currently unimplemented, will panic.
// TODO: make interval clock use FakeClock so this can be implemented. // TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) After(d time.Duration) <-chan time.Time { func (*IntervalClock) After(d time.Duration) <-chan time.Time {
panic("IntervalClock doesn't implement After") panic("IntervalClock doesn't implement After")
} }
// Unimplemented, will panic. // NewTimer is currently unimplemented, will panic.
// TODO: make interval clock use FakeClock so this can be implemented. // TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) NewTimer(d time.Duration) Timer { func (*IntervalClock) NewTimer(d time.Duration) Timer {
panic("IntervalClock doesn't implement NewTimer") panic("IntervalClock doesn't implement NewTimer")
} }
// Unimplemented, will panic. // NewTicker is currently unimplemented, will panic.
// TODO: make interval clock use FakeClock so this can be implemented. // TODO: make interval clock use FakeClock so this can be implemented.
func (*IntervalClock) NewTicker(d time.Duration) Ticker { func (*IntervalClock) NewTicker(d time.Duration) Ticker {
panic("IntervalClock doesn't implement NewTicker") panic("IntervalClock doesn't implement NewTicker")
} }
// Sleep is currently unimplemented; will panic.
func (*IntervalClock) Sleep(d time.Duration) { func (*IntervalClock) Sleep(d time.Duration) {
panic("IntervalClock doesn't implement Sleep") panic("IntervalClock doesn't implement Sleep")
} }
@ -355,6 +363,7 @@ func (f *fakeTimer) Reset(d time.Duration) bool {
return false return false
} }
// Ticker defines the Ticker interface
type Ticker interface { type Ticker interface {
C() <-chan time.Time C() <-chan time.Time
Stop() Stop()

View File

@ -90,7 +90,7 @@ func (w emptyWatch) ResultChan() <-chan Event {
// FakeWatcher lets you test anything that consumes a watch.Interface; threadsafe. // FakeWatcher lets you test anything that consumes a watch.Interface; threadsafe.
type FakeWatcher struct { type FakeWatcher struct {
result chan Event result chan Event
Stopped bool stopped bool
sync.Mutex sync.Mutex
} }
@ -110,24 +110,24 @@ func NewFakeWithChanSize(size int, blocking bool) *FakeWatcher {
func (f *FakeWatcher) Stop() { func (f *FakeWatcher) Stop() {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
if !f.Stopped { if !f.stopped {
klog.V(4).Infof("Stopping fake watcher.") klog.V(4).Infof("Stopping fake watcher.")
close(f.result) close(f.result)
f.Stopped = true f.stopped = true
} }
} }
func (f *FakeWatcher) IsStopped() bool { func (f *FakeWatcher) IsStopped() bool {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
return f.Stopped return f.stopped
} }
// Reset prepares the watcher to be reused. // Reset prepares the watcher to be reused.
func (f *FakeWatcher) Reset() { func (f *FakeWatcher) Reset() {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
f.Stopped = false f.stopped = false
f.result = make(chan Event) f.result = make(chan Event)
} }

19
vendor/k8s.io/apiserver/go.mod generated vendored
View File

@ -2,7 +2,7 @@
module k8s.io/apiserver module k8s.io/apiserver
go 1.12 go 1.13
require ( require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
@ -38,16 +38,17 @@ require (
go.uber.org/zap v1.10.0 go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 // indirect
google.golang.org/grpc v1.23.1 google.golang.org/grpc v1.23.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/square/go-jose.v2 v2.2.2 gopkg.in/square/go-jose.v2 v2.2.2
gopkg.in/yaml.v2 v2.2.4 gopkg.in/yaml.v2 v2.2.4
gotest.tools v2.2.0+incompatible // indirect gotest.tools v2.2.0+incompatible // indirect
k8s.io/api v0.17.1 k8s.io/api v0.18.0-alpha.1
k8s.io/apimachinery v0.17.1 k8s.io/apimachinery v0.18.0-alpha.1
k8s.io/client-go v0.17.1 k8s.io/client-go v0.18.0-alpha.1
k8s.io/component-base v0.17.1 k8s.io/component-base v0.18.0-alpha.1
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f k8s.io/utils v0.0.0-20191114184206-e782cd3c129f
@ -58,8 +59,8 @@ require (
replace ( replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13 golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => k8s.io/api v0.17.1 k8s.io/api => k8s.io/api v0.18.0-alpha.1
k8s.io/apimachinery => k8s.io/apimachinery v0.17.1 k8s.io/apimachinery => k8s.io/apimachinery v0.18.0-alpha.1
k8s.io/client-go => k8s.io/client-go v0.17.1 k8s.io/client-go => k8s.io/client-go v0.18.0-alpha.1
k8s.io/component-base => k8s.io/component-base v0.17.1 k8s.io/component-base => k8s.io/component-base v0.18.0-alpha.1
) )

View File

@ -158,7 +158,7 @@ func (rl *respLogger) Log() {
latency := time.Since(rl.startTime) latency := time.Since(rl.startTime)
if klog.V(3) { if klog.V(3) {
if !rl.hijacked { if !rl.hijacked {
klog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) %v%v%v [%s %s]", rl.req.Method, rl.req.RequestURI, latency, rl.status, rl.statusStack, rl.addedInfo, rl.req.UserAgent(), rl.req.RemoteAddr)) klog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) %v [%s %s]%v%v", rl.req.Method, rl.req.RequestURI, latency, rl.status, rl.req.UserAgent(), rl.req.RemoteAddr, rl.statusStack, rl.addedInfo))
} else { } else {
klog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) hijacked [%s %s]", rl.req.Method, rl.req.RequestURI, latency, rl.req.UserAgent(), rl.req.RemoteAddr)) klog.InfoDepth(1, fmt.Sprintf("%s %s: (%v) hijacked [%s %s]", rl.req.Method, rl.req.RequestURI, latency, rl.req.UserAgent(), rl.req.RemoteAddr))
} }

105
vendor/k8s.io/client-go/README.md generated vendored
View File

@ -2,7 +2,8 @@
Go clients for talking to a [kubernetes](http://kubernetes.io/) cluster. Go clients for talking to a [kubernetes](http://kubernetes.io/) cluster.
We recommend using the `kubernetes-1.x.y` tag matching the current Kubernetes release (`kubernetes-1.15.3` at the time this was written). We recommend using the `v0.x.y` tags for Kubernetes releases >= `v1.17.0` and
`kubernetes-1.x.y` tags for Kubernetes releases < `v1.17.0`.
See [INSTALL.md](/INSTALL.md) for detailed installation instructions. See [INSTALL.md](/INSTALL.md) for detailed installation instructions.
`go get k8s.io/client-go@master` works, but will fetch `master`, which may be less stable than a tagged release. `go get k8s.io/client-go@master` works, but will fetch `master`, which may be less stable than a tagged release.
@ -44,42 +45,31 @@ See [INSTALL.md](/INSTALL.md) for detailed installation instructions.
### Versioning ### Versioning
`client-go` follows [semver](http://semver.org/). We will not make - For each `v1.x.y` Kubernetes release, the major version (first digit)
backwards-incompatible changes without incrementing the major version number. A would remain `0`.
change is backwards-incompatible either if it *i)* changes the public interfaces
of `client-go`, or *ii)* makes `client-go` incompatible with otherwise supported
versions of Kubernetes clusters.
Changes that add features in a backwards-compatible way will result in bumping - Bugfixes will result in the patch version (third digit) changing. PRs that are
the minor version (second digit) number.
Bugfixes will result in the patch version (third digit) changing. PRs that are
cherry-picked into an older Kubernetes release branch will result in an update cherry-picked into an older Kubernetes release branch will result in an update
to the corresponding branch in `client-go`, with a corresponding new tag to the corresponding branch in `client-go`, with a corresponding new tag
changing the patch version. changing the patch version.
A consequence of this is that `client-go` version numbers will be unrelated to
Kubernetes version numbers.
#### Branches and tags. #### Branches and tags.
We will create a new branch and tag for each increment in the major version number or We will create a new branch and tag for each increment in the minor version
minor version number. We will create only a new tag for each increment in the patch number. We will create only a new tag for each increment in the patch
version number. See [semver](http://semver.org/) for definitions of major, version number. See [semver](http://semver.org/) for definitions of major,
minor, and patch. minor, and patch.
The master branch will track HEAD in the main Kubernetes repo and The HEAD of the master branch in client-go will track the HEAD of the master
accumulate changes. Consider HEAD to have the version `x.(y+1).0-alpha` or branch in the main Kubernetes repo.
`(x+1).0.0-alpha` (depending on whether it has accumulated a breaking change or
not), where `x` and `y` are the current major and minor versions.
#### Compatibility: your code <-> client-go #### Compatibility: your code <-> client-go
`client-go` follows [semver](http://semver.org/), so until the major version of The `v0.x.y` tags indicate that go APIs may change in incompatible ways in
client-go gets increased, your code will compile and will continue to work with different versions.
explicitly supported versions of Kubernetes clusters. You must use a dependency
management system and pin a specific major version of `client-go` to get this See [INSTALL.md](INSTALL.md) for guidelines on requiring a specific
benefit, as HEAD follows the upstream Kubernetes repo. version of client-go.
#### Compatibility: client-go <-> Kubernetes clusters #### Compatibility: client-go <-> Kubernetes clusters
@ -92,16 +82,12 @@ We will backport bugfixes--but not new features--into older versions of
#### Compatibility matrix #### Compatibility matrix
| | Kubernetes 1.9 | Kubernetes 1.10 | Kubernetes 1.11 | Kubernetes 1.12 | Kubernetes 1.13 | Kubernetes 1.14 | Kubernetes 1.15 | | | Kubernetes 1.15 | Kubernetes 1.16 | Kubernetes 1.17 |
|---------------------|----------------|-----------------|-----------------|-----------------|-----------------|-----------------|-----------------| |-------------------------------|-----------------|-----------------|-----------------|
| client-go 6.0 | ✓ | +- | +- | +- | +- | +- | +- | | `kubernetes-1.15.0` | ✓ | +- | +- |
| client-go 7.0 | +- | ✓ | +- | +- | +- | +- | +- | | `kubernetes-1.16.0` | +- | ✓ | +- |
| client-go 8.0 | +- | +- | ✓ | +- | +- | +- | +- | | `kubernetes-1.17.0`/`v0.17.0` | +- | +- | ✓ |
| client-go 9.0 | +- | +- | +- | ✓ | +- | +- | +- | | `HEAD` | +- | +- | +- |
| client-go 10.0 | +- | +- | +- | +- | ✓ | +- | +- |
| client-go 11.0 | +- | +- | +- | +- | +- | ✓ | +- |
| client-go 12.0 | +- | +- | +- | +- | +- | +- | ✓ |
| client-go HEAD | +- | +- | +- | +- | +- | +- | +- |
Key: Key:
@ -122,19 +108,21 @@ between client-go versions.
| Branch | Canonical source code location | Maintenance status | | Branch | Canonical source code location | Maintenance status |
|----------------|--------------------------------------|-------------------------------| |----------------|--------------------------------------|-------------------------------|
| client-go 1.4 | Kubernetes main repo, 1.4 branch | = - | | `release-1.4` | Kubernetes main repo, 1.4 branch | = - |
| client-go 1.5 | Kubernetes main repo, 1.5 branch | = - | | `release-1.5` | Kubernetes main repo, 1.5 branch | = - |
| client-go 2.0 | Kubernetes main repo, 1.5 branch | = - | | `release-2.0` | Kubernetes main repo, 1.5 branch | = - |
| client-go 3.0 | Kubernetes main repo, 1.6 branch | = - | | `release-3.0` | Kubernetes main repo, 1.6 branch | = - |
| client-go 4.0 | Kubernetes main repo, 1.7 branch | = - | | `release-4.0` | Kubernetes main repo, 1.7 branch | = - |
| client-go 5.0 | Kubernetes main repo, 1.8 branch | = - | | `release-5.0` | Kubernetes main repo, 1.8 branch | = - |
| client-go 6.0 | Kubernetes main repo, 1.9 branch | = - | | `release-6.0` | Kubernetes main repo, 1.9 branch | = - |
| client-go 7.0 | Kubernetes main repo, 1.10 branch | = - | | `release-7.0` | Kubernetes main repo, 1.10 branch | = - |
| client-go 8.0 | Kubernetes main repo, 1.11 branch | =- | | `release-8.0` | Kubernetes main repo, 1.11 branch | =- |
| client-go 9.0 | Kubernetes main repo, 1.12 branch | =- | | `release-9.0` | Kubernetes main repo, 1.12 branch | =- |
| client-go 10.0 | Kubernetes main repo, 1.13 branch | ✓ | | `release-10.0` | Kubernetes main repo, 1.13 branch | =- |
| client-go 11.0 | Kubernetes main repo, 1.14 branch | ✓ | | `release-11.0` | Kubernetes main repo, 1.14 branch | ✓ |
| client-go 12.0 | Kubernetes main repo, 1.15 branch | ✓ | | `release-12.0` | Kubernetes main repo, 1.15 branch | ✓ |
| `release-13.0` | Kubernetes main repo, 1.16 branch | ✓ |
| `release-14.0` | Kubernetes main repo, 1.17 branch | ✓ |
| client-go HEAD | Kubernetes main repo, master branch | ✓ | | client-go HEAD | Kubernetes main repo, master branch | ✓ |
Key: Key:
@ -161,14 +149,19 @@ existing users won't be broken.
This repository is still a mirror of This repository is still a mirror of
[k8s.io/kubernetes/staging/src/client-go](https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/client-go), [k8s.io/kubernetes/staging/src/client-go](https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/client-go),
the code development is still done in the staging area. Since Kubernetes 1.8 the code development is still done in the staging area.
release, when syncing the code from the staging area, we also sync the Kubernetes
version tags to client-go, prefixed with "kubernetes-". For example, if you check Since Kubernetes `v1.8.0`, when syncing the code from the staging area,
out the `kubernetes-1.15.3` tag in client-go, the code you get is exactly the we also sync the Kubernetes version tags to client-go, prefixed with
same as if you check out the `v1.15.3` tag in Kubernetes, and change directory to `kubernetes-`. From Kubernetes `v1.17.0`, we also create matching semver
`staging/src/k8s.io/client-go`. The purpose is to let users quickly find matching `v0.x.y` tags for each `v1.x.y` Kubernetes release.
commits among published repos, like
[sample-apiserver](https://github.com/kubernetes/sample-apiserver), For example, if you check out the `kubernetes-1.17.0` or the `v0.17.0` tag in
client-go, the code you get is exactly the same as if you check out the `v1.17.0`
tag in Kubernetes, and change directory to `staging/src/k8s.io/client-go`.
The purpose is to let users quickly find matching commits among published repos,
like [sample-apiserver](https://github.com/kubernetes/sample-apiserver),
[apiextension-apiserver](https://github.com/kubernetes/apiextensions-apiserver), [apiextension-apiserver](https://github.com/kubernetes/apiextensions-apiserver),
etc. The Kubernetes version tag does NOT claim any backwards compatibility etc. The Kubernetes version tag does NOT claim any backwards compatibility
guarantees for client-go. Please check the [semantic versions](#versioning) if guarantees for client-go. Please check the [semantic versions](#versioning) if
@ -179,7 +172,7 @@ you care about backwards compatibility.
Use go1.11+ and fetch the desired version using the `go get` command. For example: Use go1.11+ and fetch the desired version using the `go get` command. For example:
``` ```
go get k8s.io/client-go@kubernetes-1.15.3 go get k8s.io/client-go@v0.17.0
``` ```
See [INSTALL.md](/INSTALL.md) for detailed instructions. See [INSTALL.md](/INSTALL.md) for detailed instructions.

10
vendor/k8s.io/client-go/go.mod generated vendored
View File

@ -2,7 +2,7 @@
module k8s.io/client-go module k8s.io/client-go
go 1.12 go 1.13
require ( require (
cloud.google.com/go v0.38.0 // indirect cloud.google.com/go v0.38.0 // indirect
@ -28,8 +28,8 @@ require (
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
google.golang.org/appengine v1.5.0 // indirect google.golang.org/appengine v1.5.0 // indirect
k8s.io/api v0.17.1 k8s.io/api v0.18.0-alpha.1
k8s.io/apimachinery v0.17.1 k8s.io/apimachinery v0.18.0-alpha.1
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f k8s.io/utils v0.0.0-20191114184206-e782cd3c129f
sigs.k8s.io/yaml v1.1.0 sigs.k8s.io/yaml v1.1.0
@ -38,6 +38,6 @@ require (
replace ( replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13 golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => k8s.io/api v0.17.1 k8s.io/api => k8s.io/api v0.18.0-alpha.1
k8s.io/apimachinery => k8s.io/apimachinery v0.17.1 k8s.io/apimachinery => k8s.io/apimachinery v0.18.0-alpha.1
) )

View File

@ -20,6 +20,7 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -42,6 +43,7 @@ import (
"k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1" "k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1"
"k8s.io/client-go/pkg/apis/clientauthentication/v1beta1" "k8s.io/client-go/pkg/apis/clientauthentication/v1beta1"
"k8s.io/client-go/tools/clientcmd/api" "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/tools/metrics"
"k8s.io/client-go/transport" "k8s.io/client-go/transport"
"k8s.io/client-go/util/connrotation" "k8s.io/client-go/util/connrotation"
"k8s.io/klog" "k8s.io/klog"
@ -260,6 +262,7 @@ func (a *Authenticator) cert() (*tls.Certificate, error) {
func (a *Authenticator) getCreds() (*credentials, error) { func (a *Authenticator) getCreds() (*credentials, error) {
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
if a.cachedCreds != nil && !a.credsExpired() { if a.cachedCreds != nil && !a.credsExpired() {
return a.cachedCreds, nil return a.cachedCreds, nil
} }
@ -267,6 +270,7 @@ func (a *Authenticator) getCreds() (*credentials, error) {
if err := a.refreshCredsLocked(nil); err != nil { if err := a.refreshCredsLocked(nil); err != nil {
return nil, err return nil, err
} }
return a.cachedCreds, nil return a.cachedCreds, nil
} }
@ -355,6 +359,17 @@ func (a *Authenticator) refreshCredsLocked(r *clientauthentication.Response) err
if err != nil { if err != nil {
return fmt.Errorf("failed parsing client key/certificate: %v", err) return fmt.Errorf("failed parsing client key/certificate: %v", err)
} }
// Leaf is initialized to be nil:
// https://golang.org/pkg/crypto/tls/#X509KeyPair
// Leaf certificate is the first certificate:
// https://golang.org/pkg/crypto/tls/#Certificate
// Populating leaf is useful for quickly accessing the underlying x509
// certificate values.
cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
if err != nil {
return fmt.Errorf("failed parsing client leaf certificate: %v", err)
}
newCreds.cert = &cert newCreds.cert = &cert
} }
@ -362,10 +377,20 @@ func (a *Authenticator) refreshCredsLocked(r *clientauthentication.Response) err
a.cachedCreds = newCreds a.cachedCreds = newCreds
// Only close all connections when TLS cert rotates. Token rotation doesn't // Only close all connections when TLS cert rotates. Token rotation doesn't
// need the extra noise. // need the extra noise.
if len(a.onRotateList) > 0 && oldCreds != nil && !reflect.DeepEqual(oldCreds.cert, a.cachedCreds.cert) { if oldCreds != nil && !reflect.DeepEqual(oldCreds.cert, a.cachedCreds.cert) {
// Can be nil if the exec auth plugin only returned token auth.
if oldCreds.cert != nil && oldCreds.cert.Leaf != nil {
metrics.ClientCertRotationAge.Observe(time.Now().Sub(oldCreds.cert.Leaf.NotBefore))
}
for _, onRotate := range a.onRotateList { for _, onRotate := range a.onRotateList {
onRotate() onRotate()
} }
} }
expiry := time.Time{}
if a.cachedCreds.cert != nil && a.cachedCreds.cert.Leaf != nil {
expiry = a.cachedCreds.cert.Leaf.NotAfter
}
expirationMetrics.set(a, expiry)
return nil return nil
} }

View File

@ -0,0 +1,60 @@
/*
Copyright 2018 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 exec
import (
"sync"
"time"
"k8s.io/client-go/tools/metrics"
)
type certificateExpirationTracker struct {
mu sync.RWMutex
m map[*Authenticator]time.Time
metricSet func(*time.Time)
}
var expirationMetrics = &certificateExpirationTracker{
m: map[*Authenticator]time.Time{},
metricSet: func(e *time.Time) {
metrics.ClientCertExpiry.Set(e)
},
}
// set stores the given expiration time and updates the updates the certificate
// expiry metric to the earliest expiration time.
func (c *certificateExpirationTracker) set(a *Authenticator, t time.Time) {
c.mu.Lock()
defer c.mu.Unlock()
c.m[a] = t
earliest := time.Time{}
for _, t := range c.m {
if t.IsZero() {
continue
}
if earliest.IsZero() || earliest.After(t) {
earliest = t
}
}
if earliest.IsZero() {
c.metricSet(nil)
} else {
c.metricSet(&earliest)
}
}

View File

@ -562,7 +562,7 @@ func (r *Request) tryThrottle() error {
} }
if latency := time.Since(now); latency > longThrottleLatency { if latency := time.Since(now); latency > longThrottleLatency {
klog.V(4).Infof("Throttling request took %v, request: %s:%s", latency, r.verb, r.URL().String()) klog.V(3).Infof("Throttling request took %v, request: %s:%s", latency, r.verb, r.URL().String())
} }
return err return err
@ -806,19 +806,24 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
r.backoff.UpdateBackoff(r.URL(), err, resp.StatusCode) r.backoff.UpdateBackoff(r.URL(), err, resp.StatusCode)
} }
if err != nil { if err != nil {
// "Connection reset by peer" is usually a transient error. // "Connection reset by peer", "Connection refused" or "apiserver is shutting down" are usually a transient errors.
// Thus in case of "GET" operations, we simply retry it. // Thus in case of "GET" operations, we simply retry it.
// We are not automatically retrying "write" operations, as // We are not automatically retrying "write" operations, as
// they are not idempotent. // they are not idempotent.
if !net.IsConnectionReset(err) || r.verb != "GET" { if r.verb != "GET" {
return err return err
} }
// For the purpose of retry, we set the artificial "retry-after" response. // For connection errors and apiserver shutdown errors retry.
// TODO: Should we clean the original response if it exists? if net.IsConnectionReset(err) || net.IsConnectionRefused(err) {
resp = &http.Response{ // For the purpose of retry, we set the artificial "retry-after" response.
StatusCode: http.StatusInternalServerError, // TODO: Should we clean the original response if it exists?
Header: http.Header{"Retry-After": []string{"1"}}, resp = &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte{})), StatusCode: http.StatusInternalServerError,
Header: http.Header{"Retry-After": []string{"1"}},
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
}
} else {
return err
} }
} }

View File

@ -26,6 +26,16 @@ import (
var registerMetrics sync.Once var registerMetrics sync.Once
// DurationMetric is a measurement of some amount of time.
type DurationMetric interface {
Observe(duration time.Duration)
}
// ExpiryMetric sets some time of expiry. If nil, assume not relevant.
type ExpiryMetric interface {
Set(expiry *time.Time)
}
// LatencyMetric observes client latency partitioned by verb and url. // LatencyMetric observes client latency partitioned by verb and url.
type LatencyMetric interface { type LatencyMetric interface {
Observe(verb string, u url.URL, latency time.Duration) Observe(verb string, u url.URL, latency time.Duration)
@ -37,21 +47,51 @@ type ResultMetric interface {
} }
var ( var (
// ClientCertExpiry is the expiry time of a client certificate
ClientCertExpiry ExpiryMetric = noopExpiry{}
// ClientCertRotationAge is the age of a certificate that has just been rotated.
ClientCertRotationAge DurationMetric = noopDuration{}
// RequestLatency is the latency metric that rest clients will update. // RequestLatency is the latency metric that rest clients will update.
RequestLatency LatencyMetric = noopLatency{} RequestLatency LatencyMetric = noopLatency{}
// RequestResult is the result metric that rest clients will update. // RequestResult is the result metric that rest clients will update.
RequestResult ResultMetric = noopResult{} RequestResult ResultMetric = noopResult{}
) )
// RegisterOpts contains all the metrics to register. Metrics may be nil.
type RegisterOpts struct {
ClientCertExpiry ExpiryMetric
ClientCertRotationAge DurationMetric
RequestLatency LatencyMetric
RequestResult ResultMetric
}
// Register registers metrics for the rest client to use. This can // Register registers metrics for the rest client to use. This can
// only be called once. // only be called once.
func Register(lm LatencyMetric, rm ResultMetric) { func Register(opts RegisterOpts) {
registerMetrics.Do(func() { registerMetrics.Do(func() {
RequestLatency = lm if opts.ClientCertExpiry != nil {
RequestResult = rm ClientCertExpiry = opts.ClientCertExpiry
}
if opts.ClientCertRotationAge != nil {
ClientCertRotationAge = opts.ClientCertRotationAge
}
if opts.RequestLatency != nil {
RequestLatency = opts.RequestLatency
}
if opts.RequestResult != nil {
RequestResult = opts.RequestResult
}
}) })
} }
type noopDuration struct{}
func (noopDuration) Observe(time.Duration) {}
type noopExpiry struct{}
func (noopExpiry) Set(*time.Time) {}
type noopLatency struct{} type noopLatency struct{}
func (noopLatency) Observe(string, url.URL, time.Duration) {} func (noopLatency) Observe(string, url.URL, time.Duration) {}

2
vendor/k8s.io/cri-api/go.mod generated vendored
View File

@ -2,7 +2,7 @@
module k8s.io/cri-api module k8s.io/cri-api
go 1.12 go 1.13
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect

File diff suppressed because it is too large Load Diff

View File

@ -543,6 +543,19 @@ message LinuxContainerResources {
string cpuset_cpus = 6; string cpuset_cpus = 6;
// CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified). // CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified).
string cpuset_mems = 7; string cpuset_mems = 7;
// List of HugepageLimits to limit the HugeTLB usage of container per page size. Default: nil (not specified).
repeated HugepageLimit hugepage_limits = 8;
}
// HugepageLimit corresponds to the file`hugetlb.<hugepagesize>.limit_in_byte` in container level cgroup.
// For example, `PageSize=1GB`, `Limit=1073741824` means setting `1073741824` bytes to hugetlb.1GB.limit_in_bytes.
message HugepageLimit {
// The value of PageSize has the format <size><unit-prefix>B (2MB, 1GB),
// and must match the <hugepagesize> of the corresponding control file found in `hugetlb.<hugepagesize>.limit_in_bytes`.
// The values of <unit-prefix> are intended to be parsed using base 1024("1KB" = 1024, "1MB" = 1048576, etc).
string page_size = 1;
// limit in bytes of hugepagesize HugeTLB usage.
uint64 limit = 2;
} }
// SELinuxOption are the labels to be applied to the container. // SELinuxOption are the labels to be applied to the container.

6
vendor/k8s.io/kubernetes/go.mod generated vendored
View File

@ -4,7 +4,7 @@
module k8s.io/kubernetes module k8s.io/kubernetes
go 1.12 go 1.13
require ( require (
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
@ -14,7 +14,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.2.0 github.com/Azure/go-autorest/autorest/to v0.2.0
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534 github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab
github.com/Microsoft/go-winio v0.4.11 github.com/Microsoft/go-winio v0.4.14
github.com/Microsoft/hcsshim v0.0.0-20190417211021-672e52e9209d github.com/Microsoft/hcsshim v0.0.0-20190417211021-672e52e9209d
github.com/PuerkitoBio/purell v1.1.1 github.com/PuerkitoBio/purell v1.1.1
github.com/Rican7/retry v0.1.0 // indirect github.com/Rican7/retry v0.1.0 // indirect
@ -185,7 +185,7 @@ replace (
github.com/GoogleCloudPlatform/k8s-cloud-provider => github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534 github.com/GoogleCloudPlatform/k8s-cloud-provider => github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534
github.com/JeffAshton/win_pdh => github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab github.com/JeffAshton/win_pdh => github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab
github.com/MakeNowJust/heredoc => github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd github.com/MakeNowJust/heredoc => github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd
github.com/Microsoft/go-winio => github.com/Microsoft/go-winio v0.4.11 github.com/Microsoft/go-winio => github.com/Microsoft/go-winio v0.4.14
github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.0.0-20190417211021-672e52e9209d github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.0.0-20190417211021-672e52e9209d
github.com/NYTimes/gziphandler => github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46 github.com/NYTimes/gziphandler => github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46
github.com/OpenPeeDeeP/depguard => github.com/OpenPeeDeeP/depguard v1.0.1 github.com/OpenPeeDeeP/depguard => github.com/OpenPeeDeeP/depguard v1.0.1

View File

@ -40,6 +40,14 @@ func (rl *ResourceList) Memory() *resource.Quantity {
return &resource.Quantity{Format: resource.BinarySI} return &resource.Quantity{Format: resource.BinarySI}
} }
// Storage returns the Storage limit if specified.
func (rl *ResourceList) Storage() *resource.Quantity {
if val, ok := (*rl)[ResourceStorage]; ok {
return &val
}
return &resource.Quantity{Format: resource.BinarySI}
}
// Pods returns the list of pods // Pods returns the list of pods
func (rl *ResourceList) Pods() *resource.Quantity { func (rl *ResourceList) Pods() *resource.Quantity {
if val, ok := (*rl)[ResourcePods]; ok { if val, ok := (*rl)[ResourcePods]; ok {