Skip to content

Commit a65e877

Browse files
committed
Initial commit
1 parent 584696e commit a65e877

File tree

23,565 files changed

+7426227
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

23,565 files changed

+7426227
-0
lines changed

Makefile

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
# kernel-style V=1 build verbosity
2+
ifeq ("$(origin V)", "command line")
3+
BUILD_VERBOSE = $(V)
4+
endif
5+
6+
SHELL := /bin/bash
7+
PKG = github.com/openshift/operator-framework-olm
8+
PKGS = $(shell $(GO) list ./... | grep -v /vendor/)
9+
export GO111MODULE=on
10+
GO := GOFLAGS="-mod=mod" go
11+
REGISTRY_CMDS := $(addprefix bin/, $(shell ls ./cmd | grep -v "^\(olm\|opm\|operator-verify\)"))
12+
CMDS := $(shell $(GO) list ./cmd/olm/... ./cmd/opm/...)
13+
TCMDS := $(shell $(GO) list ./test/e2e/...)
14+
15+
SPECIFIC_UNIT_TEST := $(if $(TEST),-run $(TEST),)
16+
17+
# ART builds are performed in dist-git, with content (but not commits) copied
18+
# from the source repo. Thus at build time if your code is inspecting the local
19+
# git repo it is getting unrelated commits and tags from the dist-git repo,
20+
# not the source repo.
21+
# For ART image builds, SOURCE_GIT_COMMIT, SOURCE_GIT_TAG, SOURCE_DATE_EPOCH
22+
# variables are inserted in Dockerfile to enable recovering the original git
23+
# metadata at build time.
24+
GIT_COMMIT := $(or $(SOURCE_GIT_COMMIT),$(shell git rev-parse --short HEAD))
25+
26+
OLM_VERSION := $(or $(SOURCE_GIT_TAG),$(shell git describe --always --tags HEAD))
27+
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
28+
TAGS := -tags "json1"
29+
registry_api := "./staging/operator-registry/pkg/api"
30+
# -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
31+
ifeq ($(shell $(GO) env GOARCH),s390x)
32+
TEST_RACE :=
33+
else
34+
TEST_RACE := -race
35+
endif
36+
KUBEBUILDER_ASSETS := $(or $(or $(KUBEBUILDER_ASSETS),$(dir $(shell command -v kubebuilder))),/usr/local/kubebuilder/bin)
37+
export KUBEBUILDER_ASSETS
38+
39+
# Undefine GOFLAGS environment variable.
40+
ifdef GOFLAGS
41+
$(warning Undefining GOFLAGS set in CI)
42+
undefine GOFLAGS
43+
endif
44+
45+
.PHONY: all
46+
all: clean test build
47+
48+
help: ## Display this help.
49+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
50+
51+
bin/operator-verify:
52+
$(GO) build \
53+
-gcflags "all=-trimpath=${GOPATH}" \
54+
-asmflags "all=-trimpath=${GOPATH}" \
55+
-ldflags " \
56+
-X '${PKG}/version.GitVersion=${OLM_VERSION}' \
57+
-X '${PKG}/version.GitCommit=${GIT_COMMIT}' \
58+
" \
59+
-o "bin/operator-verify" \
60+
"$(PKG)/cmd/operator-verify"
61+
62+
$(REGISTRY_CMDS):
63+
$(arch_flags) $(GO) build $(extra_flags) $(TAGS) -o bin/$(shell basename $@) ./cmd/$(notdir $@)
64+
65+
$(CMDS): version_flags=-ldflags "-X '$(PKG)/pkg/version.GitCommit=$(GIT_COMMIT)' -X '$(PKG)/pkg/version.OLMVersion=$(OLM_VERSION)' -X '$(PKG)/pkg/version.buildDate=$(BUILD_DATE)'"
66+
$(CMDS):
67+
$(arch_flags) $(GO) build $(version_flags) $(extra_flags) $(TAGS) -o bin/$(shell basename $@) $@
68+
69+
$(TCMDS):
70+
$(GO) test -c $(BUILD_TAGS) -o bin/$(shell basename $@) $@
71+
72+
73+
.PHONY: build ## Build binaries
74+
build: clean $(REGISTRY_CMDS) $(CMDS) bin/operator-verify
75+
76+
.PHONY: cross
77+
cross: version_flags=-ldflags "-X '$(PKG)/pkg/version.GitCommit=$(GIT_COMMIT)' -X '$(PKG)/pkg/version.OLMVersion=$(OLM_VERSION)' -X '$(PKG)/pkg/version.buildDate=$(BUILD_DATE)'"
78+
cross: ## Cross-compile opm binary
79+
ifeq ($(shell $(GO) env GOARCH),amd64)
80+
GOOS=darwin CC=o64-clang CXX=o64-clang++ CGO_ENABLED=1 $(GO) build $(version_flags) $(TAGS) -o "bin/darwin-amd64-opm" --ldflags "-extld=o64-clang" ./cmd/opm
81+
GOOS=windows CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 $(GO) build $(version_flags) $(TAGS) -o "bin/windows-amd64-opm" --ldflags "-extld=x86_64-w64-mingw32-gcc" ./cmd/opm
82+
endif
83+
84+
.PHONY: static
85+
static: extra_flags=-ldflags '-w -extldflags "-static"'
86+
static: build
87+
88+
.PHONY: registry-image
89+
registry-image:
90+
docker build -f operator-registry.Dockerfile .
91+
92+
# Code management.
93+
.PHONY: format tidy clean vendor generate
94+
95+
format: ## Format the source code
96+
$(GO) fmt $(PKGS)
97+
98+
tidy: ## Update dependencies
99+
$(GO) mod tidy -v
100+
101+
vendor: tidy ## Update vendor directory
102+
$(GO) mod vendor
103+
104+
clean: ## Clean up the build artifacts
105+
@rm -rf build
106+
@rm -rf ./bin
107+
@rm -rf cover.out
108+
@rm -rf bin
109+
@rm -rf test/e2e/resources
110+
@rm -rf test/e2e/test-resources
111+
@rm -rf test/e2e/log
112+
@rm -rf e2e.namespace
113+
114+
manifests: ## Generate and copy CRD manifests
115+
./scripts/olm/generate_manifests.sh
116+
117+
.PHONY: generate-fakes
118+
generate-fakes: ## Generate deepcopy, conversion, clients, listers, and informers
119+
./scripts/olm/generate_fakes.sh
120+
121+
122+
codegen: ## Generate clients, listers, and informers
123+
./scripts/olm/update_codegen.sh
124+
125+
mockgen: ## Generate mock types.
126+
./scripts/olm/update_mockgen.sh
127+
128+
gen-all: manifests generate-fakes gen-grpc codegen mockgen ## Generate everything.
129+
130+
.PHONY: gen-grpc
131+
gen-grpc: ## Generate GRPC APIs for registry
132+
protoc -I $(registry_api) --go_out=$(registry_api) $(registry_api)/*.proto
133+
protoc -I $(registry_api) --go-grpc_out=$(registry_api) $(registry_api)/*.proto
134+
protoc -I $(registry_api)/grpc_health_v1 --go_out=$(registry_api)/grpc_health_v1 $(registry_api)/grpc_health_v1/*.proto
135+
protoc -I $(registry_api)/grpc_health_v1 --go-grpc_out=$(registry_api)/grpc_health_v1 $(registry_api)/grpc_health_v1/*.proto
136+
137+
.PHONY: container-gen-grpc
138+
container-gen-grpc:
139+
docker build -t operator-registry:codegen -f codegen.Dockerfile .
140+
docker run --name temp-codegen operator-registry:codegen /bin/true
141+
docker cp temp-codegen:/codegen/pkg/api/. $(registry_api)
142+
docker rm temp-codegen
143+
144+
diff:
145+
git diff --exit-code
146+
147+
verify-codegen: codegen diff
148+
verify-mockgen: mockgen diff
149+
verify-manifests: manifests diff
150+
verify: verify-codegen verify-mockgen verify-manifests
151+
152+
# Static tests.
153+
.PHONY: test unit e2e
154+
155+
test: unit cover.out ## Run unit tests
156+
157+
unit: kubebuilder
158+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) $(GO) test $(SPECIFIC_UNIT_TEST) $(TAGS) $(TEST_RACE) -count=1 -v ./...
159+
160+
cover.out:
161+
$(GO) test $(TAGS) -v $(TEST_RACE) -coverprofile=cover.out -covermode=atomic -coverpkg ./...
162+
163+
# Ensure kubebuilder is installed before continuing
164+
KUBEBUILDER_ASSETS_ERR := not detected in $(KUBEBUILDER_ASSETS), to override the assets path set the KUBEBUILDER_ASSETS environment variable, for install instructions see https://book.kubebuilder.io/quick-start.html
165+
kubebuilder:
166+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kubebuilder))
167+
$(error kubebuilder $(KUBEBUILDER_ASSETS_ERR))
168+
endif
169+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/etcd))
170+
$(error etcd $(KUBEBUILDER_ASSETS_ERR))
171+
endif
172+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kube-apiserver))
173+
$(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
174+
endif
175+
176+
.PHONY: e2e
177+
178+
e2e:
179+
$(GO) test -v -failfast -timeout 150m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager -dummyImage=bitnami/nginx:latest -ginkgo.flakeAttempts=3
180+
181+
e2e-operator-metrics:
182+
$(GO) test -v -timeout 70m ./test/rh-operators/...
183+
184+
185+
##########################
186+
# OLM - Build and Test #
187+
##########################
188+
189+
IMAGE_REPO := quay.io/operator-framework/olm
190+
IMAGE_TAG ?= "dev"
191+
YQ_INTERNAL := $(GO) run ./vendor/github.com/mikefarah/yq/v3/
192+
193+
.PHONY: build test run clean vendor \
194+
vendor-update coverage coverage-html e2e \
195+
kubebuilder .FORCE
196+
197+
build-linux: arch_flags=GOOS=linux GOARCH=386
198+
build-linux: clean $(CMDS)
199+
200+
build-wait: clean bin/wait
201+
202+
bin/wait:
203+
GOOS=linux GOARCH=386 $(GO) build -o $@ $(PKG)/test/e2e/wait
204+
205+
build-util-linux: arch_flags=GOOS=linux GOARCH=386
206+
build-util-linux: build-util
207+
208+
build-util: bin/cpb
209+
210+
bin/cpb:
211+
CGO_ENABLED=0 $(arch_flags) $(GO) build -ldflags '-extldflags "-static"' -o $@ ./util/cpb
212+
213+
214+
test-bare: BUILD_TAGS=-tags=bare
215+
test-bare: clean $(TCMDS)
216+
217+
test-bin: clean $(TCMDS)
218+
219+
################################
220+
# OLM - Install/Uninstall/Run #
221+
################################
222+
223+
LOCAL_NAMESPACE := "olm"
224+
225+
.PHONY: run-console-local
226+
run-console-local: ## Run Openshift console locally
227+
@echo Running script to run the OLM console locally:
228+
. ./scripts/olm/run_console_local.sh
229+
230+
.PHONY: run-local ## Build and run OLM locally
231+
run-local: build-linux build-wait build-util-linux build-local deploy-local
232+
233+
build-local:
234+
rm -rf build
235+
. ./scripts/olm/build_local.sh
236+
237+
deploy-local:
238+
mkdir -p build/resources
239+
. ./scripts/olm/package_release.sh 1.0.0 build/resources doc/install/local-values.yaml
240+
. ./scripts/olm/install_local.sh $(LOCAL_NAMESPACE) build/resources
241+
rm -rf build
242+
243+
# e2e test exculding the rh-operators directory which tests rh-operators and their metric cardinality.
244+
clean-e2e:
245+
kubectl delete crds --all
246+
kubectl delete apiservices.apiregistration.k8s.io v1.packages.operators.coreos.com || true
247+
kubectl delete -f test/e2e/resources/0000_50_olm_00-namespace.yaml
248+
249+
e2e-local: build-linux build-wait build-util-linux build-local ## Run e2e tests locally
250+
. ./scripts/olm/run_e2e_local.sh $(TEST)
251+
252+
e2e-local-docker:
253+
. ./scripts/olm/build_local.sh
254+
. ./scripts/olm/run_e2e_docker.sh $(TEST)
255+
256+
# useful if running e2e directly with `go test -tags=bare`
257+
e2e.namespace:
258+
@printf "e2e-tests-$(shell date +%s)-$$RANDOM" > e2e.namespace
259+
260+
setup-bare: clean e2e.namespace
261+
. ./scripts/olm/build_bare.sh
262+
. ./scripts/olm/package_release.sh 1.0.0 test/e2e/resources test/e2e/e2e-bare-values.yaml
263+
. ./scripts/olm/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources
264+
265+
e2e-bare: setup-bare
266+
. ./scripts/olm/run_e2e_bare.sh $(TEST)
267+

base.Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dockerfile to bootstrap build and test in openshift-ci
2+
3+
FROM openshift/origin-release:golang-1.13
4+
5+
# Install test dependencies
6+
RUN yum install -y skopeo && \
7+
export OS=$(go env GOOS) && \
8+
export ARCH=$(go env GOARCH) && \
9+
curl -L "https://go.kubebuilder.io/dl/2.3.1/${OS}/${ARCH}" | tar -xz -C /tmp/ && \
10+
mv /tmp/kubebuilder_2.3.1_${OS}_${ARCH}/ /usr/local/kubebuilder && \
11+
export PATH=$PATH:/usr/local/kubebuilder/bin && \
12+
echo "Kubebuilder installation complete!"

boilerplate.go.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Copyright Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/

0 commit comments

Comments
 (0)