kruise-rollout-api/cmd/gen-schema
守辰 8f290c557a init project from kruise-api
Signed-off-by: 守辰 <shouchen.zz@alibaba-inc.com>
2024-01-19 17:52:53 +08:00
..
README.md init project from kruise-api 2024-01-19 17:52:53 +08:00
main.go init project from kruise-api 2024-01-19 17:52:53 +08:00

README.md

gen-schema

Description

This dictionary contains a tool that generates a kustomize schema file for native kubernetes resources plus projects under the openkrusie name including kruise and rollouts.

The purpose of the kustomize schema file is to be able to use Policy Merge Patch (SMP) on any array type field within an environment variable or resource definition when using kustomize to deploy CRDs in openkruise.

How to run

To generate the schema, run the following command in the project root directory:

make gen-openapi-schema

the schema will be generated in the schema folder.

How to use

In your kustomization.yaml file add a config block like:

openapi:
  path: https://raw.githubusercontent.com/openkruise/kruise-api/main/schema/openkruise_all_k8s_kustomize_schema.json

you can find examples in test folder.

How to upgrade the schema

When there are some new CRDs or updated CRD fields in openkruise, some new fields of array types may need to support SMP. You can simply upgrade schema in the following steps:

1. Check field and add annotations

Firstly, determine whether the newly added field is of array type. Then, combined with the usage scenario, determine if there is a requirement for merging the field based on a unique key.

Then, add annotations to the specified field in the CRD definition file as follows:

// +patchMergeKey=name
// +patchStrategy=merge
InitContainers []SidecarContainer `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

2. Run command to generate schema

make gen-openapi-schema
  1. Why include native resources definition info the schema file?
  2. Kustomize build not honoring the retainKeys patchStrategy
  3. Reason for Error API rule violation: list_type_missing