Skip to content

Commit 552f129

Browse files
authored
Merge branch 'operator-framework:main' into jmprusi/upgrade-edges
2 parents a9c0905 + 949c06a commit 552f129

25 files changed

+722
-48
lines changed

.github/workflows/e2e.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: e2e
33
on:
44
workflow_dispatch:
55
pull_request:
6+
merge_group:
67
push:
78
branches:
89
- main
@@ -22,4 +23,16 @@ jobs:
2223

2324
- name: Run e2e tests
2425
run: |
25-
make e2e
26+
# By default make stops building on first non-zero exit code which
27+
# in case of E2E tests will mean that code coverage will only be
28+
# collected on successful runs. We want to collect coverage even
29+
# after failing tests.
30+
# With -k flag make will continue the build, but will return non-zero
31+
# exit code in case of any errors.
32+
make -k e2e
33+
34+
- uses: codecov/codecov-action@v3
35+
with:
36+
files: e2e-cover.out
37+
flags: e2e
38+
functionalities: fixes

.github/workflows/go-apidiff.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: go-apidiff
2-
on: [ pull_request ]
2+
on:
3+
pull_request:
4+
merge_group:
35
jobs:
46
go-apidiff:
57
runs-on: ubuntu-latest

.github/workflows/pages.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy Documentation site
2+
on:
3+
push:
4+
branches:
5+
- main
6+
permissions:
7+
contents: write
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.x
16+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
17+
- uses: actions/cache@v3
18+
with:
19+
key: mkdocs-material-${{ env.cache_id }}
20+
path: .cache
21+
restore-keys: |
22+
mkdocs-material-
23+
- run: pip install mkdocs-material
24+
- run: mkdocs gh-deploy --force

.github/workflows/release.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
pull_request:
1111
branches:
1212
- main
13+
merge_group:
1314

1415
jobs:
1516
goreleaser:

.github/workflows/sanity.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: sanity
33
on:
44
workflow_dispatch:
55
pull_request:
6+
merge_group:
67
push:
78
branches:
89
- main

.github/workflows/unit-test.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: unit-test
33
on:
44
workflow_dispatch:
55
pull_request:
6+
merge_group:
67
push:
78
branches:
89
- main
@@ -25,5 +26,5 @@ jobs:
2526
- uses: codecov/codecov-action@v3
2627
with:
2728
files: cover.out
28-
fail_ci_if_error: true
29+
flags: unit
2930
functionalities: fixes

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Dockerfile.cross
1414
# Test binary, build with `go test -c`
1515
*.test
1616

17-
# Output of the go coverage tool, specifically when used with LiteIDE
17+
# Output of the go coverage tools
1818
*.out
19+
coverage
1920

