Skip to content

Commit 2804278

Browse files
tricktrontekton-robot
authored andcommitted
fix: update crd schemas command errors
Changes the following Kubernetes controller annotations so that the `controller-gen:schemapatch` command works without any errors: - Removes the duplicated list type annotation from struct fields where the annotation is already set on the type. - Create a type alias and set the list type annotation there (mainly with `[]corev1.Volume`). - Set the `storageversion` annotation to the most stable version. As a result, we can then simplify the update-schema.sh script.
1 parent f747ba8 commit 2804278

30 files changed

+218
-349
lines changed

hack/update-schemas.sh

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,44 @@ GOFLAGS=""
2424
CRD_PATH=$(dirname "${0}")/../config/300-crds
2525
API_PATH=$(dirname "${0}")/../pkg/apis
2626

27-
TEMP_DIR_LOGS=$(mktemp -d)
28-
29-
for FILENAME in `find $CRD_PATH -type f`;
30-
do
31-
echo "Gererating CRD schema for $FILENAME"
32-
33-
# NOTE: APIs for the group tekton.dev are implemented under ./pkg/apis/pipeline,
34-
# while the ResolutionRequest from group resolution.tekton.dev is implemented under ./pkg/apis/resolution
35-
36-
GROUP=$(grep -E '^ group:' $FILENAME)
37-
GROUP=${GROUP#" group: "}
38-
if [ "$GROUP" = "tekton.dev" ]; then
39-
API_SUBDIR='pipeline'
40-
else
41-
API_SUBDIR=${GROUP%".tekton.dev"}
42-
fi
43-
27+
# collect all existing crds into the FILES array using the recommended
28+
# mapfile: https://www.shellcheck.net/wiki/SC2207
29+
mapfile -d '' FILES < <(find "$CRD_PATH" -type f -name '*.yaml' -print0)
30+
for file in "${FILES[@]}"; do
31+
echo "Generating CRD schema for $file"
32+
# NOTE: Workaround for https://github.com/kubernetes-sigs/controller-tools/pull/627
33+
#
34+
# Tekton splits its CRD definitions into multiple sub-packages. E.g. under
35+
# the same `tekton.dev/v1alpha1` we find the following packages:
36+
# pkg/apis/
37+
# ├── pipeline
38+
# │ └── v1alpha1
39+
# ├── resource
40+
# │ └── v1alpha1
41+
# └── run
42+
# └── v1alpha1
43+
# This breaks controller-gen's assumption of 1 group/version -> 1 go package.
44+
# As a workaround, we patch every crd in isolation (tmp dir) with the correct
45+
# API sub dir path.
4446
TEMP_DIR=$(mktemp -d)
45-
cp -p $FILENAME $TEMP_DIR/.
46-
LOG_FILE=$TEMP_DIR_LOGS/log-schema-generation-$(basename $FILENAME)
47-
48-
counter=0 limit=10
49-
while [ "$counter" -lt "$limit" ]; do
50-
# FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
51-
# FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
52-
# FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
53-
# FIXME:(burigolucas): controller-gen return status 1 with message "Error: not all generators ran successfully"
54-
set +e
55-
go run sigs.k8s.io/controller-tools/cmd/[email protected] \
56-
schemapatch:manifests=$TEMP_DIR,generateEmbeddedObjectMeta=false \
57-
output:dir=$CRD_PATH \
58-
paths=$API_PATH/$API_SUBDIR/... > $LOG_FILE 2>&1
59-
rc=$?
60-
set -e
61-
if [ $rc -eq 0 ]; then
62-
break
63-
fi
64-
if grep -q 'exit status 1' $LOG_FILE; then
65-
echo "[WARNING] Ignoring errors/warnings from CRD schema generation, check $LOG_FILE for details"
66-
break
67-
fi
68-
counter="$(( $counter + 1 ))"
69-
if [ $counter -eq $limit ]; then
70-
echo "[ERROR] Failed to generate CRD schema"
71-
exit 1
72-
fi
73-
done
47+
cp -p "$file" "$TEMP_DIR"
48+
case "$(basename "$file" | tr '[:upper:]' '[:lower:]')" in
49+
*customrun*)
50+
API_SUBDIR="run" ;;
51+
*resolutionrequest*)
52+
API_SUBDIR="resolution" ;;
53+
*)
54+
API_SUBDIR="pipeline" ;;
55+
esac
7456

