我有一个自定义资源定义,其中包含具有默认值的嵌套字段(为简洁起见,省略了一些样板):
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
spec:
scope: Namespaced
group: thismatters.stackoverflow
names:
kind: BadDefault
versions:
- name: v1alpha
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
regularThing:
type: integer
default: 6
shouldDefault:
type: object
properties:
nestedThing:
type: integer
default: 12
shouldDefault
每当我在不指定对象的情况下创建此类资源时:
apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
name: blank-demo
spec:
regularThing: 7
资源为d.shouldDefault.nestedThing
时不显示默认值:describe
apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
name: blank-demo
spec:
regularThing: 7
如果我使用此清单更新资源:
apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
name: blank-demo
spec:
regularThing: 7
shouldDefault: {}
describe
然后在d时填充嵌套字段默认值:
apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
name: blank-demo
spec:
regularThing: 7
shouldDefault:
nestedThing: 12
我可以在 CRD 中做些什么来消除对shouldDefault: {}
资源清单中的行的需求,并在嵌套字段中填充默认值吗?
我的集群在 Kubernetes 版本 1.19 上。