Revert "try old patch after new patch fails"

This reverts commit f32696e734.
This commit is contained in:
ymqytw
2016-11-22 21:02:30 -08:00
parent 9b16b435fc
commit d248843b65
18 changed files with 123 additions and 58 deletions

View File

@@ -521,7 +521,7 @@ func RecordChangeCause(obj runtime.Object, changeCause string) error {
// ChangeResourcePatch creates a strategic merge patch between the origin input resource info
// and the annotated with change-cause input resource info.
func ChangeResourcePatch(info *resource.Info, changeCause string) ([]byte, error) {
func ChangeResourcePatch(info *resource.Info, changeCause string, smPatchVersion strategicpatch.StrategicMergePatchVersion) ([]byte, error) {
oldData, err := json.Marshal(info.Object)
if err != nil {
return nil, err
@@ -533,8 +533,7 @@ func ChangeResourcePatch(info *resource.Info, changeCause string) ([]byte, error
if err != nil {
return nil, err
}
// Using SMPatchVersion_1_5, since RecordChangeCause() just update the annotation which is a map[string]string
return strategicpatch.CreateTwoWayMergePatch(oldData, newData, info.Object, strategicpatch.SMPatchVersion_1_5)
return strategicpatch.CreateTwoWayMergePatch(oldData, newData, info.Object, smPatchVersion)
}
// containsChangeCause checks if input resource info contains change-cause annotation.
@@ -726,3 +725,13 @@ func RequireNoArguments(c *cobra.Command, args []string) {
CheckErr(UsageError(c, fmt.Sprintf(`unknown command %q`, strings.Join(args, " "))))
}
}
// GetServerSupportedSMPatchVersionFromFactory is a wrapper of GetServerSupportedSMPatchVersion(),
// It takes a Factory, returns the max version the server supports.
func GetServerSupportedSMPatchVersionFromFactory(f Factory) (strategicpatch.StrategicMergePatchVersion, error) {
clientSet, err := f.ClientSet()
if err != nil {
return strategicpatch.Unknown, err
}
return strategicpatch.GetServerSupportedSMPatchVersion(clientSet.Discovery())
}