mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
kubectl diff: Print error when something goes wrong
This commit is contained in:
@@ -122,8 +122,7 @@ func (d *DiffProgram) getCommand(args ...string) exec.Cmd {
|
|||||||
|
|
||||||
// Run runs the detected diff program. `from` and `to` are the directory to diff.
|
// Run runs the detected diff program. `from` and `to` are the directory to diff.
|
||||||
func (d *DiffProgram) Run(from, to string) error {
|
func (d *DiffProgram) Run(from, to string) error {
|
||||||
d.getCommand(from, to).Run() // Ignore diff return code
|
return d.getCommand(from, to).Run()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printer is used to print an object.
|
// Printer is used to print an object.
|
||||||
@@ -396,8 +395,5 @@ func RunDiff(f cmdutil.Factory, diff *DiffProgram, options *DiffOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error ignore on purpose. diff(1) for example, returns an error if there is any diff.
|
return differ.Run(diff)
|
||||||
_ = differ.Run(diff)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,12 @@ run_kubectl_diff_tests() {
|
|||||||
kube::log::status "Testing kubectl diff"
|
kube::log::status "Testing kubectl diff"
|
||||||
|
|
||||||
# Test that it works when the live object doesn't exist
|
# Test that it works when the live object doesn't exist
|
||||||
output_message=$(kubectl diff -f hack/testdata/pod.yaml)
|
output_message=$(! kubectl diff -f hack/testdata/pod.yaml)
|
||||||
kube::test::if_has_string "${output_message}" 'test-pod'
|
kube::test::if_has_string "${output_message}" 'test-pod'
|
||||||
|
|
||||||
kubectl apply -f hack/testdata/pod.yaml
|
kubectl apply -f hack/testdata/pod.yaml
|
||||||
|
|
||||||
output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml)
|
output_message=$(! kubectl diff -f hack/testdata/pod-changed.yaml)
|
||||||
kube::test::if_has_string "${output_message}" 'k8s.gcr.io/pause:3.0'
|
kube::test::if_has_string "${output_message}" 'k8s.gcr.io/pause:3.0'
|
||||||
|
|
||||||
kubectl delete -f hack/testdata/pod.yaml
|
kubectl delete -f hack/testdata/pod.yaml
|
||||||
|
Reference in New Issue
Block a user