mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
managedfields: Allow duplicates for built-in updates associative lists
This commit is contained in:
parent
dec443b305
commit
9d1847c196
@ -25,6 +25,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
|
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
|
||||||
"sigs.k8s.io/structured-merge-diff/v4/merge"
|
"sigs.k8s.io/structured-merge-diff/v4/merge"
|
||||||
|
"sigs.k8s.io/structured-merge-diff/v4/typed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type structuredMergeManager struct {
|
type structuredMergeManager struct {
|
||||||
@ -95,11 +96,11 @@ func (f *structuredMergeManager) Update(liveObj, newObj runtime.Object, managed
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err)
|
return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err)
|
||||||
}
|
}
|
||||||
newObjTyped, err := f.typeConverter.ObjectToTyped(newObjVersioned)
|
newObjTyped, err := f.typeConverter.ObjectToTyped(newObjVersioned, typed.AllowDuplicates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to convert new object (%v) to smd typed: %v", objectGVKNN(newObjVersioned), err)
|
return nil, nil, fmt.Errorf("failed to convert new object (%v) to smd typed: %v", objectGVKNN(newObjVersioned), err)
|
||||||
}
|
}
|
||||||
liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned)
|
liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned, typed.AllowDuplicates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to convert live object (%v) to smd typed: %v", objectGVKNN(liveObjVersioned), err)
|
return nil, nil, fmt.Errorf("failed to convert live object (%v) to smd typed: %v", objectGVKNN(liveObjVersioned), err)
|
||||||
}
|
}
|
||||||
@ -139,11 +140,13 @@ func (f *structuredMergeManager) Apply(liveObj, patchObj runtime.Object, managed
|
|||||||
return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err)
|
return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't allow duplicates in the applied object.
|
||||||
patchObjTyped, err := f.typeConverter.ObjectToTyped(patchObj)
|
patchObjTyped, err := f.typeConverter.ObjectToTyped(patchObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to create typed patch object (%v): %v", objectGVKNN(patchObj), err)
|
return nil, nil, fmt.Errorf("failed to create typed patch object (%v): %v", objectGVKNN(patchObj), err)
|
||||||
}
|
}
|
||||||
liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned)
|
|
||||||
|
liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned, typed.AllowDuplicates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to create typed live object (%v): %v", objectGVKNN(liveObjVersioned), err)
|
return nil, nil, fmt.Errorf("failed to create typed live object (%v): %v", objectGVKNN(liveObjVersioned), err)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
// TypeConverter allows you to convert from runtime.Object to
|
// TypeConverter allows you to convert from runtime.Object to
|
||||||
// typed.TypedValue and the other way around.
|
// typed.TypedValue and the other way around.
|
||||||
type TypeConverter interface {
|
type TypeConverter interface {
|
||||||
ObjectToTyped(runtime.Object) (*typed.TypedValue, error)
|
ObjectToTyped(runtime.Object, ...typed.ValidationOptions) (*typed.TypedValue, error)
|
||||||
TypedToObject(*typed.TypedValue) (runtime.Object, error)
|
TypedToObject(*typed.TypedValue) (runtime.Object, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ func NewTypeConverter(openapiSpec map[string]*spec.Schema, preserveUnknownFields
|
|||||||
return &typeConverter{parser: tr}, nil
|
return &typeConverter{parser: tr}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *typeConverter) ObjectToTyped(obj runtime.Object) (*typed.TypedValue, error) {
|
func (c *typeConverter) ObjectToTyped(obj runtime.Object, opts ...typed.ValidationOptions) (*typed.TypedValue, error) {
|
||||||
gvk := obj.GetObjectKind().GroupVersionKind()
|
gvk := obj.GetObjectKind().GroupVersionKind()
|
||||||
t := c.parser[gvk]
|
t := c.parser[gvk]
|
||||||
if t == nil {
|
if t == nil {
|
||||||
@ -62,9 +62,9 @@ func (c *typeConverter) ObjectToTyped(obj runtime.Object) (*typed.TypedValue, er
|
|||||||
}
|
}
|
||||||
switch o := obj.(type) {
|
switch o := obj.(type) {
|
||||||
case *unstructured.Unstructured:
|
case *unstructured.Unstructured:
|
||||||
return t.FromUnstructured(o.UnstructuredContent())
|
return t.FromUnstructured(o.UnstructuredContent(), opts...)
|
||||||
default:
|
default:
|
||||||
return t.FromStructured(obj)
|
return t.FromStructured(obj, opts...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +84,12 @@ func NewDeducedTypeConverter() TypeConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ObjectToTyped converts an object into a TypedValue with a "deduced type".
|
// ObjectToTyped converts an object into a TypedValue with a "deduced type".
|
||||||
func (deducedTypeConverter) ObjectToTyped(obj runtime.Object) (*typed.TypedValue, error) {
|
func (deducedTypeConverter) ObjectToTyped(obj runtime.Object, opts ...typed.ValidationOptions) (*typed.TypedValue, error) {
|
||||||
switch o := obj.(type) {
|
switch o := obj.(type) {
|
||||||
case *unstructured.Unstructured:
|
case *unstructured.Unstructured:
|
||||||
return typed.DeducedParseableType.FromUnstructured(o.UnstructuredContent())
|
return typed.DeducedParseableType.FromUnstructured(o.UnstructuredContent(), opts...)
|
||||||
default:
|
default:
|
||||||
return typed.DeducedParseableType.FromStructured(obj)
|
return typed.DeducedParseableType.FromStructured(obj, opts...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user