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 7, 2022
1 parent 22c9c5f commit 9e74532
Show file tree
Hide file tree
Showing 37 changed files with 2,767 additions and 33 deletions.
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 9e74532

Please sign in to comment.