mirror of https://github.com/k3s-io/k3s
Consistently print errors to stderr and add newlines to cordon
parent
95c99eb052
commit
c291d3d7ed
|
@ -728,24 +728,24 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||||
if nodeInfo.Mapping.GroupVersionKind.Kind == "Node" {
|
if nodeInfo.Mapping.GroupVersionKind.Kind == "Node" {
|
||||||
obj, err := scheme.Scheme.ConvertToVersion(nodeInfo.Object, nodeInfo.Mapping.GroupVersionKind.GroupVersion())
|
obj, err := scheme.Scheme.ConvertToVersion(nodeInfo.Object, nodeInfo.Mapping.GroupVersionKind.GroupVersion())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: unable to %s node %q: %v", cordonOrUncordon, nodeInfo.Name, err)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
oldData, err := json.Marshal(obj)
|
oldData, err := json.Marshal(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: unable to %s node %q: %v", cordonOrUncordon, nodeInfo.Name, err)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
node, ok := obj.(*corev1.Node)
|
node, ok := obj.(*corev1.Node)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: unexpected Type%T, expected Node", cordonOrUncordon, nodeInfo.Name, obj)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: unexpected Type%T, expected Node\n", cordonOrUncordon, nodeInfo.Name, obj)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
unsched := node.Spec.Unschedulable
|
unsched := node.Spec.Unschedulable
|
||||||
if unsched == desired {
|
if unsched == desired {
|
||||||
printObj, err := o.ToPrinter(already(desired))
|
printObj, err := o.ToPrinter(already(desired))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: %v", err)
|
fmt.Fprintf(o.ErrOut, "error: %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||||
|
@ -755,23 +755,23 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||||
node.Spec.Unschedulable = desired
|
node.Spec.Unschedulable = desired
|
||||||
newData, err := json.Marshal(obj)
|
newData, err := json.Marshal(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v", cordonOrUncordon, nodeInfo.Name, err)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
|
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: unable to %s node %q: %v", cordonOrUncordon, nodeInfo.Name, err)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, err = helper.Patch(o.Namespace, nodeInfo.Name, types.StrategicMergePatchType, patchBytes, nil)
|
_, err = helper.Patch(o.Namespace, nodeInfo.Name, types.StrategicMergePatchType, patchBytes, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: unable to %s node %q: %v", cordonOrUncordon, nodeInfo.Name, err)
|
fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printObj, err := o.ToPrinter(changed(desired))
|
printObj, err := o.ToPrinter(changed(desired))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(o.ErrOut, "%v", err)
|
fmt.Fprintf(o.ErrOut, "%v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||||
|
@ -779,7 +779,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
||||||
} else {
|
} else {
|
||||||
printObj, err := o.ToPrinter("skipped")
|
printObj, err := o.ToPrinter("skipped")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(o.ErrOut, "%v", err)
|
fmt.Fprintf(o.ErrOut, "%v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
printObj(cmdutil.AsDefaultVersionedOrOriginal(nodeInfo.Object, nodeInfo.Mapping), o.Out)
|
||||||
|
|
|
@ -595,7 +595,7 @@ func TestDrain(t *testing.T) {
|
||||||
pods: []corev1.Pod{ds_pod_with_emptyDir},
|
pods: []corev1.Pod{ds_pod_with_emptyDir},
|
||||||
rcs: []corev1.ReplicationController{rc},
|
rcs: []corev1.ReplicationController{rc},
|
||||||
args: []string{"node", "--ignore-daemonsets"},
|
args: []string{"node", "--ignore-daemonsets"},
|
||||||
expectWarning: "WARNING: Ignoring DaemonSet-managed pods: bar\n",
|
expectWarning: "WARNING: Ignoring DaemonSet-managed pods: bar",
|
||||||
expectFatal: false,
|
expectFatal: false,
|
||||||
expectDelete: false,
|
expectDelete: false,
|
||||||
},
|
},
|
||||||
|
@ -855,8 +855,9 @@ func TestDrain(t *testing.T) {
|
||||||
t.Fatalf("%s: expected warning, but found no stderr output", test.description)
|
t.Fatalf("%s: expected warning, but found no stderr output", test.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
if errBuf.String() != test.expectWarning {
|
// Mac and Bazel on Linux behave differently when returning newlines
|
||||||
t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting: %s\n Got: %s", test.description, test.expectWarning, errBuf.String())
|
if a, e := errBuf.String(), test.expectWarning; !strings.Contains(a, e) {
|
||||||
|
t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting:\n%v\n Got:\n%v", test.description, e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue