Skip to content

Commit

Permalink
Autogeneration of CRDs. (#1240)
Browse files Browse the repository at this point in the history
* add controller-gen command to the generate target
* change annotations to relax validation somewhat, to match current
  usage patterns, and in some cases fix tests to conform to newly added
  validation
* re-generate files. The changes to CRDs fall in the the following
  categories:
  - descriptions copied from the comments in structs (the vast majority of
    this change)
  - validation tree expanded deeper (i.e. actual allowed properties are
    listed rather than just saying that "this is an object") and the
    `required` properties brought up to date with the structs
  - some fields added explicitly with the same value as they have by
    default when omitted (`singular`, `listKind`, `versions`)
  - added `controller-gen.kubebuilder.io/version` annotation
  - the `controller-tools.k8s.io: "1.0"` label removed from the `Test*`
    types
  - some missing properties added in the `Test*` types (`commands`,
    `kindContainers`, `kindNodeCache`)

Signed-off-by: Marcin Owsiany <marcin@owsiany.pl>
  • Loading branch information
porridge committed Jan 7, 2020
1 parent f5e963b commit 7d84119
Show file tree
Hide file tree
Showing 23 changed files with 1,924 additions and 48 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ deploy-clean:
.PHONY: generate
# Generate code
generate:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)
endif
controller-gen crd paths=./pkg/apis/... output:crd:dir=config/crds output:stdout
ifeq (, $(shell which go-bindata))
go get github.com/go-bindata/go-bindata/go-bindata@v3.1.2
go get github.com/go-bindata/go-bindata/go-bindata@$$(go list -f '{{.Version}}' -m github.com/go-bindata/go-bindata)
endif
go-bindata -pkg crd -o pkg/kudoctl/kudoinit/crd/bindata.go -ignore README.md -nometadata config/crds
./hack/update_codegen.sh
Expand Down
4 changes: 2 additions & 2 deletions config/crds/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CRD manifests

These files are currently the authoritative definition for the CRDs (some of these
are used as source by `kubectl kudo init`).
These files are generated by `controller-gen` from the structs in the `pkg/apis` directory.
And in turn they are the source for the `pkg/kudoctl/kudoinit/crds` package.
117 changes: 117 additions & 0 deletions config/crds/kudo.dev_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,161 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
creationTimestamp: null
name: instances.kudo.dev
spec:
group: kudo.dev
names:
kind: Instance
listKind: InstanceList
plural: instances
singular: instance
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: Instance is the Schema for the instances API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: InstanceSpec defines the desired state of Instance.
properties:
operatorVersion:
description: OperatorVersion specifies a reference to a specific OperatorVersion
object.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of an
entire object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen only
to have some well-defined way of referencing a part of an object.
TODO: this design is not final and this field is subject to change
in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference is
made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
parameters:
additionalProperties:
type: string
type: object
type: object
status:
description: InstanceStatus defines the observed state of Instance
properties:
aggregatedStatus:
description: AggregatedStatus is overview of an instance status derived
from the plan status
properties:
activePlanName:
type: string
status:
description: ExecutionStatus captures the state of the rollout.
type: string
type: object
planStatus:
additionalProperties:
description: "PlanStatus is representing status of a plan \n These
are valid states and transitions \n | Never
executed | | v
| Error |<------>| Pending | ^ |
\ | v | +-------+--------+
\ | +-------+--------+ | |
\ v v | Fatal error | | Complete
\ |"
properties:
lastFinishedRun:
format: date-time
nullable: true
type: string
message:
type: string
name:
type: string
phases:
items:
description: PhaseStatus is representing status of a phase
properties:
message:
type: string
name:
type: string
status:
description: ExecutionStatus captures the state of the rollout.
type: string
steps:
items:
description: StepStatus is representing status of a step
properties:
message:
type: string
name:
type: string
status:
description: ExecutionStatus captures the state of
the rollout.
type: string
type: object
type: array
type: object
type: array
status:
description: ExecutionStatus captures the state of the rollout.
type: string
uid:
description: UID is a type that holds unique ID values, including
UUIDs. Because we don't ONLY use UUIDs, this is an alias to
string. Being a type captures intent and helps make sure that
UIDs and names do not get conflated.
type: string
type: object
description: slice would be enough here but we cannot use slice because
order of sequence in yaml is considered significant while here it's
not
type: object
type: object
type: object
version: v1beta1
versions:
- name: v1beta1
served: true
storage: true
status:
acceptedNames:
kind: ""
Expand Down
20 changes: 20 additions & 0 deletions config/crds/kudo.dev_operators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
creationTimestamp: null
name: operators.kudo.dev
spec:
group: kudo.dev
names:
kind: Operator
listKind: OperatorList
plural: operators
singular: operator
scope: Namespaced
validation:
openAPIV3Schema:
description: Operator is the Schema for the operator API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: OperatorSpec defines the desired state of Operator
properties:
description:
type: string
Expand All @@ -31,20 +42,29 @@ spec:
type: string
maintainers:
items:
description: Maintainer describes an Operator maintainer.
properties:
email:
description: Email is an optional email address to contact the
named maintainer.
type: string
name:
description: Name is a user name or organization name.
type: string
type: object
type: array
url:
type: string
type: object
status:
description: OperatorStatus defines the observed state of Operator
type: object
type: object
version: v1beta1
versions:
- name: v1beta1
served: true
storage: true
status:
acceptedNames:
kind: ""
Expand Down
Loading

0 comments on commit 7d84119

Please sign in to comment.