mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-04-12 00:00:26 +08:00
Merge pull request #63565 from roycaihw/bump-kube-openapi-dep
Automatic merge from submit-queue (batch tested with PRs 59034, 63565, 63533). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Bump kube-openapi dependency picks: https://github.com/kubernetes/kube-openapi/pull/67 ref: https://github.com/kubernetes/kubernetes/issues/63494 **Release note**: ```release-note NONE ``` Kubernetes-commit: 3663dc757e05fb79f23a14ad4f2ba832d6e5962c
This commit is contained in:
+11
-6
@@ -73,7 +73,6 @@ var (
|
||||
mapStringInterfaceType = reflect.TypeOf(map[string]interface{}{})
|
||||
stringType = reflect.TypeOf(string(""))
|
||||
int64Type = reflect.TypeOf(int64(0))
|
||||
uint64Type = reflect.TypeOf(uint64(0))
|
||||
float64Type = reflect.TypeOf(float64(0))
|
||||
boolType = reflect.TypeOf(bool(false))
|
||||
fieldCache = newFieldsCache()
|
||||
@@ -438,13 +437,15 @@ func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]inte
|
||||
}
|
||||
|
||||
// DeepCopyJSON deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
|
||||
// types produced by json.Unmarshal().
|
||||
// types produced by json.Unmarshal() and also int64.
|
||||
// bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil
|
||||
func DeepCopyJSON(x map[string]interface{}) map[string]interface{} {
|
||||
return DeepCopyJSONValue(x).(map[string]interface{})
|
||||
}
|
||||
|
||||
// DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
|
||||
// types produced by json.Unmarshal().
|
||||
// types produced by json.Unmarshal() and also int64.
|
||||
// bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil
|
||||
func DeepCopyJSONValue(x interface{}) interface{} {
|
||||
switch x := x.(type) {
|
||||
case map[string]interface{}:
|
||||
@@ -591,10 +592,14 @@ func toUnstructured(sv, dv reflect.Value) error {
|
||||
dv.Set(reflect.ValueOf(sv.Int()))
|
||||
return nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
||||
dv.Set(reflect.New(uint64Type))
|
||||
uVal := sv.Uint()
|
||||
if uVal > math.MaxInt64 {
|
||||
return fmt.Errorf("unsigned value %d does not fit into int64 (overflow)", uVal)
|
||||
}
|
||||
dv.Set(reflect.ValueOf(sv.Uint()))
|
||||
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
||||
dv.Set(reflect.New(int64Type))
|
||||
}
|
||||
dv.Set(reflect.ValueOf(int64(uVal)))
|
||||
return nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
|
||||
|
||||
+144
@@ -21,8 +21,11 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
// Scheme defines methods for serializing and deserializing API objects, a type
|
||||
@@ -68,6 +71,13 @@ type Scheme struct {
|
||||
// converter stores all registered conversion functions. It also has
|
||||
// default coverting behavior.
|
||||
converter *conversion.Converter
|
||||
|
||||
// versionPriority is a map of groups to ordered lists of versions for those groups indicating the
|
||||
// default priorities of these versions as registered in the scheme
|
||||
versionPriority map[string][]string
|
||||
|
||||
// observedVersions keeps track of the order we've seen versions during type registration
|
||||
observedVersions []schema.GroupVersion
|
||||
}
|
||||
|
||||
// Function to convert a field selector to internal representation.
|
||||
@@ -82,6 +92,7 @@ func NewScheme() *Scheme {
|
||||
unversionedKinds: map[string]reflect.Type{},
|
||||
fieldLabelConversionFuncs: map[string]map[string]FieldLabelConversionFunc{},
|
||||
defaulterFuncs: map[reflect.Type]func(interface{}){},
|
||||
versionPriority: map[string][]string{},
|
||||
}
|
||||
s.converter = conversion.NewConverter(s.nameFunc)
|
||||
|
||||
@@ -141,6 +152,7 @@ func (s *Scheme) Converter() *conversion.Converter {
|
||||
// TODO: there is discussion about removing unversioned and replacing it with objects that are manifest into
|
||||
// every version with particular schemas. Resolve this method at that point.
|
||||
func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Object) {
|
||||
s.addObservedVersion(version)
|
||||
s.AddKnownTypes(version, types...)
|
||||
for _, obj := range types {
|
||||
t := reflect.TypeOf(obj).Elem()
|
||||
@@ -158,6 +170,7 @@ func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Objec
|
||||
// the struct becomes the "kind" field when encoding. Version may not be empty - use the
|
||||
// APIVersionInternal constant if you have a type that does not have a formal version.
|
||||
func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object) {
|
||||
s.addObservedVersion(gv)
|
||||
for _, obj := range types {
|
||||
t := reflect.TypeOf(obj)
|
||||
if t.Kind() != reflect.Ptr {
|
||||
@@ -173,6 +186,7 @@ func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object) {
|
||||
// your structs. Version may not be empty - use the APIVersionInternal constant if you have a
|
||||
// type that does not have a formal version.
|
||||
func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
|
||||
s.addObservedVersion(gvk.GroupVersion())
|
||||
t := reflect.TypeOf(obj)
|
||||
if len(gvk.Version) == 0 {
|
||||
panic(fmt.Sprintf("version is required on all types: %s %v", gvk, t))
|
||||
@@ -620,3 +634,133 @@ func setTargetKind(obj Object, kind schema.GroupVersionKind) {
|
||||
}
|
||||
obj.GetObjectKind().SetGroupVersionKind(kind)
|
||||
}
|
||||
|
||||
// SetVersionPriority allows specifying a precise order of priority. All specified versions must be in the same group,
|
||||
// and the specified order overwrites any previously specified order for this group
|
||||
func (s *Scheme) SetVersionPriority(versions ...schema.GroupVersion) error {
|
||||
groups := sets.String{}
|
||||
order := []string{}
|
||||
for _, version := range versions {
|
||||
if len(version.Version) == 0 || version.Version == APIVersionInternal {
|
||||
return fmt.Errorf("internal versions cannot be prioritized: %v", version)
|
||||
}
|
||||
|
||||
groups.Insert(version.Group)
|
||||
order = append(order, version.Version)
|
||||
}
|
||||
if len(groups) != 1 {
|
||||
return fmt.Errorf("must register versions for exactly one group: %v", strings.Join(groups.List(), ", "))
|
||||
}
|
||||
|
||||
s.versionPriority[groups.List()[0]] = order
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrioritizedVersionsForGroup returns versions for a single group in priority order
|
||||
func (s *Scheme) PrioritizedVersionsForGroup(group string) []schema.GroupVersion {
|
||||
ret := []schema.GroupVersion{}
|
||||
for _, version := range s.versionPriority[group] {
|
||||
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
|
||||
}
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
if observedVersion.Group != group {
|
||||
continue
|
||||
}
|
||||
found := false
|
||||
for _, existing := range ret {
|
||||
if existing == observedVersion {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ret = append(ret, observedVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// PrioritizedVersionsAllGroups returns all known versions in their priority order. Groups are random, but
|
||||
// versions for a single group are prioritized
|
||||
func (s *Scheme) PrioritizedVersionsAllGroups() []schema.GroupVersion {
|
||||
ret := []schema.GroupVersion{}
|
||||
for group, versions := range s.versionPriority {
|
||||
for _, version := range versions {
|
||||
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
|
||||
}
|
||||
}
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
found := false
|
||||
for _, existing := range ret {
|
||||
if existing == observedVersion {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ret = append(ret, observedVersion)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// PreferredVersionAllGroups returns the most preferred version for every group.
|
||||
// group ordering is random.
|
||||
func (s *Scheme) PreferredVersionAllGroups() []schema.GroupVersion {
|
||||
ret := []schema.GroupVersion{}
|
||||
for group, versions := range s.versionPriority {
|
||||
for _, version := range versions {
|
||||
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
found := false
|
||||
for _, existing := range ret {
|
||||
if existing.Group == observedVersion.Group {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ret = append(ret, observedVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// IsGroupRegistered returns true if types for the group have been registered with the scheme
|
||||
func (s *Scheme) IsGroupRegistered(group string) bool {
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
if observedVersion.Group == group {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsVersionRegistered returns true if types for the version have been registered with the scheme
|
||||
func (s *Scheme) IsVersionRegistered(version schema.GroupVersion) bool {
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
if observedVersion == version {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Scheme) addObservedVersion(version schema.GroupVersion) {
|
||||
if len(version.Version) == 0 || version.Version == APIVersionInternal {
|
||||
return
|
||||
}
|
||||
for _, observedVersion := range s.observedVersions {
|
||||
if observedVersion == version {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
s.observedVersions = append(s.observedVersions, version)
|
||||
}
|
||||
|
||||
-5
@@ -75,11 +75,6 @@ func init() {
|
||||
case jsoniter.NumberValue:
|
||||
var number json.Number
|
||||
iter.ReadVal(&number)
|
||||
u64, err := strconv.ParseUint(string(number), 10, 64)
|
||||
if err == nil {
|
||||
*(*interface{})(ptr) = u64
|
||||
return
|
||||
}
|
||||
i64, err := strconv.ParseInt(string(number), 10, 64)
|
||||
if err == nil {
|
||||
*(*interface{})(ptr) = i64
|
||||
|
||||
Reference in New Issue
Block a user