Skip to content

Commit 8a9d8ed

Browse files
authored
use controller tools for schema generation (#931)
1 parent bbe04de commit 8a9d8ed

File tree

11 files changed

+186
-406
lines changed

11 files changed

+186
-406
lines changed

config/300-addressableservice.yaml

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,33 @@ spec:
2929
status: {}
3030
schema:
3131
openAPIV3Schema:
32+
description: |-
33+
AddressableService is a Knative abstraction that encapsulates the interface by which Knative
34+
components express a desire to have a particular image cached.
3235
type: object
3336
properties:
37+
apiVersion:
38+
description: |-
39+
APIVersion defines the versioned schema of this representation of an object.
40+
Servers should convert recognized schemas to the latest internal value, and
41+
may reject unrecognized values.
42+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
43+
type: string
44+
kind:
45+
description: |-
46+
Kind is a string value representing the REST resource this object represents.
47+
Servers may infer this from the endpoint the client submits requests to.
48+
Cannot be updated.
49+
In CamelCase.
50+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
51+
type: string
52+
metadata:
53+
type: object
3454
spec:
3555
description: Spec holds the desired state of the AddressableService (from the client).
3656
type: object
57+
required:
58+
- serviceName
3759
properties:
3860
serviceName:
3961
description: ServiceName holds the name of the Kubernetes Service to expose as an "addressable".
@@ -45,11 +67,11 @@ spec:
4567
address:
4668
description: Address holds the information needed to connect this Addressable up to receive events.
4769
type: object
48-
required:
49-
- url
5070
properties:
5171
CACerts:
52-
description: CACerts is the Certification Authority (CA) certificates in PEM format according to https://www.rfc-editor.org/rfc/rfc7468.
72+
description: |-
73+
CACerts is the Certification Authority (CA) certificates in PEM format
74+
according to https://www.rfc-editor.org/rfc/rfc7468.
5375
type: string
5476
audience:
5577
description: Audience is the OIDC audience for this address.
@@ -60,20 +82,31 @@ spec:
6082
url:
6183
type: string
6284
annotations:
63-
description: Annotations is additional Status fields for the Resource to save some additional State as well as convey more information to the user. This is roughly akin to Annotations on any k8s resource, just the reconciler conveying richer information outwards.
85+
description: |-
86+
Annotations is additional Status fields for the Resource to save some
87+
additional State as well as convey more information to the user. This is
88+
roughly akin to Annotations on any k8s resource, just the reconciler conveying
89+
richer information outwards.
6490
type: object
65-
x-kubernetes-preserve-unknown-fields: true
91+
additionalProperties:
92+
type: string
6693
conditions:
6794
description: Conditions the latest available observations of a resource's current state.
6895
type: array
6996
items:
97+
description: |-
98+
Condition defines a readiness condition for a Knative resource.
99+
See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
70100
type: object
71101
required:
72-
- type
73102
- status
103+
- type
74104
properties:
75105
lastTransitionTime:
76-
description: LastTransitionTime is the last time the condition transitioned from one status to another. We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic differences (all other things held constant).
106+
description: |-
107+
LastTransitionTime is the last time the condition transitioned from one status to another.
108+
We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic
109+
differences (all other things held constant).
77110
type: string
78111
message:
79112
description: A human readable message indicating details about the transition.
@@ -82,7 +115,9 @@ spec:
82115
description: The reason for the condition's last transition.
83116
type: string
84117
severity:
85-
description: Severity with which to treat failures of this type of condition. When this is not specified, it defaults to Error.
118+
description: |-
119+
Severity with which to treat failures of this type of condition.
120+
When this is not specified, it defaults to Error.
86121
type: string
87122
status:
88123
description: Status of the condition, one of True, False, Unknown.
@@ -91,7 +126,9 @@ spec:
91126
description: Type of condition.
92127
type: string
93128
observedGeneration:
94-
description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.
129+
description: |-
130+
ObservedGeneration is the 'Generation' of the Service that
131+
was last processed by the controller.
95132
type: integer
96133
format: int64
97134
additionalPrinterColumns:

config/300-simpledeployment.yaml

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,34 @@ spec:
2929
status: {}
3030
schema:
3131
openAPIV3Schema:
32+
description: |-
33+
SimpleDeployment is a Knative abstraction that encapsulates the interface by which Knative
34+
components express a desire to have a particular image cached.
3235
type: object
3336
properties:
37+
apiVersion:
38+
description: |-
39+
APIVersion defines the versioned schema of this representation of an object.
40+
Servers should convert recognized schemas to the latest internal value, and
41+
may reject unrecognized values.
42+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
43+
type: string
44+
kind:
45+
description: |-
46+
Kind is a string value representing the REST resource this object represents.
47+
Servers may infer this from the endpoint the client submits requests to.
48+
Cannot be updated.
49+
In CamelCase.
50+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
51+
type: string
52+
metadata:
53+
type: object
3454
spec:
3555
description: Spec holds the desired state of the SimpleDeployment (from the client).
3656
type: object
57+
required:
58+
- image
59+
- replicas
3760
properties:
3861
image:
3962
type: string
@@ -43,22 +66,35 @@ spec:
4366
status:
4467
description: Status communicates the observed state of the SimpleDeployment (from the controller).
4568
type: object
69+
required:
70+
- readyReplicas
4671
properties:
4772
annotations:
48-
description: Annotations is additional Status fields for the Resource to save some additional State as well as convey more information to the user. This is roughly akin to Annotations on any k8s resource, just the reconciler conveying richer information outwards.
73+
description: |-
74+
Annotations is additional Status fields for the Resource to save some
75+
additional State as well as convey more information to the user. This is
76+
roughly akin to Annotations on any k8s resource, just the reconciler conveying
77+
richer information outwards.
4978
type: object
50-
x-kubernetes-preserve-unknown-fields: true
79+
additionalProperties:
80+
type: string
5181
conditions:
5282
description: Conditions the latest available observations of a resource's current state.
5383
type: array
5484
items:
85+
description: |-
86+
Condition defines a readiness condition for a Knative resource.
87+
See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
5588
type: object
5689
required:
57-
- type
5890
- status
91+
- type
5992
properties:
6093
lastTransitionTime:
61-
description: LastTransitionTime is the last time the condition transitioned from one status to another. We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic differences (all other things held constant).
94+
description: |-
95+
LastTransitionTime is the last time the condition transitioned from one status to another.
96+
We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic
97+
differences (all other things held constant).
6298
type: string
6399
message:
64100
description: A human readable message indicating details about the transition.
@@ -67,7 +103,9 @@ spec:
67103
description: The reason for the condition's last transition.
68104
type: string
69105
severity:
70-
description: Severity with which to treat failures of this type of condition. When this is not specified, it defaults to Error.
106+
description: |-
107+
Severity with which to treat failures of this type of condition.
108+
When this is not specified, it defaults to Error.
71109
type: string
72110
status:
73111
description: Status of the condition, one of True, False, Unknown.
@@ -76,7 +114,9 @@ spec:
76114
description: Type of condition.
77115
type: string
78116
observedGeneration:
79-
description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.
117+
description: |-
118+
ObservedGeneration is the 'Generation' of the Service that
119+
was last processed by the controller.
80120
type: integer
81121
format: int64
82122
readyReplicas:

hack/update-codegen.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ set -o pipefail
2121
source $(dirname $0)/../vendor/knative.dev/hack/codegen-library.sh
2222
export PATH="$GOBIN:$PATH"
2323

24-
function run_yq() {
25-
go_run github.com/mikefarah/yq/[email protected] "$@"
26-
}
27-
2824
echo "=== Update Codegen for ${MODULE_NAME}"
2925

3026
group "Kubernetes Codegen"
3127

32-
# generate the code with:
33-
# --output-base because this script should also be able to run inside the vendor dir of
34-
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
35-
# instead of the $GOPATH directly. For normal projects this can be dropped.
36-
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
37-
knative.dev/sample-controller/pkg/client knative.dev/sample-controller/pkg/apis \
38-
"samples:v1alpha1" \
39-
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
28+
source "${CODEGEN_PKG}/kube_codegen.sh"
29+
30+
kube::codegen::gen_client \
31+
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
32+
--output-dir "${REPO_ROOT_DIR}/pkg/client" \
33+
--output-pkg "knative.dev/sample-controller/pkg/client" \
34+
--with-watch \
35+
"${REPO_ROOT_DIR}/pkg/apis"
36+
37+
kube::codegen::gen_helpers \
38+
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
39+
"${REPO_ROOT_DIR}/pkg"
4040

4141
group "Knative Codegen"
4242

@@ -48,15 +48,11 @@ ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \
4848

4949
group "Update CRD Schema"
5050

51-
go run $(dirname $0)/../cmd/schema/ dump SimpleDeployment \
52-
| run_yq eval-all --header-preprocess=false --inplace 'select(fileIndex == 0).spec.versions[0].schema.openAPIV3Schema = select(fileIndex == 1) | select(fileIndex == 0)' \
53-
$(dirname $0)/../config/300-simpledeployment.yaml -
54-
55-
go run $(dirname $0)/../cmd/schema/ dump AddressableService \
56-
| run_yq eval-all --header-preprocess=false --inplace 'select(fileIndex == 0).spec.versions[0].schema.openAPIV3Schema = select(fileIndex == 1) | select(fileIndex == 0)' \
57-
$(dirname $0)/../config/300-addressableservice.yaml -
51+
go run sigs.k8s.io/controller-tools/cmd/[email protected] \
52+
schemapatch:manifests=config,generateEmbeddedObjectMeta=true \
53+
output:dir=config/ \
54+
paths=./pkg/apis/...
5855

5956
group "Update deps post-codegen"
60-
6157
# Make sure our dependencies are up-to-date
6258
${REPO_ROOT_DIR}/hack/update-deps.sh

pkg/client/clientset/versioned/fake/clientset_generated.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)