From bc4143092ce177f3af4a4a9b421129c183bf1bd6 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Thu, 24 Mar 2016 11:25:38 -0400 Subject: [PATCH] Make kubectl edit not convert GV on edits Previously, kubectl edit was using a decoder to load in edits that converted to the internal version. It would then re-encode this decoded value to produce a patch. However, if you were editing in the object in a GroupVersion that was not the internal version, this would cause the kubectl edit command to attempt to produce a patch which changed the GroupVersion, which would fail. Now, we use a plain deserializer instead, so no conversion or defaulting occurs when loading in the edited file. Fixes #23378 --- pkg/kubectl/cmd/edit.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/edit.go b/pkg/kubectl/cmd/edit.go index bbc7f23e1b3..7ed9f0143c9 100644 --- a/pkg/kubectl/cmd/edit.go +++ b/pkg/kubectl/cmd/edit.go @@ -125,7 +125,13 @@ func RunEdit(f *cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args ObjectTyper: typer, RESTMapper: mapper, ClientMapper: resource.ClientMapperFunc(f.ClientForMapping), - Decoder: f.Decoder(true), + + // NB: we use `f.Decoder(false)` to get a plain deserializer for + // the resourceMapper, since it's used to read in edits and + // we don't want to convert into the internal version when + // reading in edits (this would cause us to potentially try to + // compare two different GroupVersions). + Decoder: f.Decoder(false), } r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).