概述
kubernetes的声明式API提供了丰富的扩展机制,可以通过crd及codegen机制生成对应的api对象,而kubernetes对于golang的支持较为完备,本文主要介绍如何通过crd定义生成对应的java类。
方法
- 首先准备好你的crd定义模板,例如:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: newkinds.my.group.com
spec:
group: my.group.com
names:
kind: NewKind
listKind: NewKindList
plural: newkinds
singular: newkind
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: NewKind is the Schema for the NewKind API
properties:
apiVersion:
description: 'desc'
type: string
kind:
description: 'desc'
type: string
metadata:
type: object
spec:
description: NewKind defines the desired state of NewKind