Skip to content

Commit

Permalink
add clientset/lister/informer generation (kubeflow#1194)
Browse files Browse the repository at this point in the history
* adapt v1beta1

* add resources for v1alpha3

* fix

* refine update-codegen script

* add katib apiVersion as prefix of swagger version
  • Loading branch information
sperlingxx committed Jun 29, 2020
1 parent b3a6b18 commit c43c1e1
Show file tree
Hide file tree
Showing 378 changed files with 30,892 additions and 50 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

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

9 changes: 9 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ required = [
name = "github.com/kubeflow/katib"
unused-packages = false
non-go = false

[[prune.project]]
name = "k8s.io/code-generator"
unused-packages = false
non-go = false

[[prune.project]]
name = "k8s.io/gengo"
unused-packages = false
39 changes: 39 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Copyright 2019 The Kubeflow 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.

set -o errexit
set -o nounset
set -o pipefail

if [[ -z "${GOPATH:-}" ]]; then
export GOPATH=$(go env GOPATH)
fi

VERSION_LIST=(v1alpha3 v1beta1)
PROJECT_ROOT=${GOPATH}/src/github.com/kubeflow/katib

modules=(experiments suggestions trials common)
versions=(v1alpha3 v1beta1)
versionStr=$(printf ",%s" "${versions[@]}")
GROUP_VERSIONS=$(printf "%s:${versionStr:1} " "${modules[@]}")

echo "Generating clients for ${GROUP_VERSIONS} ..."
${PROJECT_ROOT}/vendor/k8s.io/code-generator/generate-groups.sh \
all \
github.com/kubeflow/katib/pkg/client/controller \
github.com/kubeflow/katib/pkg/apis/controller \
"${GROUP_VERSIONS}" \
--go-header-file ${PROJECT_ROOT}/hack/boilerplate.go.txt
46 changes: 15 additions & 31 deletions hack/update-openapigen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,24 @@ set -o nounset
set -o pipefail

if [[ -z "${GOPATH:-}" ]]; then
export GOPATH=$(go env GOPATH)
export GOPATH=$(go env GOPATH)
fi

PROJECT_ROOT=$(pwd)
CODEGEN_PKG=$(pwd)/vendor/k8s.io/code-generator

KATIB_VERSION_V1ALPHA3="v1alpha3"
SWAGGER_CODEGEN_FILE_V1ALPHA3="pkg/apis/v1alpha3/swagger.json"

KATIB_VERSION_V1BETA1="v1beta1"
SWAGGER_CODEGEN_FILE_V1BETA1="pkg/apis/v1beta1/swagger.json"

PROJECT_ROOT=${GOPATH}/src/github.com/kubeflow/katib
CODEGEN_PKG=${PROJECT_ROOT}/vendor/k8s.io/code-generator
VERSION_LIST=(v1alpha3 v1beta1)
SWAGGER_VERSION="0.1"

# OpenAPI for v1alpha3 Katib version
echo "Generating OpenAPI specification for v1alpha3..."
go run ${CODEGEN_PKG}/cmd/openapi-gen/main.go \
--go-header-file ${PROJECT_ROOT}/hack/boilerplate.go.txt \
--input-dirs github.com/kubeflow/katib/pkg/apis/controller/common/${KATIB_VERSION_V1ALPHA3},github.com/kubeflow/katib/pkg/apis/controller/experiments/${KATIB_VERSION_V1ALPHA3},github.com/kubeflow/katib/pkg/apis/controller/suggestions/${KATIB_VERSION_V1ALPHA3},github.com/kubeflow/katib/pkg/apis/controller/trials/${KATIB_VERSION_V1ALPHA3} \
--output-package github.com/kubeflow/katib/pkg/apis/${KATIB_VERSION_V1ALPHA3} \
$@

# Swagger file for v1alpha3 Katib version
echo "Generating Swagger file for v1alpha3..."
go run hack/swagger/main.go ${SWAGGER_VERSION} ${KATIB_VERSION_V1ALPHA3} >${SWAGGER_CODEGEN_FILE_V1ALPHA3}
for VERSION in ${VERSION_LIST[@]}; do
SWAGGER_CODEGEN_FILE=${PROJECT_ROOT}/pkg/apis/${VERSION}/swagger.json

# OpenAPI for v1beta1 Katib version
echo "Generating OpenAPI specification for v1beta1..."
go run ${CODEGEN_PKG}/cmd/openapi-gen/main.go \
--go-header-file ${PROJECT_ROOT}/hack/boilerplate.go.txt \
--input-dirs github.com/kubeflow/katib/pkg/apis/controller/common/${KATIB_VERSION_V1BETA1},github.com/kubeflow/katib/pkg/apis/controller/experiments/${KATIB_VERSION_V1BETA1},github.com/kubeflow/katib/pkg/apis/controller/suggestions/${KATIB_VERSION_V1BETA1},github.com/kubeflow/katib/pkg/apis/controller/trials/${KATIB_VERSION_V1BETA1} \
--output-package github.com/kubeflow/katib/pkg/apis/${KATIB_VERSION_V1BETA1} \
$@
echo "Generating OpenAPI specification for ${VERSION} ..."
go run ${CODEGEN_PKG}/cmd/openapi-gen/main.go \
--go-header-file ${PROJECT_ROOT}/hack/boilerplate.go.txt \
--input-dirs github.com/kubeflow/katib/pkg/apis/controller/common/${VERSION},github.com/kubeflow/katib/pkg/apis/controller/experiments/${VERSION},github.com/kubeflow/katib/pkg/apis/controller/suggestions/${VERSION},github.com/kubeflow/katib/pkg/apis/controller/trials/${VERSION} \
--output-package github.com/kubeflow/katib/pkg/apis/${VERSION} \
$@

# Swagger file for v1beta1 Katib version
echo "Generating Swagger file for v1beta1..."
go run hack/swagger/main.go ${SWAGGER_VERSION} ${KATIB_VERSION_V1BETA1} >${SWAGGER_CODEGEN_FILE_V1BETA1}
echo "Generating swagger file for ${VERSION} ..."
go run ${PROJECT_ROOT}/hack/swagger/main.go ${VERSION}-${SWAGGER_VERSION} ${VERSION} > ${SWAGGER_CODEGEN_FILE}
done
7 changes: 5 additions & 2 deletions pkg/apis/controller/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Generate deepcopy for apis
//go:generate go run ../../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../../hack/boilerplate.go.txt
// Generate deepcopy, clientset, listers, informers for apis
//go:generate ../../../hack/update-codegen.sh

// Generate open-api for apis
//go:generate ../../../hack/update-openapigen.sh

// Package apis contains Kubernetes API groups.
package apis
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/controller/common/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/common/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/experiments/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/experiments/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/suggestions/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/suggestions/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/trials/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

5 changes: 5 additions & 0 deletions pkg/apis/controller/trials/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

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

2 changes: 1 addition & 1 deletion pkg/apis/v1alpha3/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"description": "Swagger description for Katib",
"title": "Katib",
"version": "v0.1"
"version": "v1alpha3-0.1"
},
"paths": {},
"definitions": {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/v1beta1/openapi_generated.go

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

5 changes: 2 additions & 3 deletions pkg/apis/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"description": "Swagger description for Katib",
"title": "Katib",
"version": "v0.1"
"version": "v1beta1-0.1"
},
"paths": {},
"definitions": {
Expand Down Expand Up @@ -666,8 +666,7 @@
"type": "string"
},
"value": {
"type": "number",
"format": "double"
"type": "string"
}
}
},
Expand Down
Loading

0 comments on commit c43c1e1

Please sign in to comment.