Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 36 additions & 47 deletions hack/update-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,44 @@ GOFLAGS=""
CRD_PATH=$(dirname "${0}")/../config/300-crds
API_PATH=$(dirname "${0}")/../pkg/apis

TEMP_DIR_LOGS=$(mktemp -d)

for FILENAME in `find $CRD_PATH -type f`;
do
echo "Gererating CRD schema for $FILENAME"

# NOTE: APIs for the group tekton.dev are implemented under ./pkg/apis/pipeline,
# while the ResolutionRequest from group resolution.tekton.dev is implemented under ./pkg/apis/resolution

GROUP=$(grep -E '^ group:' $FILENAME)
GROUP=${GROUP#" group: "}
if [ "$GROUP" = "tekton.dev" ]; then
API_SUBDIR='pipeline'
else
API_SUBDIR=${GROUP%".tekton.dev"}
fi

# collect all existing crds into the FILES array using the recommended
# mapfile: https://www.shellcheck.net/wiki/SC2207
mapfile -d '' FILES < <(find "$CRD_PATH" -type f -name '*.yaml' -print0)
for file in "${FILES[@]}"; do
echo "Generating CRD schema for $file"
# NOTE: Workaround for https://github.com/kubernetes-sigs/controller-tools/pull/627
#
# Tekton splits its CRD definitions into multiple sub-packages. E.g. under
# the same `tekton.dev/v1alpha1` we find the following packages:
# pkg/apis/
# ├── pipeline
# │ └── v1alpha1
# ├── resource
# │ └── v1alpha1
# └── run
# └── v1alpha1
# This breaks controller-gen's assumption of 1 group/version -> 1 go package.
# As a workaround, we patch every crd in isolation (tmp dir) with the correct
# API sub dir path.
TEMP_DIR=$(mktemp -d)
cp -p $FILENAME $TEMP_DIR/.
LOG_FILE=$TEMP_DIR_LOGS/log-schema-generation-$(basename $FILENAME)

counter=0 limit=10
while [ "$counter" -lt "$limit" ]; do
# FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
# FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
# FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
# FIXME:(burigolucas): controller-gen return status 1 with message "Error: not all generators ran successfully"
set +e
go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.1 \
schemapatch:manifests=$TEMP_DIR,generateEmbeddedObjectMeta=false \
output:dir=$CRD_PATH \
paths=$API_PATH/$API_SUBDIR/... > $LOG_FILE 2>&1
rc=$?
set -e
if [ $rc -eq 0 ]; then
break
fi
if grep -q 'exit status 1' $LOG_FILE; then
echo "[WARNING] Ignoring errors/warnings from CRD schema generation, check $LOG_FILE for details"
break
fi
counter="$(( $counter + 1 ))"
if [ $counter -eq $limit ]; then
echo "[ERROR] Failed to generate CRD schema"
exit 1
fi
done
cp -p "$file" "$TEMP_DIR"
case "$(basename "$file" | tr '[:upper:]' '[:lower:]')" in
*customrun*)
API_SUBDIR="run" ;;
*resolutionrequest*)
API_SUBDIR="resolution" ;;
*)
API_SUBDIR="pipeline" ;;
esac

rm -rf $TEMP_DIR
# FIXME:(burigolucas): add schema for fields with generic type once supported by controller-tools
# FIXME:(burigolucas): add schema for recursive fields once supported by controller-tools
# FIXME:(burigolucas): add reference for dependent external/internal schemas once supported in CRD specification
go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0 \
schemapatch:manifests="$TEMP_DIR",generateEmbeddedObjectMeta=false \
output:dir="$CRD_PATH" \
paths="$API_PATH/$API_SUBDIR/..."
rm -rf "$TEMP_DIR"
done

GOFLAGS="${OLDGOFLAGS}"
6 changes: 4 additions & 2 deletions pkg/apis/pipeline/pod/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
corev1 "k8s.io/api/core/v1"
)

// +listType=atomic
type Volumes []corev1.Volume

// Template holds pod specific configuration
// +k8s:deepcopy-gen=true
// +k8s:openapi-gen=true
Expand Down Expand Up @@ -65,10 +68,9 @@ type Template struct {
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=atomic
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Volumes []corev1.Volume `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge,retainKeys" protobuf:"bytes,1,rep,name=volumes"`
Volumes Volumes `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge,retainKeys" protobuf:"bytes,1,rep,name=volumes"`

// RuntimeClassName refers to a RuntimeClass object in the node.k8s.io
// group, which should be used to run this pod. If no RuntimeClass resource
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/pod/zz_generated.deepcopy.go

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

1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ type Step struct {
Ref *Ref `json:"ref,omitempty"`
// Params declares parameters passed to this step action.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`
// Results declares StepResults produced by the Step.
//
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/pipeline/v1/matrix_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ type Matrix struct {
// Params takes only `Parameters` of type `"array"`
// Each array element is supplied to the `PipelineTask` by substituting `params` of type `"string"` in the underlying `Task`.
// The names of the `params` in the `Matrix` must match the names of the `params` in the underlying `Task` that they will be substituting.
// +listType=atomic
Params Params `json:"params,omitempty"`

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

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

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

Expand Down
86 changes: 0 additions & 86 deletions pkg/apis/pipeline/v1/openapi_generated.go

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

3 changes: 1 addition & 2 deletions pkg/apis/pipeline/v1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
// Pipeline describes a list of Tasks to execute. It expresses how outputs
// of tasks feed into inputs of subsequent tasks.
// +k8s:openapi-gen=true
// +kubebuilder:storageversion
type Pipeline struct {
metav1.TypeMeta `json:",inline"`
// +optional
Expand Down Expand Up @@ -114,7 +115,6 @@ type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks,omitempty"`
// Params declares a list of input parameters that must be supplied when
// this Pipeline is run.
// +listType=atomic
Params ParamSpecs `json:"params,omitempty"`
// Workspaces declares a set of named workspaces that are expected to be
// provided by a PipelineRun.
Expand Down Expand Up @@ -225,7 +225,6 @@ type PipelineTask struct {

// Parameters declares parameters passed to this task.
// +optional
// +listType=atomic
Params Params `json:"params,omitempty"`

// Matrix declares parameters used to fan out this task.
Expand Down
Loading
Loading