Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clientset/lister/informer generation #1194

Merged
merged 5 commits into from
Jun 10, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 6 additions & 6 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 @@ -106,3 +106,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need boilerplate.go.txt file in /hack folder for header?

Copy link
Member Author

@sperlingxx sperlingxx May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreyvelich Maybe we can change it to kubeflow specialized header ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be specific to Kubeflow licence, like here: https://github.com/kubeflow/katib/blob/master/hack/verify-gofmt.sh#L2-L14 ?

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each Katib version Swagger Version will be v0.1, is that fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreyvelich I've refined the schema of swagger version, which became ${katib_version}-{swagger_sub_version}. So, with swagger version, we can figure out katib version who generated it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sperlingxx, SGTM.


# 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