From a3417fe62cb671fdf3e9fd7e217dd35a5d555ed2 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Wed, 22 Aug 2018 05:51:26 -0700 Subject: [PATCH] diff: Fix crash when remote object doesn't exist Since we're saving nil in an interface rather than the implementation, we can't compare to nil to check if the remote object exists or not. Change the struct to save in the implementation. --- pkg/kubectl/cmd/diff.go | 2 +- test/cmd/diff.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/diff.go b/pkg/kubectl/cmd/diff.go index 9fd37676fae..33a5dc64f81 100644 --- a/pkg/kubectl/cmd/diff.go +++ b/pkg/kubectl/cmd/diff.go @@ -265,7 +265,7 @@ type Object interface { // InfoObject is an implementation of the Object interface. It gets all // the information from the Info object. type InfoObject struct { - Remote runtime.Unstructured + Remote *unstructured.Unstructured Info *resource.Info Encoder runtime.Encoder Parser *parse.Factory diff --git a/test/cmd/diff.sh b/test/cmd/diff.sh index 27032db6ee9..4edd8d8121d 100755 --- a/test/cmd/diff.sh +++ b/test/cmd/diff.sh @@ -26,6 +26,10 @@ run_kubectl_diff_tests() { create_and_use_new_namespace kube::log::status "Testing kubectl alpha diff" + # Test that it works when the live object doesn't exist + output_message=$(kubectl alpha diff LOCAL LIVE -f hack/testdata/pod.yaml) + kube::test::if_has_string "${output_message}" 'test-pod' + kubectl apply -f hack/testdata/pod.yaml # Ensure that selfLink has been added, and shown in the diff