From bd5659c8ff64d4ae4d71d895db38171953b2ee76 Mon Sep 17 00:00:00 2001 From: daliu Date: Tue, 11 Aug 2020 14:30:54 +0800 Subject: [PATCH] add hack dir --- Makefile | 54 ++++++++++++++++++++++++++++ go.sum | 2 ++ hack/custom-boilerplate.go.txt | 1 + hack/update-apiserver-gen.sh | 64 ++++++++++++++++++++++++++++++++++ hack/update-protobuf.sh | 50 ++++++++++++++++++++++++++ 5 files changed, 171 insertions(+) create mode 100644 hack/custom-boilerplate.go.txt create mode 100755 hack/update-apiserver-gen.sh create mode 100755 hack/update-protobuf.sh diff --git a/Makefile b/Makefile index f20ce3de5..53529def2 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,11 @@ IMAGE_REGISTRY ?= quay.io/open-cluster-management IMAGE_TAG ?= latest IMAGE_NAME ?= $(IMAGE_REGISTRY)/$(IMAGE):$(IMAGE_TAG) +GIT_HOST ?= github.com/open-cluster-management +BASE_DIR := $(shell basename $(PWD)) +DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR) +BINDIR ?= output + # KUBEBUILDER for unit test export KUBEBUILDER_ASSETS ?=$(shell pwd)/$(PERMANENT_TMP_GOPATH)/kubebuilder/bin @@ -72,6 +77,55 @@ build-e2e: test-e2e: build-e2e deploy-hub deploy-klusterlet deploy-acm-foundation-hub deploy-acm-foundation-agent ./e2e.test -test.v -ginkgo.v +############################################################ +# This section contains the code generation stuff +############################################################ + +generate_exes: $(BINDIR)/defaulter-gen \ + $(BINDIR)/deepcopy-gen \ + $(BINDIR)/conversion-gen \ + $(BINDIR)/client-gen \ + $(BINDIR)/lister-gen \ + $(BINDIR)/informer-gen \ + $(BINDIR)/openapi-gen \ + $(BINDIR)/go-to-protobuf \ + $(BINDIR)/protoc-gen-gogo \ + +$(BINDIR)/defaulter-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/defaulter-gen + +$(BINDIR)/deepcopy-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/deepcopy-gen + +$(BINDIR)/conversion-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/conversion-gen + +$(BINDIR)/client-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/client-gen + +$(BINDIR)/lister-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/lister-gen + +$(BINDIR)/informer-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/informer-gen + +$(BINDIR)/openapi-gen: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/openapi-gen + +$(BINDIR)/go-to-protobuf: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/go-to-protobuf + +$(BINDIR)/protoc-gen-gogo: + go build -o $@ $(DEST)/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo + +# Regenerate all files if the gen exes changed or any "types.go" files changed +generate_files: generate_exes $(TYPES_FILES) + # generate apiserver deps + hack/update-apiserver-gen.sh + # generate protobuf + hack/update-protobuf.sh + + # Generate manifests e.g. CRD, RBAC etc. manifests: ensure-controller-gen $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/action/v1beta1" output:crd:artifacts:config=deploy/dev/hub/resources/crds diff --git a/go.sum b/go.sum index aa9323468..c03070c62 100644 --- a/go.sum +++ b/go.sum @@ -731,12 +731,14 @@ k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g= k8s.io/code-generator v0.0.0-20190717022600-77f3a1fe56bb/go.mod h1:cDx5jQmWH25Ff74daM7NVYty9JWw9dvIS9zT9eIubCY= k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc= k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= +k8s.io/code-generator v0.18.4 h1:SouAMfh3jbL7aL8rnUQ/C+7WwXYTZnPa8L9V2TtIE7o= k8s.io/code-generator v0.18.4/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= k8s.io/component-base v0.18.2 h1:SJweNZAGcUvsypLGNPNGeJ9UgPZQ6+bW+gEHe8uyh/Y= k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM= k8s.io/component-base v0.18.4 h1:Kr53Fp1iCGNsl9Uv4VcRvLy7YyIqi9oaJOQ7SXtKI98= k8s.io/component-base v0.18.4/go.mod h1:7jr/Ef5PGmKwQhyAz/pjByxJbC58mhKAhiaDu0vXfPk= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/gengo v0.0.0-20200114144118-36b2048a9120 h1:RPscN6KhmG54S33L+lr3GS+oD1jmchIU0ll519K6FA4= k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= diff --git a/hack/custom-boilerplate.go.txt b/hack/custom-boilerplate.go.txt new file mode 100644 index 000000000..b5b2ef217 --- /dev/null +++ b/hack/custom-boilerplate.go.txt @@ -0,0 +1 @@ +// Copyright (c) 2020 Red Hat, Inc. diff --git a/hack/update-apiserver-gen.sh b/hack/update-apiserver-gen.sh new file mode 100755 index 000000000..0518c73d5 --- /dev/null +++ b/hack/update-apiserver-gen.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# licensed Materials - Property of IBM +# 5737-E67 +# (C) Copyright IBM Corporation 2016, 2019 All Rights Reserved +# US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. +# +# Copyright 2018 The Kubernetes 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. + +# The only argument this script should ever be called with is '--verify-only' + +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +realpath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +REPO_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..) +BINDIR="${REPO_ROOT}"/output +SC_PKG='github.com/open-cluster-management/multicloud-operators-foundation' + +# Generate defaults +"${BINDIR}"/defaulter-gen "$@" \ + --v 1 --logtostderr \ + --go-header-file "${REPO_ROOT}"/hack/custom-boilerplate.go.txt \ + --input-dirs "${SC_PKG}/pkg/proxyserver/apis/v1beta1" \ + --extra-peer-dirs "${SC_PKG}/pkg/proxyserver/apis/v1beta1" \ + --output-file-base "zz_generated.defaults" +# Generate deep copies +"${BINDIR}"/deepcopy-gen "$@" \ + --v 1 --logtostderr\ + --go-header-file "${REPO_ROOT}"/hack/custom-boilerplate.go.txt \ + --input-dirs "${SC_PKG}/pkg/proxyserver/apis/v1beta1" \ + --output-file-base zz_generated.deepcopy +# Generate conversions +"${BINDIR}"/conversion-gen "$@" \ + --v 1 --logtostderr \ + --extra-peer-dirs k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/conversion,k8s.io/apimachinery/pkg/runtime \ + --go-header-file "${REPO_ROOT}"/hack/custom-boilerplate.go.txt \ + --input-dirs "${SC_PKG}/pkg/proxyserver/apis/v1beta1" \ + --output-file-base zz_generated.conversion + +# generate openapi for servicecatalog and settings group +"${BINDIR}"/openapi-gen "$@" \ + --v 1 --logtostderr \ + --go-header-file "${REPO_ROOT}"/hack/custom-boilerplate.go.txt \ + --input-dirs "${SC_PKG}/pkg/proxyserver/apis/v1beta1,k8s.io/apimachinery/pkg/apis/meta/v1" \ + --output-package "${SC_PKG}/pkg/proxyserver/apis/openapi" \ + --report-filename ".api_violation.report" diff --git a/hack/update-protobuf.sh b/hack/update-protobuf.sh new file mode 100755 index 000000000..2181d2cb5 --- /dev/null +++ b/hack/update-protobuf.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# licensed Materials - Property of IBM +# 5737-E67 +# (C) Copyright IBM Corporation 2016, 2019 All Rights Reserved +# US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. +# +# Copyright 2018 The Kubernetes 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. + +# The only argument this script should ever be called with is '--verify-only' + +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +realpath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +REPO_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..) +BINDIR="${REPO_ROOT}"/output +SC_PKG='github.com/open-cluster-management/multicloud-operators-foundation' + +if [[ "$(protoc --version)" != "libprotoc 3.0."* ]]; then + echo "Generating protobuf requires protoc 3.0.x. Please download and +install the platform appropriate Protobuf package for your OS: + https://github.com/google/protobuf/releases" + exit 1 +fi + +PATH="$PATH:$BINDIR" go-to-protobuf \ + --output-base="${GOPATH}/src" \ + --apimachinery-packages='-k8s.io/apimachinery/pkg/util/intstr,-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/api/core/v1,-k8s.io/api/rbac/v1,-k8s.io/api/certificates/v1beta1' \ + --go-header-file="${REPO_ROOT}"/hack/custom-boilerplate.go.txt \ + --proto-import="${REPO_ROOT}"/third_party/protobuf \ + --proto-import="${REPO_ROOT}"/vendor \ + --packages="${SC_PKG}/pkg/proxyserver/apis/v1beta1"