在尝试在CRD中添加字段时,我应该创建一个新版本吗?

huangapple go评论73阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年8月10日 10:07:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76872236.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定