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

✨ introduce runtime-openapi-gen to generate openapi spec on release #6462

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ run:
- e2e
skip-files:
- "zz_generated.*\\.go$"
- "vendored_openapi\\.go$"
skip-dirs:
- third_party
allow-parallel-runners: true
50 changes: 47 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ KPROMO_PKG := sigs.k8s.io/promo-tools/v3/cmd/kpromo
CONVERSION_VERIFIER_BIN := conversion-verifier
CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_VERIFIER_BIN))

OPENAPI_GEN_VER := 5e7f5fd
OPENAPI_GEN_BIN := openapi-gen
# We are intentionally using the binary without version suffix, to avoid the version
# in generated files.
chrischdi marked this conversation as resolved.
Show resolved Hide resolved
OPENAPI_GEN := $(abspath $(TOOLS_BIN_DIR)/$(OPENAPI_GEN_BIN))
OPENAPI_GEN_PKG := k8s.io/kube-openapi/cmd/openapi-gen

RUNTIME_OPENAPI_GEN_BIN := runtime-openapi-gen
RUNTIME_OPENAPI_GEN := $(abspath $(TOOLS_BIN_DIR)/$(RUNTIME_OPENAPI_GEN_BIN))

TILT_PREPARE_BIN := tilt-prepare
TILT_PREPARE := $(abspath $(TOOLS_BIN_DIR)/$(TILT_PREPARE_BIN))

Expand Down Expand Up @@ -179,8 +189,8 @@ help: # Display this help
ALL_GENERATE_MODULES = core kubeadm-bootstrap kubeadm-control-plane

.PHONY: generate
generate: ## Run all generate-manifests-*, generate-go-deepcopy-*, generate-go-conversions-* targets
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions
generate: ## Run all generate-manifests-*, generate-go-deepcopy-*, generate-go-conversions-* and generate-go-openapi targets
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions generate-go-openapi
$(MAKE) -C $(CAPD_DIR) generate

.PHONY: generate-manifests
Expand Down Expand Up @@ -328,6 +338,18 @@ generate-go-conversions-kubeadm-control-plane: $(CONVERSION_GEN) ## Generate con
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-openapi
generate-go-openapi: $(OPENAPI_GEN) $(CONTROLLER_GEN) ## Generate openapi go code for runtime SDK
@for pkg in "api/v1beta1" "$(EXP_DIR)/runtime/hooks/api/v1alpha1"; do \
$(MAKE) clean-generated-openapi-definitions SRC_DIRS="./$${pkg}"; \
echo "** Generating openapi schema for types in ./$${pkg} **"; \
$(OPENAPI_GEN) \
--input-dirs=./$${pkg} \
--output-file-base=zz_generated.openapi \
--output-package=sigs.k8s.io/cluster-api/$${pkg} \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt; \
done

.PHONY: generate-modules
generate-modules: ## Run go mod tidy to ensure modules are up to date
go mod tidy
Expand Down Expand Up @@ -590,7 +612,7 @@ manifest-modification: # Set the manifest images to the staging/production bucke
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_pull_policy.yaml"

.PHONY: release-manifests
release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) ## Build the manifests to publish with a release
release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) $(RUNTIME_OPENAPI_GEN) ## Build the manifests to publish with a release
# Build core-components.
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/core-components.yaml
# Build bootstrap-components.
Expand All @@ -607,6 +629,9 @@ release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) ## Build the manifests to publish
# Add metadata to the release artifacts
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml

# Generate OpenAPI specification.
$(RUNTIME_OPENAPI_GEN) --version $(RELEASE_TAG) --output-file $(RELEASE_DIR)/runtime-sdk-openapi.yaml

.PHONY: release-manifests-dev
release-manifests-dev: ## Build the development manifests and copies them in the release folder
# Release CAPD components and add them to the release dir
Expand Down Expand Up @@ -761,6 +786,10 @@ clean-release-git: ## Restores the git files usually modified during a release
clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs. Example SRC_DIRS="./api/v1alpha4"
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done)

.PHONY: clean-generated-openapi-definitions
clean-generated-openapi-definitions: ## Remove files generated by openapi-gen from the mentioned dirs. Example SRC_DIRS="./api/v1alpha4"
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.openapi*' -exec rm -f {} \;; done)

## --------------------------------------
## Hack / Tools
## --------------------------------------
Expand All @@ -773,6 +802,12 @@ $(CONTROLLER_GEN_BIN): $(CONTROLLER_GEN) ## Build a local copy of controller-gen
.PHONY: $(CONVERSION_GEN_BIN)
$(CONVERSION_GEN_BIN): $(CONVERSION_GEN) ## Build a local copy of conversion-gen.

.PHONY: $(OPENAPI_GEN_BIN)
$(OPENAPI_GEN_BIN): $(OPENAPI_GEN) ## Build a local copy of openapi-gen.

.PHONY: $(RUNTIME_OPENAPI_GEN_BIN)
$(RUNTIME_OPENAPI_GEN_BIN): $(RUNTIME_OPENAPI_GEN) ## Build a local copy of runtime-openapi-gen.

.PHONY: $(CONVERSION_VERIFIER_BIN)
$(CONVERSION_VERIFIER_BIN): $(CONVERSION_VERIFIER) ## Build a local copy of conversion-verifier.

Expand Down Expand Up @@ -812,6 +847,15 @@ $(CONVERSION_GEN): # Build conversion-gen from tools folder.
$(CONVERSION_VERIFIER): $(TOOLS_DIR)/go.mod # Build conversion-verifier from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(CONVERSION_VERIFIER_BIN) sigs.k8s.io/cluster-api/hack/tools/conversion-verifier

.PHONY: $(OPENAPI_GEN)
chrischdi marked this conversation as resolved.
Show resolved Hide resolved
$(OPENAPI_GEN): # Build openapi-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(OPENAPI_GEN_PKG) $(OPENAPI_GEN_BIN) $(OPENAPI_GEN_VER)

## We are forcing a rebuilt of runtime-openapi-gen via PHONY so that we're always using an up-to-date version.
.PHONY: $(RUNTIME_OPENAPI_GEN)
$(RUNTIME_OPENAPI_GEN): $(TOOLS_DIR)/go.mod # Build openapi-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(RUNTIME_OPENAPI_GEN_BIN) sigs.k8s.io/cluster-api/hack/tools/runtime-openapi-gen

$(GOTESTSUM): # Build gotestsum from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOTESTSUM_PKG) $(GOTESTSUM_BIN) $(GOTESTSUM_VER)

Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ limitations under the License.
*/

// Package v1beta1 contains the v1beta1 API implementation.
// +k8s:openapi-gen=true
package v1beta1
Loading