This commit is contained in:
Kevin Wiesmüller 2020-01-10 00:58:52 +01:00
parent ddf0d4b803
commit a252628649
2 changed files with 7 additions and 4 deletions

View File

@ -65,12 +65,12 @@ func (f *stripMetaManager) Update(liveObj, newObj runtime.Object, managed Manage
// Apply implements Manager.
func (f *stripMetaManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) {
appliedObj, managed, err := f.fieldManager.Apply(liveObj, appliedObj, managed, manager, force)
newObj, managed, err := f.fieldManager.Apply(liveObj, appliedObj, managed, manager, force)
if err != nil {
return nil, nil, err
}
f.stripFields(managed.Fields(), manager)
return appliedObj, managed, nil
return newObj, managed, nil
}
// stripFields removes a predefined set of paths found in typed from managed

View File

@ -137,15 +137,18 @@ func (f *structuredMergeManager) Update(liveObj, newObj runtime.Object, managed
// Apply implements Manager.
func (f *structuredMergeManager) Apply(liveObj, patchObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) {
// Check that the patch object has the same version as the live object
if patchObj.GetObjectKind().GroupVersionKind().GroupVersion() != f.groupVersion {
if patchVersion := patchObj.GetObjectKind().GroupVersionKind().GroupVersion(); patchVersion != f.groupVersion {
return nil, nil,
errors.NewBadRequest(
fmt.Sprintf("Incorrect version specified in apply patch. "+
"Specified patch version: %s, expected: %s",
patchObj.GetObjectKind().GroupVersionKind().GroupVersion(), f.groupVersion))
patchVersion, f.groupVersion))
}
patchObjMeta, err := meta.Accessor(patchObj)
if err != nil {
return nil, nil, fmt.Errorf("couldn't get accessor: %v", err)
}
if patchObjMeta.GetManagedFields() != nil {
return nil, nil, errors.NewBadRequest(fmt.Sprintf("metadata.managedFields must be nil"))
}