75-
rm -rf $TEMP_DIR
57+
# FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
58+
# FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
59+
# FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
60+
go run sigs.k8s.io/controller-tools/cmd/[email protected] \
61+
schemapatch:manifests="$TEMP_DIR",generateEmbeddedObjectMeta=false \
62+
output:dir="$CRD_PATH" \
63+
paths="$API_PATH/$API_SUBDIR/..."
64+
rm -rf "$TEMP_DIR"
7665
done
7766

7867
GOFLAGS="${OLDGOFLAGS}"

pkg/apis/pipeline/pod/template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
)
2424

25+
// +listType=atomic
26+
type Volumes []corev1.Volume
27+
2528
// Template holds pod specific configuration
2629
// +k8s:deepcopy-gen=true
2730
// +k8s:openapi-gen=true
@@ -65,10 +68,9 @@ type Template struct {
6568
// +optional
6669
// +patchMergeKey=name
6770
// +patchStrategy=merge,retainKeys
68-
// +listType=atomic
6971
// +kubebuilder:pruning:PreserveUnknownFields
7072
// +kubebuilder:validation:Schemaless
71-
Volumes []corev1.Volume `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge,retainKeys" protobuf:"bytes,1,rep,name=volumes"`
73+
Volumes Volumes `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge,retainKeys" protobuf:"bytes,1,rep,name=volumes"`
7274

7375
// RuntimeClassName refers to a RuntimeClass object in the node.k8s.io
7476
// group, which should be used to run this pod. If no RuntimeClass resource

pkg/apis/pipeline/pod/zz_generated.deepcopy.go

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

pkg/apis/pipeline/v1/container_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ type Step struct {
140140
Ref *Ref `json:"ref,omitempty"`
141141
// Params declares parameters passed to this step action.
142142
// +optional
143-
// +listType=atomic
144143
Params Params `json:"params,omitempty"`
145144
// Results declares StepResults produced by the Step.
146145
//

pkg/apis/pipeline/v1/matrix_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ type Matrix struct {
3131
// Params takes only `Parameters` of type `"array"`
3232
// Each array element is supplied to the `PipelineTask` by substituting `params` of type `"string"` in the underlying `Task`.
3333
// The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.
34-
// +listType=atomic
3534
Params Params `json:"params,omitempty"`
3635

3736
// Include is a list of IncludeParams which allows passing in specific combinations of Parameters into the Matrix.
3837
// +optional
39-
// +listType=atomic
4038
Include IncludeParamsList `json:"include,omitempty"`
4139
}
4240

@@ -51,7 +49,6 @@ type IncludeParams struct {
5149

5250
// Params takes only `Parameters` of type `"string"`
5351
// The names of the `params` must match the names of the `params` in the underlying `Task`
54-
// +listType=atomic
5552
Params Params `json:"params,omitempty"`
5653
}
5754

pkg/apis/pipeline/v1/openapi_generated.go

Lines changed: 0 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/pipeline/v1/pipeline_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const (
5151
// Pipeline describes a list of Tasks to execute. It expresses how outputs
5252
// of tasks feed into inputs of subsequent tasks.
5353
// +k8s:openapi-gen=true
54+
// +kubebuilder:storageversion
5455
type Pipeline struct {
5556
metav1.TypeMeta `json:",inline"`
5657
// +optional
@@ -114,7 +115,6 @@ type PipelineSpec struct {
114115
Tasks []PipelineTask `json:"tasks,omitempty"`
115116
// Params declares a list of input parameters that must be supplied when
116117
// this Pipeline is run.
117-
// +listType=atomic
118118
Params ParamSpecs `json:"params,omitempty"`
119119
// Workspaces declares a set of named workspaces that are expected to be
120120
// provided by a PipelineRun.
@@ -225,7 +225,6 @@ type PipelineTask struct {
225225

226226
// Parameters declares parameters passed to this task.
227227
// +optional
228-
// +listType=atomic
229228
Params Params `json:"params,omitempty"`
230229

231230
// Matrix declares parameters used to fan out this task.

0 commit comments

Comments
 (0)