英文:
Should I create a new version when I trying to add a field in CRD?
问题
如果我想在自定义资源定义(CRD)中添加一个字段(而不更改任何现有字段),我应该通过创建一个新版本来实现吗?
如果我应该创建一个新版本,那么直接修改原始版本的缺点是什么?
英文:
If I want to add a field in a CRD(without change any exist field), Should I do it by create a new version?
If I should create a new version, then what's the disadvantages of directly modifying the original version?
答案1
得分: 1
As explained in the blog written by Dinesh Parvathaneni, you can validate the points as mentioned below:
CRDs are similar to K8s built-in types and the expectation for operator developers is to follow the same guidelines when it comes to their versioning.
- Adding a required new field or removing a field is a backward incompatible change to the API. This makes all the old versions immediately unusable. So don’t make backward incompatible CRD API changes.
- If you want to still continue using the old versions they need to be updated with the new field as an optional parameter as K8s doesn’t add a required field, instead adds an optional field with a default value.
Example: when a new field is added, the new version of the operator would still behave as the old version when the new field is not provided in user input. This is more like a feature flag for the new features in the operator.
- CRD can define multiple versions of the custom resource. A version can be marked as served or not served and only one version can be used as a storage version in etcd.
- If there is schema difference across versions, conversion webhooks are needed to convert between versions when necessary.
Hope the above information is useful to you.
英文:
As explained in the blog written by Dinesh Parvathaneni, you can validate the points as mentioned below:
CRDs are similar to K8s built-in types and the expectation for operator developers is to follow the same guidelines when it comes to their versioning.
-
> Adding a required new field or removing a field is a backward incompatible change to the API. This makes all the old versions
immediately unusable. So don’t make backward incompatible CRD API
changes. -
> If you want to still continue using the old versions they need to be updated with the new field as an optional parameter as K8s
doesn’t add a required field, instead adds an optional field with a
default value.> Example: when a new field is added, the new version of the operator would still behave as the old version when the new field is
not provided in user input. This is more like a feature flag for
the new features in the operator. -
> CRD can define multiple versions of the custom resource. A version can be marked as served or not served and only one version can be
used as a storage version in etcd. -
> If there is schema difference across versions, conversion webhooks are needed to convert between versions when necessary.
Hope the above information is useful to you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论