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?
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.