Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl edit ThirdPartyResource object fails with "invalid character" #35993

Closed
aaronlevy opened this issue Nov 1, 2016 · 9 comments
Closed
Assignees
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@aaronlevy
Copy link
Contributor

What keywords did you search in Kubernetes issues before filing this one?

kubectl edit invalid character
kubectl edit thirdpartyresource


Is this a BUG REPORT or FEATURE REQUEST?
BUG REPORT

Kubernetes version (use kubectl version):

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.5", GitCommit:"5a0a696437ad35c133c0c8493f7e9d22b0f9b81b", GitTreeState:"clean", BuildDate:"2016-10-29T01:38:40Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.3+coreos.0", GitCommit:"7819c84f25e8c661321ee80d6b9fa5f4ff06676f", GitTreeState:"clean", BuildDate:"2016-10-17T21:19:17Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

What happened:

kubectl edit of a thirdPartyResource fails then re-enters the editor and adds the following comment:

# The edited file had a syntax error: unable to decode "edited-file": invalid character '#' looking for beginning of value

What you expected to happen:

kubectl edit to successfully edit the ThirdPartResource object.

How to reproduce it (as minimally and precisely as possible):

tpr.yaml

metadata:
  name: foo-obj.a.example.com
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
description: "foo"
versions:
- name: v1

obj.yaml

metadata:
  name: foo
apiVersion: a.example.com/v1
kind: FooObj
someData: foo
$ kubectl create -f tpr.yaml
$ kubectl create -f obj.yaml
$ kubectl edit fooObj/foo
@paultiplady
Copy link
Contributor

I am also seeing this issue on GKE, with the following k8s versions:

Client Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.1", GitCommit:"33cf7b9acbb2cb7c9c72a10d6636321fb180b159", GitTreeState:"clean", BuildDate:"2016-10-10T18:19:49Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.5", GitCommit:"5a0a696437ad35c133c0c8493f7e9d22b0f9b81b", GitTreeState:"clean", BuildDate:"2016-10-29T01:32:42Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

@pwittrock pwittrock added kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Nov 17, 2016
@pwittrock
Copy link
Member

@adohe Is this something you could take a look at?

@adohe-zz
Copy link

@pwittrock IIRC, I have already fixed this on my local, I need to get it back.

@adohe-zz
Copy link

I looked into this issue again, and just found other problem when test against master branch.

the provided version "a.example.com/v1" has no relevant versions: group a.example.com has not been registered
no matches for a.example.com/, Kind=FooObj

I believe there are some problem of TPR discovery.

@pires
Copy link
Contributor

pires commented Dec 5, 2016

I can confirm this issue as well.

@adohe-zz
Copy link

adohe-zz commented Dec 6, 2016

@pires what error you get? and also what's your kubernetes version?

@pires
Copy link
Contributor

pires commented Dec 6, 2016

Environment: kubectl and Kubernetes v1.4.6

I create a TPR that exposes an object XyzCluster and am able to create/delete it. But when I try to edit through kubectl edit xyzcluster <name>, change some data and save it, the editor pops up again with the same error message @aaronlevy mentioned:

# The edited file had a syntax error: unable to decode "edited-file": invalid character '#' looking for beginning of value

@pires
Copy link
Contributor

pires commented Jan 11, 2017

@adohe any updates on this?

@bgrant0607 bgrant0607 added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed team/ux (deprecated - do not use) labels Feb 7, 2017
@liggitt liggitt added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Feb 8, 2017
@liggitt
Copy link
Member

liggitt commented Feb 13, 2017

fixed in #41304

k8s-github-robot pushed a commit that referenced this issue Feb 15, 2017
Automatic merge from submit-queue

Make kubectl edit work with unstructured objects

Fixes #35993


1. First (before any other changes), added several test cases for complex edit scenarios:
   - [x] ensure the edit loop bails out if given the same result that already caused errors
   - [x] ensure an edited file with a syntax error is reopened preserving the input
   - [x] ensure objects with existing "caused-by" annotations get updated with the current command

2. Refactored the edit code to prep for switching to unstructured:
   - [x] made editFn operate on a slice of resource.Info objects passed as an arg, regardless of edit mode
   - [x] simplified short-circuiting logic when re-editing a file containing an error
   - [x] refactored how we build the various visitors (namespace enforcement, annotation application, patching, creating) so we could easily switch to just using a single visitor over a set of resource infos read from the updated input for all of them

3. Switched to using a resource builder to parse the stream of the user's edited output
   - [x] improve the error message you get on syntax errors
   - [x] preserve the user's input more faithfully (see how the captured testcase requests to the server changed to reflect exactly what the user edited)
   - [x] stopped doing client-side conversion (means deprecating `--output-version`)

4. Switched edit to work with generic objects
   - [x] use unstructured objects
   - [x] fall back to generic json merge patch for unrecognized group/version/kinds

5. Added new test cases
   - [x] schemaless objects falls back to generic json merge (covers TPR scenario)
   - [x] edit unknown version of known kind (version "v0" of storageclass) falls back to generic json merge

```release-note
`kubectl edit` now edits objects exactly as they were retrieved from the API. This allows using `kubectl edit` with third-party resources and extension API servers. Because client-side conversion is no longer done, the `--output-version` option is deprecated for `kubectl edit`. To edit using a particular API version, fully-qualify the resource, version, and group used to fetch the object (for example, `job.v1.batch/myjob`)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Development

No branches or pull requests

8 participants