...
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# enable multi-versions feature for CRDs
16CRD_OPTIONS ?= "crd"
17
18# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
19ifeq (,$(shell go env GOBIN))
20GOBIN=$(shell go env GOPATH)/bin
21else
22GOBIN=$(shell go env GOBIN)
23endif
24
25CONTROLLER_GEN := $(GOBIN)/controller-gen
26CONTROLLER_GEN_VERSION := 0.10.0
27
28.PHONY: all
29all: manager
30
31# Run tests
32.PHONY: test
33test: generate fmt vet manifests
34 go test -v ./pkg/... -coverprofile cover.out
35
36# Build manager binary
37.PHONY: manager
38manager: generate fmt vet
39 go build -o bin/manager cmd/manager/main.go
40
41# Generate manifests e.g. CRD, RBAC etc.
42.PHONY: manifests
43manifests: controller-gen
44 $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases
45 go run scripts/generate-image-configmap/main.go
46
47# Run go fmt against code
48.PHONY: fmt
49fmt:
50 go fmt ./...
51
52# Run go vet against code
53.PHONY: vet
54vet:
55 go vet ./...
56
57# Generate code
58.PHONY: generate
59generate: controller-gen
60 $(CONTROLLER_GEN) object paths="./..."
61
62# Download controller-gen binary if not found at the path specified by
63# CONTROLLER_GEN or if the binary found is not the version specified by
64# CONTROLLER_GEN_VERSION.
65.PHONY: controller-gen
66controller-gen:
67ifneq (Version: v$(CONTROLLER_GEN_VERSION), $(shell $(CONTROLLER_GEN) --version))
68 GOFLAGS='' go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_GEN_VERSION)
69endif
View as plain text