forked from IBM/ibm-namespace-scope-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (165 loc) · 7.93 KB
/
Makefile
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Copyright 2021 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.DEFAULT_GOAL:=help
# Dependence tools
KUBECTL ?= $(shell which kubectl)
OPERATOR_SDK ?= $(shell which operator-sdk)
CONTROLLER_GEN ?= $(shell which controller-gen)
KUSTOMIZE ?= $(shell which kustomize)
# Specify whether this repo is build locally or not, default values is '1';
# If set to 1, then you need to also set 'DOCKER_USERNAME' and 'DOCKER_PASSWORD'
# environment variables before build the repo.
BUILD_LOCALLY ?= 1
VCS_URL ?= https://github.com/IBM/ibm-namespace-scope-operator
VCS_REF ?= $(shell git rev-parse HEAD)
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
RELEASE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
LATEST_VERSION ?= latest
LOCAL_OS := $(shell uname)
ifeq ($(LOCAL_OS),Linux)
TARGET_OS ?= linux
XARGS_FLAGS="-r"
STRIP_FLAGS=
else ifeq ($(LOCAL_OS),Darwin)
TARGET_OS ?= darwin
XARGS_FLAGS=
STRIP_FLAGS="-x"
else
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
endif
ARCH := $(shell uname -m)
LOCAL_ARCH := "amd64"
ifeq ($(ARCH),x86_64)
LOCAL_ARCH="amd64"
else ifeq ($(ARCH),ppc64le)
LOCAL_ARCH="ppc64le"
else ifeq ($(ARCH),s390x)
LOCAL_ARCH="s390x"
else
$(error "This system's ARCH $(ARCH) isn't recognized/supported")
endif
# Default image repo
QUAY_REGISTRY ?= quay.io/opencloudio
ifeq ($(BUILD_LOCALLY),0)
ARTIFACTORYA_REGISTRY ?= "hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com/ibmcom"
else
ARTIFACTORYA_REGISTRY ?= "hyc-cloud-private-scratch-docker-local.artifactory.swg-devops.com/ibmcom"
endif
# Current Operator image name
OPERATOR_IMAGE_NAME ?= ibm-namespace-scope-operator
# Current Operator version
OPERATOR_VERSION ?= 1.1.0
# Options for 'bundle-build'
CHANNELS ?= beta
DEFAULT_CHANNEL ?= beta
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
ifeq ($(BUILD_LOCALLY),0)
export CONFIG_DOCKER_TARGET = config-docker
export CONFIG_DOCKER_TARGET_QUAY = config-docker-quay
endif
include common/Makefile.common.mk
##@ Development
code-dev: ## Run the default dev commands which are the go tidy, fmt, vet then execute the $ make code-gen
@echo Running the common required commands for developments purposes
- make generate
- make manifests
- make code-tidy
- make code-fmt
- make code-vet
- make lint-all
check: ## Check code lint error
make lint-all
build: ## Build manager binary
go build -o bin/manager main.go
run: generate code-fmt code-vet manifests check ## Run against the configured Kubernetes cluster in ~/.kube/config
OPERATOR_NAMESPACE=ibm-common-services go run ./main.go
install: manifests ## Install CRDs into a cluster
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests ## Uninstall CRDs from a cluster
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
cd config/manager && $(KUSTOMIZE) edit set image ibm-namespace-scope-operator=$(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
cd config/manager && $(KUSTOMIZE) edit set image ibm-namespace-scope-operator=$(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)
$(KUSTOMIZE) build config/default | kubectl delete -f -
##@ Generate code and manifests
manifests: ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=ibm-namespace-scope-operator webhook paths="./..." output:crd:artifacts:config=config/crd/bases
generate: ## Generate code e.g. API etc.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate-csv-manifests: ## Generate CSV manifests
$(OPERATOR_SDK) generate kustomize manifests
bundle: generate manifests ## Generate bundle and restricted bundle manifests
# Generate restricted bundle manifests
@yq w -i PROJECT 'projectName' ibm-namespace-scope-operator-restricted
@yq w -i config/rbac/role.yaml 'kind' Role
@yq w -i config/rbac/role_binding.yaml 'kind' RoleBinding
@yq w -i config/rbac/role_binding.yaml 'roleRef.kind' Role
- $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
-q --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS) \
--output-dir bundle-restricted
@rm -f ./bundle-restricted/manifests/ibm-namespace-scope-operator.clusterserviceversion.yaml
- $(OPERATOR_SDK) bundle validate ./bundle-restricted
@yq w -i PROJECT 'projectName' ibm-namespace-scope-operator
@yq w -i config/rbac/role.yaml 'kind' ClusterRole
@yq w -i config/rbac/role_binding.yaml 'kind' ClusterRoleBinding
@yq w -i config/rbac/role_binding.yaml 'roleRef.kind' ClusterRole
# Generate bundle manifests
- $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
-q --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS)
@rm -f ./bundle/manifests/ibm-namespace-scope-operator-restricted.clusterserviceversion.yaml
- $(OPERATOR_SDK) bundle validate ./bundle
##@ Test
test: ## Run unit test on prow
@echo good
e2e-test: ## Run e2e test
@echo "Running e2e tests for the controllers."
@USE_EXISTING_CLUSTER=true \
OPERATOR_NAME=ibm-namespace-scope-operator \
OPERATOR_NAMESPACE=ibm-common-services \
go test ./controllers/... -coverprofile cover.out
coverage: ## Run code coverage test
@common/scripts/codecov.sh ${BUILD_LOCALLY} "controllers"
##@ Build
build-operator-image: ## Build the operator image.
@echo "Building the $(OPERATOR_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
@docker build -t $(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) --build-arg VCS_URL=$(VCS_URL) \
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .
##@ Release
build-push-image: $(CONFIG_DOCKER_TARGET) $(CONFIG_DOCKER_TARGET_QUAY) build-operator-image ## Build and push the operator images.
@echo "Pushing the $(OPERATOR_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
@docker tag $(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) $(ARTIFACTORYA_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
@docker tag $(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
@docker push $(ARTIFACTORYA_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
@docker push $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
multiarch-image: $(CONFIG_DOCKER_TARGET) $(CONFIG_DOCKER_TARGET_QUAY) ## Generate multiarch images for operator image.
@MAX_PULLING_RETRY=20 RETRY_INTERVAL=30 common/scripts/multiarch_image.sh $(ARTIFACTORYA_REGISTRY) $(OPERATOR_IMAGE_NAME) $(VERSION) $(RELEASE_VERSION)
@MAX_PULLING_RETRY=20 RETRY_INTERVAL=30 common/scripts/multiarch_image.sh $(QUAY_REGISTRY) $(OPERATOR_IMAGE_NAME) $(VERSION) $(LATEST_VERSION)
##@ Help
help: ## Display this help
@echo "Usage:\n make \033[36m<target>\033[0m"
@awk 'BEGIN {FS = ":.*##"}; \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)