-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (103 loc) · 6.04 KB
/
Makefile
File metadata and controls
131 lines (103 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# kernel-style V=1 build verbosity
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
endif
ifeq ($(BUILD_VERBOSE),1)
Q =
else
Q = @
endif
REPO = github.com/operator-framework/api
BUILD_PATH = $(REPO)/cmd/operator-verify
PKGS = $(shell go list ./... | grep -v /vendor/)
SPECIFIC_UNIT_TEST := $(if $(TEST),-run $(TEST),)
SPECIFIC_SKIP_UNIT_TEST := $(if $(SKIP),-skip $(SKIP),)
.DEFAULT_GOAL := help
# bingo manages consistent tooling versions for binary dependencies in a way
# which isn't sensitive to user environments
include .bingo/Variables.mk
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: install
install: ## Build & install operator-verify
$(Q)go install \
-gcflags "all=-trimpath=${GOPATH}" \
-asmflags "all=-trimpath=${GOPATH}" \
-ldflags " \
-X '${REPO}/version.GitVersion=${VERSION}' \
-X '${REPO}/version.GitCommit=${GIT_COMMIT}' \
" \
$(BUILD_PATH)
###
# Code management.
###
.PHONY: format tidy clean generate generate-openapi manifests
format: ## Format the source code
$(Q)go fmt $(PKGS)
tidy: ## Update dependencies
$(Q)go mod tidy
$(Q)go mod verify
clean: ## Clean up the build artifacts
$(Q)rm -rf build
generate: $(CONTROLLER_GEN) generate-openapi ## Generate code
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./...
generate-openapi: $(OPENAPI_GEN) ## Generate OpenAPIModelName() functions and OpenAPI definitions
@# Generate OpenAPIModelName() functions (zz_generated.model_name.go) in each input package.
@# Also produces a consolidated OpenAPI definitions file in pkg/generated/openapi/ (required by openapi-gen).
@# API rule violations are written to api_violations.report instead of failing the build.
@# New violations in api_violations.report will cause `make verify` to fail.
$(OPENAPI_GEN) \
--go-header-file ./hack/boilerplate.go.txt \
--output-file zz_generated.openapi.go \
--output-dir ./pkg/generated/openapi \
--output-pkg $(REPO)/pkg/generated/openapi \
--output-model-name-file zz_generated.model_name.go \
--report-filename ./api_violations.report \
./pkg/operators/v1alpha1 \
./pkg/lib/version
manifests: $(CONTROLLER_GEN) $(YQ) ## Generate manifests e.g. CRD, RBAC etc
@# Create CRDs for new APIs
$(CONTROLLER_GEN) crd:crdVersions=v1 output:crd:dir=./crds paths=./pkg/operators/...
@# Update existing CRDs from type changes
$(CONTROLLER_GEN) schemapatch:manifests=./crds output:dir=./crds paths=./pkg/operators/...
@# Add missing defaults in embedded core API schemas
$(YQ) --inplace '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.containers.items.properties.ports.items.properties.protocol.default="TCP"' ./crds/operators.coreos.com_clusterserviceversions.yaml
$(Q)$(YQ) --inplace '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.initContainers.items.properties.ports.items.properties.protocol.default="TCP"' ./crds/operators.coreos.com_clusterserviceversions.yaml
$(YQ) --inplace '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.imagePullSecrets.items.properties.name.default=""' ./crds/operators.coreos.com_clusterserviceversions.yaml
$(Q)$(YQ) --inplace '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.spec.properties.hostAliases.items.properties.ip.default=""' ./crds/operators.coreos.com_clusterserviceversions.yaml
@# Preserve fields for embedded metadata fields
$(Q)$(YQ) --inplace '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.metadata.x-kubernetes-preserve-unknown-fields=true' ./crds/operators.coreos.com_clusterserviceversions.yaml
@# Remove OperatorCondition.spec.overrides[*].lastTransitionTime requirement
$(Q)$(YQ) --inplace 'del(.spec.versions[].schema.openAPIV3Schema.properties.spec.properties.overrides.items.required[] | select(. == "lastTransitionTime"))' ./crds/operators.coreos.com_operatorconditions.yaml
@# Remove status subresource from the CRD manifests to ensure server-side apply works
$(Q)for f in ./crds/*.yaml ; do $(YQ) --inplace 'del(.status)' $$f; done
@# Update embedded CRD files.
$(Q)go generate ./crds/...
# Static tests.
.PHONY: test test-unit verify unit
test: test-unit ## Run the tests
unit: test-unit ## Run the tests
TEST_PKGS:=$(shell go list ./...)
test-unit: ## Run the unit tests
$(Q)go test -coverprofile=coverage.out -count=1 ${SPECIFIC_UNIT_TEST} ${SPECIFIC_SKIP_UNIT_TEST} ${TEST_PKGS}
verify: manifests generate format tidy
git diff --exit-code
################
# Hack / Tools #
################
GO_INSTALL_OPTS ?= "-mod=mod"
# Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - no v1.28, v1.29, etc.)
# The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
# and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
# will map to a KIND_NODE_VERSION of 1.28.0
KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.0/')
KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION)
.PHONY: kind-cluster
kind-cluster: $(KIND) ## Create a kind cluster
$(KIND) create cluster --name olmv0 --image $(KIND_CLUSTER_IMAGE)
$(KIND) export kubeconfig --name olmv0