mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
fix label msg
This commit is contained in:
parent
b5be8e4246
commit
83fe357f3e
@ -307,7 +307,7 @@ func (o *LabelOptions) RunLabel() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dataChangeMsg = updateDataChangeMsg(oldData, newObj)
|
dataChangeMsg = updateDataChangeMsg(oldData, newObj, o.overwrite)
|
||||||
outputObj = info.Object
|
outputObj = info.Object
|
||||||
} else {
|
} else {
|
||||||
name, namespace := info.Name, info.Namespace
|
name, namespace := info.Name, info.Namespace
|
||||||
@ -334,7 +334,7 @@ func (o *LabelOptions) RunLabel() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dataChangeMsg = updateDataChangeMsg(oldData, newObj)
|
dataChangeMsg = updateDataChangeMsg(oldData, newObj, o.overwrite)
|
||||||
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newObj)
|
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newObj)
|
||||||
createdPatch := err == nil
|
createdPatch := err == nil
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -395,11 +395,11 @@ func (o *LabelOptions) RunLabel() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateDataChangeMsg(oldObj []byte, newObj []byte) string {
|
func updateDataChangeMsg(oldObj []byte, newObj []byte, overwrite bool) string {
|
||||||
msg := MsgNotLabeled
|
msg := MsgNotLabeled
|
||||||
if !reflect.DeepEqual(oldObj, newObj) {
|
if !reflect.DeepEqual(oldObj, newObj) {
|
||||||
msg = MsgLabeled
|
msg = MsgLabeled
|
||||||
if len(newObj) < len(oldObj) {
|
if !overwrite && len(newObj) < len(oldObj) {
|
||||||
msg = MsgUnLabeled
|
msg = MsgUnLabeled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -678,6 +678,41 @@ func TestLabelMsg(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectMsg: MsgLabeled,
|
expectMsg: MsgLabeled,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
obj: &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{"status": "unhealthy"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
labels: map[string]string{"status": "healthy"},
|
||||||
|
overwrite: true,
|
||||||
|
expectObj: &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"status": "healthy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectMsg: MsgLabeled,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{"status": "unhealthy"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
labels: map[string]string{"status": "healthy"},
|
||||||
|
overwrite: false,
|
||||||
|
expectObj: &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"status": "unhealthy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectMsg: MsgNotLabeled,
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -700,7 +735,7 @@ func TestLabelMsg(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v %v", err, test)
|
t.Errorf("unexpected error: %v %v", err, test)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChangeMsg := updateDataChangeMsg(oldData, newObj)
|
dataChangeMsg := updateDataChangeMsg(oldData, newObj, test.overwrite)
|
||||||
if dataChangeMsg != test.expectMsg {
|
if dataChangeMsg != test.expectMsg {
|
||||||
t.Errorf("unexpected dataChangeMsg: %v != %v, %v", dataChangeMsg, test.expectMsg, test)
|
t.Errorf("unexpected dataChangeMsg: %v != %v, %v", dataChangeMsg, test.expectMsg, test)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user