mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #38538 from juanvallejo/jvallejo/dont-report-success-if-obj-not-patched
Automatic merge from submit-queue Prevent "patched" output on obj not patched **Release note**: ```release-note release-note-none ``` This patch compares an original object against a patched object returned from the server and only announces that the object was successfully patched if the object returned from the server does not equal the original object. @fabianofranz @kubernetes/cli-review
This commit is contained in:
commit
085f0d74dc
@ -17,11 +17,13 @@ limitations under the License.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -167,8 +169,9 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !options.Local {
|
if !options.Local {
|
||||||
|
dataChangedMsg := "not patched"
|
||||||
helper := resource.NewHelper(client, mapping)
|
helper := resource.NewHelper(client, mapping)
|
||||||
_, err := helper.Patch(namespace, name, patchType, patchBytes)
|
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -184,8 +187,20 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
||||||
|
oldData, err := json.Marshal(info.Object)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newData, err := json.Marshal(patchedObj)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(oldData, newData) {
|
||||||
|
dataChangedMsg = "patched"
|
||||||
|
}
|
||||||
|
|
||||||
if options.OutputFormat == "name" || len(options.OutputFormat) == 0 {
|
if options.OutputFormat == "name" || len(options.OutputFormat) == 0 {
|
||||||
cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, "", name, false, "patched")
|
cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, "", name, false, dataChangedMsg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user