Skip to content

Commit

Permalink
Add empty v1 package
Browse files Browse the repository at this point in the history
This commit adds an empty package for v1 and updates the hack directory to generate
code and OpenAPI spec for v1.
  • Loading branch information
lbernick committed Jul 1, 2022
1 parent 8a3a8e5 commit d4c2ad8
Show file tree
Hide file tree
Showing 19 changed files with 786 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ require (
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
)
2 changes: 1 addition & 1 deletion go.sum

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

28 changes: 19 additions & 9 deletions hack/spec-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,38 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"

tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"

"k8s.io/klog"
"k8s.io/kube-openapi/pkg/common"
spec "k8s.io/kube-openapi/pkg/validation/spec"
)

func main() {
if len(os.Args) <= 1 {
klog.Fatal("Supply a version")
}
version := os.Args[1]
pipelinesVersion := flag.String("version", "v0.17.2", "Tekton Pipelines software version")
apiVersion := flag.String("apiVersion", "v1beta1", "API version")
flag.Parse()
version := *pipelinesVersion
if !strings.HasPrefix(version, "v") {
version = "v" + version
}
oAPIDefs := tekton.GetOpenAPIDefinitions(func(name string) spec.Ref {
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
})
var oAPIDefs map[string]common.OpenAPIDefinition
if *apiVersion == "v1beta1" {
oAPIDefs = tektonv1beta1.GetOpenAPIDefinitions(func(name string) spec.Ref {
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
})
} else if *apiVersion == "v1" {
oAPIDefs = tektonv1.GetOpenAPIDefinitions(func(name string) spec.Ref {
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
})
} else {
panic(fmt.Sprintf("Unsupported API version: %s", *apiVersion))
}
defs := spec.Definitions{}
for defName, val := range oAPIDefs {
defs[swaggify(defName)] = val.Schema
Expand Down
8 changes: 4 additions & 4 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister"
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
"resource:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
# This generates deepcopy,client,informer and lister for the pipeline package (v1alpha1 and v1beta1)
# This generates deepcopy,client,informer and lister for the pipeline package (v1alpha1, v1beta1, and v1)
bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
"pipeline:v1alpha1,v1beta1" \
"pipeline:v1alpha1,v1beta1,v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Depends on generate-groups.sh to install bin/deepcopy-gen
Expand Down Expand Up @@ -74,10 +74,10 @@ bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
github.com/tektoncd/pipeline/pkg/client/resource github.com/tektoncd/pipeline/pkg/apis \
"resource:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
# This generates the knative inject packages for the pipeline package (v1alpha1, v1beta1).
# This generates the knative inject packages for the pipeline package (v1alpha1, v1beta1, v1).
bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \
github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \
"pipeline:v1alpha1,v1beta1" \
"pipeline:v1alpha1,v1beta1,v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
GOFLAGS="${OLDGOFLAGS}"

Expand Down
47 changes: 28 additions & 19 deletions hack/update-openapigen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,31 @@ mkdir -p "${TMP_DIFFROOT}"

trap cleanup EXIT

echo "Generating OpenAPI specification ..."
go run k8s.io/kube-openapi/cmd/openapi-gen \
--input-dirs ./pkg/apis/pipeline/v1beta1,./pkg/apis/pipeline/pod,./pkg/apis/resource/v1alpha1,knative.dev/pkg/apis,knative.dev/pkg/apis/duck/v1beta1 \
--output-package ./pkg/apis/pipeline/v1beta1 -o ./ \
--go-header-file hack/boilerplate/boilerplate.go.txt \
-r "${TMP_DIFFROOT}/api-report"

violations=$(diff --changed-group-format='%>' --unchanged-group-format='' <(sort "hack/ignored-openapi-violations.list") <(sort "${TMP_DIFFROOT}/api-report") || echo "")
if [ -n "${violations}" ]; then
echo ""
echo "New API rule violations found which are not present in hack/ignored-openapi-violations.list. Please fix these violations:"
echo ""
echo "${violations}"
echo ""
exit 1
fi

echo "Generating swagger file ..."
go run hack/spec-gen/main.go v0.17.2 > pkg/apis/pipeline/v1beta1/swagger.json
for APIVERSION in "v1beta1" "v1"
do
input_dirs=./pkg/apis/pipeline/${APIVERSION},./pkg/apis/pipeline/pod,knative.dev/pkg/apis,knative.dev/pkg/apis/duck/v1beta1
if [ ${APIVERSION} = "v1beta1" ]
then
input_dirs=${input_dirs},./pkg/apis/resource/v1alpha1
fi

echo "Generating OpenAPI specification for ${APIVERSION} ..."
go run k8s.io/kube-openapi/cmd/openapi-gen \
--input-dirs ${input_dirs} \
--output-package ./pkg/apis/pipeline/${APIVERSION} -o ./ \
--go-header-file hack/boilerplate/boilerplate.go.txt \
-r "${TMP_DIFFROOT}/api-report"

violations=$(diff --changed-group-format='%>' --unchanged-group-format='' <(sort "hack/ignored-openapi-violations.list") <(sort "${TMP_DIFFROOT}/api-report") || echo "")
if [ -n "${violations}" ]; then
echo ""
echo "New API rule violations found which are not present in hack/ignored-openapi-violations.list. Please fix these violations:"
echo ""
echo "${violations}"
echo ""
exit 1
fi

echo "Generating swagger file for ${APIVERSION} ..."
go run hack/spec-gen/main.go -apiVersion=${APIVERSION} > pkg/apis/pipeline/${APIVERSION}/swagger.json
done
23 changes: 23 additions & 0 deletions pkg/apis/pipeline/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the pipeline v1 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/tektoncd/pipeline/pkg/apis/pipeline
// +k8s:defaulter-gen=TypeMeta
// +groupName=tekton.dev
package v1
Loading

0 comments on commit d4c2ad8

Please sign in to comment.