2021
# Release output
2122
dist/**
@@ -34,3 +35,7 @@ install.sh
3435
\#*\#
3536
.\#*
3637

38+
# documentation website asset folder
39+
docs/_site
40+
41+
.tiltbuild/

Makefile

+27-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ KIND_CLUSTER_NAME ?= operator-controller
2424

2525
CONTAINER_RUNTIME ?= docker
2626

27+
KUSTOMIZE_BUILD_DIR ?= config/default
28+
2729
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2830
ifeq (,$(shell go env GOBIN))
2931
GOBIN=$(shell go env GOPATH)/bin
@@ -39,8 +41,7 @@ SHELL = /usr/bin/env bash -o pipefail
3941
# Disable -j flag for make
4042
.NOTPARALLEL:
4143

42-
.PHONY: all
43-
all: build
44+
.DEFAULT_GOAL := build
4445

4546
##@ General
4647

@@ -89,32 +90,45 @@ fmt: ## Run go fmt against code.
8990
vet: ## Run go vet against code.
9091
go vet ./...
9192

92-
.PHONY: test test-e2e e2e kind-load kind-cluster kind-cluster-cleanup
93+
.PHONY: test
9394
test: manifests generate fmt vet test-unit e2e ## Run all tests.
9495

96+
.PHONY: test-e2e
9597
FOCUS := $(if $(TEST),-v -focus "$(TEST)")
9698
E2E_FLAGS ?= ""
9799
test-e2e: $(GINKGO) ## Run the e2e tests
98100
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e
99101

102+
.PHONY: test-unit
100103
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
101104
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
102105
test-unit: $(SETUP_ENVTEST) ## Run the unit tests
103106
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
104107

108+
.PHONY: e2e
105109
e2e: KIND_CLUSTER_NAME=operator-controller-e2e
106-
e2e: run kind-load-test-artifacts test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster
110+
e2e: KUSTOMIZE_BUILD_DIR=config/e2e
111+
e2e: GO_BUILD_FLAGS=-cover
112+
e2e: run kind-load-test-artifacts test-e2e e2e-coverage kind-cluster-cleanup ## Run e2e test suite on local kind cluster
113+
114+
.PHONY: e2e-coverage
115+
e2e-coverage:
116+
COVERAGE_OUTPUT=./e2e-cover.out ./hack/e2e-coverage.sh
107117

118+
.PHONY: kind-load
108119
kind-load: $(KIND) ## Loads the currently constructed image onto the cluster
109120
$(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)
110121

111-
kind-cluster: $(KIND) kind-cluster-cleanup ## Standup a kind cluster
122+
.PHONY: kind-cluster
123+
kind-cluster: $(KIND) ## Standup a kind cluster
112124
$(KIND) create cluster --name ${KIND_CLUSTER_NAME}
113125
$(KIND) export kubeconfig --name ${KIND_CLUSTER_NAME}
114126

127+
.PHONY: kind-cluster-cleanup
115128
kind-cluster-cleanup: $(KIND) ## Delete the kind cluster
116129
$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}
117130

131+
.PHONY: kind-load-test-artifacts
118132
kind-load-test-artifacts: $(KIND) ## Load the e2e testdata container images into a kind cluster
119133
$(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/registry-v1/prometheus-operator.v0.37.0 -t localhost/testdata/bundles/registry-v1/prometheus-operator:v0.37.0
120134
$(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/registry-v1/prometheus-operator.v0.47.0 -t localhost/testdata/bundles/registry-v1/prometheus-operator:v0.47.0
@@ -135,8 +149,9 @@ export GO_BUILD_ASMFLAGS ?= all=-trimpath=${PWD}
135149
export GO_BUILD_LDFLAGS ?= -s -w -X $(shell go list -m)/version.Version=$(VERSION)
136150
export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD}
137151
export GO_BUILD_TAGS ?= upstream
152+
export GO_BUILD_FLAGS ?=
138153

139-
BUILDCMD = go build -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager
154+
BUILDCMD = go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager
140155

141156
.PHONY: build-deps
142157
build-deps: manifests generate fmt vet
@@ -156,10 +171,6 @@ go-build-linux:
156171
.PHONY: run
157172
run: docker-build kind-cluster kind-load install ## Build the operator-controller then deploy it into a new kind cluster.
158173

159-
.PHONY: wait
160-
wait:
161-
kubectl wait --for=condition=Available --namespace=$(OPERATOR_CONTROLLER_NAMESPACE) deployment/operator-controller-controller-manager --timeout=$(WAIT_TIMEOUT)
162-
163174
.PHONY: docker-build
164175
docker-build: build-linux ## Build docker image for operator-controller with GOOS=linux and local GOARCH.
165176
docker build -t ${IMG} -f Dockerfile ./bin/linux
@@ -172,12 +183,14 @@ docker-build: build-linux ## Build docker image for operator-controller with GOO
172183
export ENABLE_RELEASE_PIPELINE ?= false
173184
export GORELEASER_ARGS ?= --snapshot --clean
174185

186+
.PHONY: release
175187
release: $(GORELEASER) ## Runs goreleaser for the operator-controller. By default, this will run only as a snapshot and will not publish any artifacts unless it is run with different arguments. To override the arguments, run with "GORELEASER_ARGS=...". When run as a github action from a tag, this target will publish a full release.
176188
$(GORELEASER) $(GORELEASER_ARGS)
177189

190+
.PHONY: quickstart
178191
quickstart: export MANIFEST="https://github.com/operator-framework/operator-controller/releases/download/$(VERSION)/operator-controller.yaml"
179192
quickstart: $(KUSTOMIZE) generate ## Generate the installation release manifests and scripts
180-
$(KUSTOMIZE) build config/default | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml
193+
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml
181194
envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh > install.sh
182195

183196
##@ Deployment
@@ -189,7 +202,7 @@ endif
189202
.PHONY: install
190203
install: export MANIFEST="./operator-controller.yaml"
191204
install: manifests $(KUSTOMIZE) generate ## Install CRDs into the K8s cluster specified in ~/.kube/config.
192-
$(KUSTOMIZE) build config/default > operator-controller.yaml
205+
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) > operator-controller.yaml
193206
envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh | bash -s
194207

195208
.PHONY: uninstall
@@ -199,8 +212,8 @@ uninstall: manifests $(KUSTOMIZE) ## Uninstall CRDs from the K8s cluster specifi
199212
.PHONY: deploy
200213
deploy: manifests $(KUSTOMIZE) ## Deploy controller to the K8s cluster specified in ~/.kube/config.
201214
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
202-
$(KUSTOMIZE) build config/default | kubectl apply -f -
215+
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | kubectl apply -f -
203216

204217
.PHONY: undeploy
205218
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
206-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
219+
$(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

Tiltfile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This loads a helper function that isn't part of core Tilt that simplifies restarting the process in the container
2+
# when files changes.
3+
load('ext://restart_process', 'docker_build_with_restart')
4+
5+
# Treat the main binary as a local resource, so we can automatically rebuild it when any of the deps change. This
6+
# builds it locally, targeting linux, so it can run in a linux container.
7+
local_resource(
8+
'manager_binary',
9+
cmd='''
10+
mkdir -p .tiltbuild/bin
11+
CGO_ENABLED=0 GOOS=linux go build -o .tiltbuild/bin/manager ./cmd/manager
12+
''',
13+
deps=['api', 'cmd/manager', 'internal', 'pkg', 'go.mod', 'go.sum']
14+
)
15+
16+
# Configure our image build. If the file in live_update.sync (.tiltbuild/bin/manager) changes, Tilt
17+
# copies it to the running container and restarts it.
18+
docker_build_with_restart(
19+
# This has to match an image in the k8s_yaml we call below, so Tilt knows to use this image for our Deployment,
20+
# instead of the actual image specified in the yaml.
21+
ref='quay.io/operator-framework/operator-controller:devel',
22+
# This is the `docker build` context, and because we're only copying in the binary we've already had Tilt build
23+
# locally, we set the context to the directory containing the binary.
24+
context='.tiltbuild/bin',
25+
# We use a slimmed-down Dockerfile that only has $binary in it.
26+
dockerfile_contents='''
27+
FROM gcr.io/distroless/static:debug
28+
EXPOSE 8080
29+
WORKDIR /
30+
COPY manager manager
31+
''',
32+
# The set of files Tilt should include in the build. In this case, it's just the binary we built above.
33+
only='manager',
34+
# If .tiltbuild/bin/manager changes, Tilt will copy it into the running container and restart the process.
35+
live_update=[
36+
sync('.tiltbuild/bin/manager', '/manager'),
37+
],
38+
# The command to run in the container.
39+
entrypoint="/manager",
40+
)
41+
42+
# Tell Tilt what to deploy by running kustomize and then doing some manipulation to make things work for Tilt.
43+
objects = decode_yaml_stream(kustomize('config/default'))
44+
for o in objects:
45+
# For Tilt's live_update functionality to work, we have to run the container as root. Remove any PSA labels to allow
46+
# this.
47+
if o['kind'] == 'Namespace' and 'labels' in o['metadata']:
48+
labels_to_delete = [label for label in o['metadata']['labels'] if label.startswith('pod-security.kubernetes.io')]
49+
for label in labels_to_delete:
50+
o['metadata']['labels'].pop(label)
51+
52+
if o['kind'] != 'Deployment':
53+
# We only need to modify Deployments, so we can skip this
54+
continue
55+
56+
# For Tilt's live_update functionality to work, we have to run the container as root. Otherwise, Tilt won't
57+
# be able to untar the updated binary in the container's file system (this is how live update
58+
# works). If there are any securityContexts, remove them.
59+
if "securityContext" in o['spec']['template']['spec']:
60+
o['spec']['template']['spec'].pop('securityContext')
61+
for c in o['spec']['template']['spec']['containers']:
62+
if "securityContext" in c:
63+
c.pop('securityContext')
64+
65+
# Now apply all the yaml
66+
k8s_yaml(encode_yaml_stream(objects))

config/e2e/kustomization.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace: operator-controller-system
2+
3+
resources:
4+
- ../default
5+
- manager_e2e_coverage_pvc.yaml
6+
- manager_e2e_coverage_copy_pod.yaml
7+
8+
patches:
9+
- path: manager_e2e_coverage_patch.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: e2e-coverage-copy-pod
5+
labels:
6+
app.kubernetes.io/name: e2e-coverage-copy-pod
7+
app.kubernetes.io/instance: controller-manager
8+
app.kubernetes.io/component: e2e-coverage
9+
app.kubernetes.io/created-by: operator-controller
10+
app.kubernetes.io/part-of: operator-controller
11+
app.kubernetes.io/managed-by: kustomize
12+
spec:
13+
restartPolicy: Never
14+
securityContext:
15+
runAsNonRoot: true
16+
runAsUser: 65532
17+
seccompProfile:
18+
type: RuntimeDefault
19+
containers:
20+
- name: tar
21+
image: busybox:1.36
22+
command: ["sleep", "infinity"]
23+
securityContext:
24+
allowPrivilegeEscalation: false
25+
capabilities:
26+
drop:
27+
- "ALL"
28+
volumeMounts:
29+
- name: e2e-coverage-volume
30+
mountPath: /e2e-coverage
31+
readOnly: true
32+
volumes:
33+
- name: e2e-coverage-volume
34+
persistentVolumeClaim:
35+
claimName: e2e-coverage
36+
readOnly: true
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: kube-rbac-proxy
11+
- name: manager
12+
env:
13+
- name: GOCOVERDIR
14+
value: /e2e-coverage
15+
volumeMounts:
16+
- name: e2e-coverage-volume
17+
mountPath: /e2e-coverage
18+
volumes:
19+
- name: e2e-coverage-volume
20+
persistentVolumeClaim:
21+
claimName: e2e-coverage
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: e2e-coverage
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 64Mi

0 commit comments

Comments
 (0)