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

feat: codegen openapi #34

Merged
merged 2 commits into from
Jan 24, 2024
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
schedule:
interval: daily
- package-ecosystem: gomod
directory: /scripts
directory: /tools
schedule:
interval: daily
- package-ecosystem: github-actions
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Session.vim
.netrwhist
.idea
*manifest-tool
.gopath
.tools
2 changes: 1 addition & 1 deletion scripts/boilerplate.go.txt → .hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 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 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
Expand Down
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ REPO ?= policy-reports
#########

TOOLS_DIR := $(PWD)/.tools
REGISTER_GEN := $(TOOLS_DIR)/register-gen
OPENAPI_GEN := $(TOOLS_DIR)/openapi-gen
CODE_GEN_VERSION := v0.28.0
KIND := $(TOOLS_DIR)/kind
KIND_VERSION := v0.20.0
KO := $(TOOLS_DIR)/ko
KO_VERSION := v0.14.1
HELM := $(TOOLS_DIR)/helm
HELM_VERSION := v3.10.1
TOOLS := $(KIND) $(KO) $(HELM)
TOOLS := $(REGISTER_GEN) $(OPENAPI_GEN) $(KIND) $(KO) $(HELM)

$(REGISTER_GEN):
@echo Install register-gen... >&2
@GOBIN=$(TOOLS_DIR) go install k8s.io/code-generator/cmd/register-gen@$(CODE_GEN_VERSION)

$(OPENAPI_GEN):
@echo Install openapi-gen... >&2
@GOBIN=$(TOOLS_DIR) go install k8s.io/code-generator/cmd/openapi-gen@$(CODE_GEN_VERSION)

$(KIND):
@echo Install kind... >&2
Expand Down Expand Up @@ -84,6 +95,33 @@ ko-build: $(KO) ## Build image (with ko)
# CODEGEN #
###########

GOPATH_SHIM := ${PWD}/.gopath
PACKAGE_SHIM := $(GOPATH_SHIM)/src/$(PACKAGE)

$(GOPATH_SHIM):
@echo Create gopath shim... >&2
@mkdir -p $(GOPATH_SHIM)

.INTERMEDIATE: $(PACKAGE_SHIM)
$(PACKAGE_SHIM): $(GOPATH_SHIM)
@echo Create package shim... >&2
@mkdir -p $(GOPATH_SHIM)/src/github.com/$(ORG) && ln -s -f ${PWD} $(PACKAGE_SHIM)

.PHONY: codegen-openapi
codegen-openapi: $(PACKAGE_SHIM) $(OPENAPI_GEN) ## Generate openapi
@echo Generate openapi... >&2
@$(OPENAPI_GEN) \
-i k8s.io/apimachinery/pkg/api/resource \
-i k8s.io/apimachinery/pkg/apis/meta/v1 \
-i k8s.io/apimachinery/pkg/version \
-i k8s.io/apimachinery/pkg/runtime \
-i k8s.io/apimachinery/pkg/types \
-i k8s.io/api/core/v1 \
-i sigs.k8s.io/wg-policy-prototypes/policy-report/pkg/api/wgpolicyk8s.io/v1alpha2 \
-p ./pkg/api/generated/openapi \
-O zz_generated.openapi \
-h ./.hack/boilerplate.go.txt

.PHONY: codegen-helm-docs
codegen-helm-docs: ## Generate helm docs
@echo Generate helm docs... >&2
Expand All @@ -92,6 +130,7 @@ codegen-helm-docs: ## Generate helm docs
.PHONY: codegen
codegen: ## Rebuild all generated code and docs
codegen: codegen-helm-docs
codegen: codegen-openapi

.PHONY: verify-codegen
verify-codegen: codegen ## Verify all generated code and docs are up to date
Expand Down
13,116 changes: 12,881 additions & 235 deletions pkg/api/generated/openapi/zz_generated.openapi.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/go.mod → tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kyverno/policy-reports/scripts
module github.com/kyverno/policy-reports/tools

go 1.21

Expand Down
File renamed without changes.
File renamed without changes.
Loading