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

Update json tag, keep compatibility #1317

Closed
ghost opened this issue Apr 12, 2019 · 2 comments
Closed

Update json tag, keep compatibility #1317

ghost opened this issue Apr 12, 2019 · 2 comments
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue.

Comments

@ghost
Copy link

ghost commented Apr 12, 2019

Type of question

What would be the best way to update json tag in CR struct spec, and keep compatibility at the same time?

Now I have an existing CR in a running server:

spec:
  oldKey: true

If I change json tag to a newKey in the struct, and update custom resource, it is replaced with a new one, however, it has the default value, since oldKey wasn't found when CR was retrieved:

spec:
  newKey: false

How can I keep backward compatibility, ie update oldKey with newKey, keeping the same value? It is not possible to have several json tags in a struct. Are there any best practices here?

@hasbro17
Copy link
Contributor

@eivantsov If I understand correctly you are trying to update the API/spec fields of your CRD, but you still want to handle older instances of the CRD with the older API and convert them to the new API.

If that's the case then you're probably asking about the CRD versioning and conversion.
https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/
We're still figuring out the workflow for the CRD upgrade lifecycle and are waiting on some upstream changes to support this #1240
If that's what you meant then we can move the discussion to #1240

If it's something else then we can clarify it here.

@hasbro17 hasbro17 added the triage/duplicate Indicates an issue is a duplicate of other open issue. label Apr 15, 2019
@ghost
Copy link
Author

ghost commented Apr 17, 2019

@hasbro17 yes, it looks like I asked if versioning is the best solution. I tried to add a new API version + migration function, and it worked for me. Thanks for helpful links. CLosing.

@ghost ghost closed this as completed Apr 17, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue.
Projects
None yet
Development

No branches or pull requests

1 participant