Skip to content

Commit

Permalink
use controller tools for schema generation (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso authored Jan 17, 2025
1 parent bbe04de commit 8a9d8ed
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 406 deletions.
55 changes: 46 additions & 9 deletions config/300-addressableservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,33 @@ spec:
status: {}
schema:
openAPIV3Schema:
description: |-
AddressableService is a Knative abstraction that encapsulates the interface by which Knative
components express a desire to have a particular image cached.
type: object
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: Spec holds the desired state of the AddressableService (from the client).
type: object
required:
- serviceName
properties:
serviceName:
description: ServiceName holds the name of the Kubernetes Service to expose as an "addressable".
Expand All @@ -45,11 +67,11 @@ spec:
address:
description: Address holds the information needed to connect this Addressable up to receive events.
type: object
required:
- url
properties:
CACerts:
description: CACerts is the Certification Authority (CA) certificates in PEM format according to https://www.rfc-editor.org/rfc/rfc7468.
description: |-
CACerts is the Certification Authority (CA) certificates in PEM format
according to https://www.rfc-editor.org/rfc/rfc7468.
type: string
audience:
description: Audience is the OIDC audience for this address.
Expand All @@ -60,20 +82,31 @@ spec:
url:
type: string
annotations:
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.
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.
type: object
x-kubernetes-preserve-unknown-fields: true
additionalProperties:
type: string
conditions:
description: Conditions the latest available observations of a resource's current state.
type: array
items:
description: |-
Condition defines a readiness condition for a Knative resource.
See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
type: object
required:
- type
- status
- type
properties:
lastTransitionTime:
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).
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).
type: string
message:
description: A human readable message indicating details about the transition.
Expand All @@ -82,7 +115,9 @@ spec:
description: The reason for the condition's last transition.
type: string
severity:
description: Severity with which to treat failures of this type of condition. When this is not specified, it defaults to Error.
description: |-
Severity with which to treat failures of this type of condition.
When this is not specified, it defaults to Error.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
Expand All @@ -91,7 +126,9 @@ spec:
description: Type of condition.
type: string
observedGeneration:
description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.
description: |-
ObservedGeneration is the 'Generation' of the Service that
was last processed by the controller.
type: integer
format: int64
additionalPrinterColumns:
Expand Down
52 changes: 46 additions & 6 deletions config/300-simpledeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,34 @@ spec:
status: {}
schema:
openAPIV3Schema:
description: |-
SimpleDeployment is a Knative abstraction that encapsulates the interface by which Knative
components express a desire to have a particular image cached.
type: object
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: Spec holds the desired state of the SimpleDeployment (from the client).
type: object
required:
- image
- replicas
properties:
image:
type: string
Expand All @@ -43,22 +66,35 @@ spec:
status:
description: Status communicates the observed state of the SimpleDeployment (from the controller).
type: object
required:
- readyReplicas
properties:
annotations:
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.
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.
type: object
x-kubernetes-preserve-unknown-fields: true
additionalProperties:
type: string
conditions:
description: Conditions the latest available observations of a resource's current state.
type: array
items:
description: |-
Condition defines a readiness condition for a Knative resource.
See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
type: object
required:
- type
- status
- type
properties:
lastTransitionTime:
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).
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).
type: string
message:
description: A human readable message indicating details about the transition.
Expand All @@ -67,7 +103,9 @@ spec:
description: The reason for the condition's last transition.
type: string
severity:
description: Severity with which to treat failures of this type of condition. When this is not specified, it defaults to Error.
description: |-
Severity with which to treat failures of this type of condition.
When this is not specified, it defaults to Error.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
Expand All @@ -76,7 +114,9 @@ spec:
description: Type of condition.
type: string
observedGeneration:
description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.
description: |-
ObservedGeneration is the 'Generation' of the Service that
was last processed by the controller.
type: integer
format: int64
readyReplicas:
Expand Down
36 changes: 16 additions & 20 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ set -o pipefail
source $(dirname $0)/../vendor/knative.dev/hack/codegen-library.sh
export PATH="$GOBIN:$PATH"

function run_yq() {
go_run github.com/mikefarah/yq/v4@v4.23.1 "$@"
}

echo "=== Update Codegen for ${MODULE_NAME}"

group "Kubernetes Codegen"

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
knative.dev/sample-controller/pkg/client knative.dev/sample-controller/pkg/apis \
"samples:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
source "${CODEGEN_PKG}/kube_codegen.sh"

kube::codegen::gen_client \
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
--output-dir "${REPO_ROOT_DIR}/pkg/client" \
--output-pkg "knative.dev/sample-controller/pkg/client" \
--with-watch \
"${REPO_ROOT_DIR}/pkg/apis"

kube::codegen::gen_helpers \
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
"${REPO_ROOT_DIR}/pkg"

group "Knative Codegen"

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

group "Update CRD Schema"

go run $(dirname $0)/../cmd/schema/ dump SimpleDeployment \
| run_yq eval-all --header-preprocess=false --inplace 'select(fileIndex == 0).spec.versions[0].schema.openAPIV3Schema = select(fileIndex == 1) | select(fileIndex == 0)' \
$(dirname $0)/../config/300-simpledeployment.yaml -

go run $(dirname $0)/../cmd/schema/ dump AddressableService \
| run_yq eval-all --header-preprocess=false --inplace 'select(fileIndex == 0).spec.versions[0].schema.openAPIV3Schema = select(fileIndex == 1) | select(fileIndex == 0)' \
$(dirname $0)/../config/300-addressableservice.yaml -
go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.1 \
schemapatch:manifests=config,generateEmbeddedObjectMeta=true \
output:dir=config/ \
paths=./pkg/apis/...

group "Update deps post-codegen"

# Make sure our dependencies are up-to-date
${REPO_ROOT_DIR}/hack/update-deps.sh
6 changes: 5 additions & 1 deletion pkg/client/clientset/versioned/fake/clientset_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8a9d8ed

Please sign in to comment.