From 95d39c326009b3ea861b694628b2b46e9b284877 Mon Sep 17 00:00:00 2001 From: William Stewart Date: Wed, 4 Dec 2019 11:24:02 +0100 Subject: [PATCH] Add code to generate openapi specs Some of the modern Kubernetes clients use clients generated from a swagger.json kubernetes-client/javascript uses kubernetes-client/gen which uses OpenApiTools/openapi-generator and kubernetes/kubernetes/api/openapi-spec/swagger.json There are open/closed/rotten/ignored issues all over the place about making these easier to use with CRDs. Wrongly closed issue on kubernetes-client/javascript: https://github.com/kubernetes-client/javascript/issues/341 Open issue on kubernetes-client/gen: https://github.com/kubernetes-client/gen/issues/121 It seems like kubernetes/kube-openapi is one of the repos working on solving the main part of this problem, generating the Go code to make it easy to generate a swagger.json I found the following Argo code via the following issue: https://github.com/kubernetes/kube-openapi/issues/13 https://github.com/argoproj/argo/blob/master/hack/gen-openapi-spec/main.go https://github.com/argoproj/argo/blob/master/pkg/apis/workflow/v1alpha1/openapi_generated.go#L14:6 https://github.com/kubernetes/kube-openapi/blob/master/cmd/openapi-gen/openapi-gen.go So I'm working on adding similar stuff to Shipper. gen-openapi-spec uses the generated openapi_generated.go module that is generated via the openapi-gen command. The following commit adds the code to generate openapi_generated.go Signed-off-by: William Stewart --- hack/update-openapigen.sh | 26 ++++++++++++++++ pkg/apis/api-rules/violation_exceptions.list | 32 ++++++++++++++++++++ pkg/apis/shipper/v1alpha1/doc.go | 1 + 3 files changed, 59 insertions(+) create mode 100755 hack/update-openapigen.sh create mode 100644 pkg/apis/api-rules/violation_exceptions.list diff --git a/hack/update-openapigen.sh b/hack/update-openapigen.sh new file mode 100755 index 000000000..9e371fa04 --- /dev/null +++ b/hack/update-openapigen.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +# PROJECT_ROOT=$(cd $(dirname "$0")/.. ; pwd) +# CODEGEN_PKG=${PROJECT_ROOT}/vendor/k8s.io/kube-openapi +# VERSION="v1alpha1" +# +# go run ${CODEGEN_PKG}/cmd/openapi-gen/openapi-gen.go \ +# --go-header-file ${PROJECT_ROOT}/hack/custom-boilerplate.go.txt \ +# --input-dirs github.com/bookingcom/shipper/pkg/apis/workflow/${VERSION} \ +# --output-package github.com/argoproj/argo/pkg/apis/workflow/${VERSION} \ +# --report-filename pkg/apis/api-rules/violation_exceptions.list \ +# $@ +# PROJECT_ROOT=$(cd $(dirname "$0")/.. ; pwd) +# CODEGEN_PKG=${PROJECT_ROOT}/vendor/k8s.io/kube-openapi +VERSION="v1alpha1" + +go run $GOPATH/src/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go \ + --input-dirs github.com/bookingcom/shipper/pkg/apis/shipper/${VERSION} \ + --output-package github.com/bookingcom/shipper/pkg/apis/shipper/${VERSION} \ + --report-filename pkg/apis/api-rules/violation_exceptions.list + $@ + diff --git a/pkg/apis/api-rules/violation_exceptions.list b/pkg/apis/api-rules/violation_exceptions.list new file mode 100644 index 000000000..066fa4bd3 --- /dev/null +++ b/pkg/apis/api-rules/violation_exceptions.list @@ -0,0 +1,32 @@ +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ApplicationList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ApplicationStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ApplicationStatus,History +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,CapacityTargetList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,CapacityTargetSpec,Clusters +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,CapacityTargetStatus,Clusters +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityReport,Breakdown +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityReportBreakdown,Containers +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityReportContainerBreakdown,States +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityStatus,Reports +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterCapacityStatus,SadPods +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterInstallationStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterRequirements,Capabilities +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterRequirements,Regions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterSpec,Capabilities +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ClusterTrafficStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,InstallationTargetList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,InstallationTargetSpec,Clusters +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,InstallationTargetStatus,Clusters +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,PodStatus,Containers +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,PodStatus,InitContainers +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ReleaseList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ReleaseStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,ReleaseStrategyStatus,Conditions +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,RolloutBlockList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,RolloutStrategy,Steps +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,TrafficTargetList,Items +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,TrafficTargetSpec,Clusters +API rule violation: list_type_missing,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,TrafficTargetStatus,Clusters +API rule violation: names_match,github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1,Chart,RepoURL diff --git a/pkg/apis/shipper/v1alpha1/doc.go b/pkg/apis/shipper/v1alpha1/doc.go index a30598a24..ec1f36101 100644 --- a/pkg/apis/shipper/v1alpha1/doc.go +++ b/pkg/apis/shipper/v1alpha1/doc.go @@ -1,4 +1,5 @@ // +k8s:deepcopy-gen=package,register +// +k8s:openapi-gen=true // Package v1alpha1 is the v1alpha1 version of the API. // +groupName=shipper.booking.com