Skip to content

Commit

Permalink
Update code-gen scripts to latest. (#776)
Browse files Browse the repository at this point in the history
Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun authored Sep 2, 2024
1 parent 1d2fab1 commit d740185
Show file tree
Hide file tree
Showing 48 changed files with 3,562 additions and 2,333 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ output
_output
apiserver.local.config
.api_violation.report
generate_exes
generate_files
.idea
.ko.yaml
agent
Expand Down
52 changes: 14 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ KUSTOMIZE_VERSION?=v3.5.4
KUSTOMIZE_ARCHIVE_NAME?=kustomize_$(KUSTOMIZE_VERSION)_$(GOHOSTOS)_$(GOHOSTARCH).tar.gz
kustomize_dir:=$(dir $(KUSTOMIZE))


HELM?=$(PERMANENT_TMP_GOPATH)/bin/helm
HELM_VERSION?=v3.14.0
HELM_ARCHIVE_NAME?=helm-$(HELM_VERSION)-$(GOHOSTOS)-$(GOHOSTARCH).tar.gz
helm_dir:=$(dir $(HELM))

CODE_GENENRATOR_VERSION ?= $(shell go list -m k8s.io/code-generator | awk '{print $$2}')

# Image URL to use all building/pushing image targets;
IMAGE ?= multicloud-manager
IMAGE_REGISTRY ?= quay.io/stolostron
Expand All @@ -33,8 +34,6 @@ FOUNDATION_IMAGE_NAME ?= $(IMAGE_REGISTRY)/$(IMAGE):$(IMAGE_TAG)

GIT_HOST ?= github.com/stolostron
BASE_DIR := $(shell basename $(PWD))
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
BINDIR ?= _output

SED_CMD:=sed
ifeq ($(GOHOSTOS),darwin)
Expand Down Expand Up @@ -118,49 +117,26 @@ test-e2e: build-e2e deploy-hub deploy-klusterlet deploy-foundation deploy-addons
# This section contains the code generation stuff
############################################################

generate_exes: $(BINDIR)/defaulter-gen \
$(BINDIR)/deepcopy-gen \
$(BINDIR)/conversion-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)/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
# generate apiserver deps
hack/update-apiserver-gen.sh
# generate protobuf
hack/update-protobuf.sh

update-scripts:
hack/update-codegen.sh

update-crds:
hack/update-crds.sh

update: update-crds
update: update-crds update-scripts

verify-crds:
hack/verify-crds.sh

verify: verify-crds
verify-scripts:
hack/verify-codegen.sh

verify: verify-crds verify-scripts

update-protobuf:
go install k8s.io/code-generator/cmd/go-to-protobuf@$(CODE_GENENRATOR_VERSION)
go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo@$(CODE_GENENRATOR_VERSION)
hack/update-protobuf.sh

# Ensure kubebuilder
ensure-kubebuilder:
Expand Down
3 changes: 2 additions & 1 deletion dependencymagnet/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
package dependencymagnet

import (
_ "github.com/go-bindata/go-bindata/go-bindata"
_ "github.com/openshift/build-machinery-go"
_ "k8s.io/code-generator"
_ "k8s.io/code-generator/cmd/go-to-protobuf"
_ "k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo"
_ "k8s.io/kube-openapi/cmd/openapi-gen"
)
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/stolostron/multicloud-operators-foundation
go 1.22.0

require (
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-logr/logr v1.4.2
github.com/gogo/protobuf v1.3.2
github.com/mattbaird/jsonpatch v0.0.0-20240118010651-0ba75a80ca38
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
Expand Down
48 changes: 0 additions & 48 deletions hack/update-apiserver-gen.sh

This file was deleted.

30 changes: 30 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

source "$(dirname "${BASH_SOURCE}")/init.sh"

REPO_ROOT=$(realpath $(dirname ${BASH_SOURCE})/..)
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../../k8s.io/code-generator)}

verify="${VERIFY:-}"

source "${CODEGEN_PKG}/kube_codegen.sh"

# By default, it will generate deepcopy, defaulter and conversion for all types under the pkg/apis directory
kube::codegen::gen_helpers \
--boilerplate "${REPO_ROOT}/hack/custom-boilerplate.go.txt" \
${REPO_ROOT}/pkg/proxyserver/apis/proxy

echo "${REPO_ROOT}/hack/.api_violation.report"

# Generate openapi for servicecatalog and settings group
kube::codegen::gen_openapi \
--boilerplate "${REPO_ROOT}/hack/custom-boilerplate.go.txt" \
--update-report \
--output-dir "${REPO_ROOT}/pkg/proxyserver/apis/openapi" \
--output-pkg "${REPO_ROOT}/pkg/proxyserver/apis/openapi" \
--extra-pkgs "open-cluster-management.io/api/cluster/v1" \
--extra-pkgs "open-cluster-management.io/api/cluster/v1beta2" \
--extra-pkgs "k8s.io/apimachinery/pkg/api/resource" \
--extra-pkgs "k8s.io/apimachinery/pkg/runtime" \
--extra-pkgs "k8s.io/apimachinery/pkg/apis/meta/v1" \
${REPO_ROOT}/pkg/proxyserver/apis
8 changes: 8 additions & 0 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

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

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
VERIFY=--verify-only ${SCRIPT_ROOT}/hack/update-codegen.sh
Loading

0 comments on commit d740185

Please sign in to comment.