kubeplus icon indicating copy to clipboard operation
kubeplus copied to clipboard

CRD registration of properties with default value set to null

Open devdattakulkarni opened this issue 1 year ago • 1 comments
trafficstars

In odoo helm chart, there is the following section in values.yaml

updateStrategy: type: RollingUpdate rollingUpdate: null

When Odoo CRD is created with this helm chart, the rollingUpdate field is being ignored. The OpenAPI Spec that is registered for this CRD does not seem to contain the rollingUpdate field.

devdattakulkarni avatar Aug 29 '24 11:08 devdattakulkarni

The code update for this will be in the registercrd method, specifically in the flatten method: https://github.com/cloud-ark/kubeplus/blob/master/deploy/kubeconfiggenerator.py#L666

In the flatten method implementation (https://github.com/cloud-ark/kubeplus/blob/master/deploy/kubeconfiggenerator.py#L478),

Kubernetes supports OpenAPI Spec v3.0 (https://kubernetes.io/docs/concepts/overview/kubernetes-api/). In OpenAPI Spec 3.0, nullable values are defined using nullable property, like below:

type: string nullable: true See https://stackoverflow.com/questions/48111459/how-to-define-a-property-that-can-be-string-or-null-in-openapi-swagger

Given this, we need to add following code in flatten method:

if value == "null": prop_dict = {'type': 'string', 'nullable': true} types_dict[key] = prop_dict

devdattakulkarni avatar Dec 10 '24 16:12 devdattakulkarni