mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Pod labeling should return correct messages
This commit is contained in:
parent
94d3d8f027
commit
f55809b5b5
@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -227,6 +228,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
}
|
||||
|
||||
var outputObj runtime.Object
|
||||
dataChangeMsg := "not labeled"
|
||||
if cmdutil.GetFlagBool(cmd, "dry-run") {
|
||||
err = labelFunc(info.Object, overwrite, resourceVersion, lbls, remove)
|
||||
if err != nil {
|
||||
@ -239,6 +241,13 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
meta, err := api.ObjectMetaFor(obj)
|
||||
for _, label := range remove {
|
||||
if _, ok := meta.Labels[label]; !ok {
|
||||
fmt.Fprintf(out, "label %q not found.\n", label)
|
||||
}
|
||||
}
|
||||
|
||||
if err := labelFunc(obj, overwrite, resourceVersion, lbls, remove); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -246,6 +255,9 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !reflect.DeepEqual(oldData, newData) {
|
||||
dataChangeMsg = "labeled"
|
||||
}
|
||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -267,7 +279,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
||||
if outputFormat != "" {
|
||||
return f.PrintObject(cmd, outputObj, out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, "labeled")
|
||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, dataChangeMsg)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user