diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 6a9f85ef33e1ca004c233f9dd4ae1541263083ec..7e2f4577777464dc32a65e6b4a48283e98ef6b68 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -4,30 +4,50 @@ set -o errexit set -o nounset set -o pipefail -GENERATED_PACKAGE_ROOT="src/github.com" -OPERATOR_PACKAGE_ROOT="${GENERATED_PACKAGE_ROOT}/zalando/postgres-operator" +OPERATOR_PACKAGE_ROOT="zalando/postgres-operator" +# TARGET_CODE_DIR=${1-${SCRIPT_ROOT}/pkg} + SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -TARGET_CODE_DIR=${1-${SCRIPT_ROOT}/pkg} CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} source "${CODEGEN_PKG}/kube_codegen.sh" -cleanup() { - rm -rf "${GENERATED_PACKAGE_ROOT}" -} -trap "cleanup" EXIT SIGINT +# generate the code with: +# --output-base because this script should also be able to run inside the vendor dir of +# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir +# instead of the $GOPATH directly. For normal projects this can be dropped. + +#cleanup() { +# rm -rf "${OPERATOR_PACKAGE_ROOT}" +#} +#trap "cleanup" EXIT SIGINT kube::codegen::gen_helpers \ --input-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/apis" \ - --output-base "$(dirname "${BASH_SOURCE[0]}")/../../../../.." \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ --boilerplate "${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt" +if [[ -n "${API_KNOWN_VIOLATIONS_DIR:-}" ]]; then + report_filename="${API_KNOWN_VIOLATIONS_DIR}/sample_apiserver_violation_exceptions.list" + if [[ "${UPDATE_API_KNOWN_VIOLATIONS:-}" == "true" ]]; then + update_report="--update-report" + fi +fi + +kube::codegen::gen_openapi \ + --input-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/apis" \ + --output-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/generated" \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ + --report-filename "${report_filename:-"/dev/null"}" \ + ${update_report:+"${update_report}"} \ + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" + kube::codegen::gen_client \ --with-watch \ --with-applyconfig \ --input-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/apis" \ - --output-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/generated/client" \ - --output-base "$(dirname "${BASH_SOURCE[0]}")/../../../../.." \ + --output-pkg-root "${OPERATOR_PACKAGE_ROOT}/pkg/generated" \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ --boilerplate "${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt" #bash "${CODEGEN_PKG}/kube_codegen.sh" client,deepcopy,informer,lister \ @@ -38,4 +58,4 @@ kube::codegen::gen_client \ #cp -r "${OPERATOR_PACKAGE_ROOT}"/pkg/* "${TARGET_CODE_DIR}" -cleanup +#cleanup diff --git a/pkg/apis/acid.zalan.do/register.go b/pkg/apis/acid.zalan.do/register.go index f993966564c0261417466a0c8c88a2579c59e15a..9244b4c24a25a41d4f6c21cf1ead331344733365 100644 --- a/pkg/apis/acid.zalan.do/register.go +++ b/pkg/apis/acid.zalan.do/register.go @@ -1,6 +1,52 @@ package acidzalando +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + const ( // GroupName is the group name for the operator CRDs GroupName = "acid.zalan.do" ) + +var ( + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + + // SchemeBuilder : An instance of runtime.SchemeBuilder, global for this package + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + //AddToScheme is localSchemeBuilder.AddToScheme + AddToScheme = localSchemeBuilder.AddToScheme + //SchemeGroupVersion has GroupName and APIVersion + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + // AddKnownType assumes derives the type kind from the type name, which is always uppercase. + // For our CRDs we use lowercase names historically, therefore we have to supply the name separately. + // TODO: User uppercase CRDResourceKind of our types in the next major API version + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresql"), &Postgresql{}) + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresqlList"), &PostgresqlList{}) + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("PostgresTeam"), &PostgresTeam{}) + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("PostgresTeamList"), &PostgresTeamList{}) + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfiguration"), + &OperatorConfiguration{}) + scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfigurationList"), + &OperatorConfigurationList{}) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/zalando.org/register.go b/pkg/apis/zalando.org/register.go index 3dbd3f089661935632e55b1d1ef701bd19846071..1979517976914b1061c81602db835f30f742c27b 100644 --- a/pkg/apis/zalando.org/register.go +++ b/pkg/apis/zalando.org/register.go @@ -1,6 +1,38 @@ package zalando +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + const ( // GroupName is the group name for the operator CRDs GroupName = "zalando.org" ) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns back a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &FabricEventStream{}, + &FabricEventStreamList{}, + ) + return nil +}