Skip to content

Commit fd1d79b

Browse files
committed
Clean up local workflow
1 parent 78e7c2f commit fd1d79b

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

CONTRIBUTING.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ We gratefully welcome improvements to documentation as well as to code.
88

99
## Getting Started
1010

11+
### Pre-requisites
12+
13+
* [Go](https://golang.org/doc/install).
14+
* Docker version 23.0.0 or greater.
15+
16+
### Local development cheat sheet
17+
18+
* `make test` to run unit tests
19+
* `make lint` to run linters
20+
* `make fmt` to format Go code
21+
* `make vet` to run `go vet`
22+
* `make generate` to generate code and manifests based on Go struct definitions for CRDs.
23+
24+
`make precommit` includes all of the above.
25+
1126
### Workflow
1227

1328
It is recommended to follow the ["GitHub Workflow"](https://guides.github.com/introduction/flow/). When using [GitHub's CLI](https://github.com/cli/cli), here's how it typically looks like:
@@ -36,13 +51,6 @@ The following `make` target is run on CI to verify the project structure:
3651
make ensure-generate-is-noop
3752
```
3853

39-
### Pre-requisites
40-
* Install [Go](https://golang.org/doc/install).
41-
* Install [Kustomize](https://kubectl.docs.kubernetes.io/installation/kustomize/).
42-
* Install [Operator SDK](https://sdk.operatorframework.io/docs/installation/).
43-
* Have a Kubernetes cluster ready for development. We recommend `minikube` or `kind`.
44-
* Docker version 23.0.0 or greater.
45-
4654
### Adding new components - webhook, API
4755

4856
The repository structure MUST be compliant with `operator-sdk` scaffolding, which uses `kubebuilder` behind the scenes. This is to ensure a valid bundle generation and it makes it easy to maintain the project and add new components.
@@ -52,6 +60,7 @@ Refer to the [Operator SDK documentation](https://sdk.operatorframework.io/docs/
5260
### Local run
5361

5462
Build the manifests, install the CRD and run the operator as a local process:
63+
5564
```bash
5665
make install run
5766
```
@@ -98,13 +107,6 @@ kubectl create secret docker-registry regcred --docker-server=<registry> --docke
98107

99108
## Testing
100109

101-
With an existing cluster (such as `minikube`), run:
102-
```bash
103-
USE_EXISTING_CLUSTER=true make test
104-
```
105-
106-
Tests can also be run without an existing cluster. For that, install [`kubebuilder`](https://book.kubebuilder.io/quick-start.html#installation). In this case, the tests will bootstrap `etcd` and `kubernetes-api-server` for the tests. Run against an existing cluster whenever possible, though.
107-
108110
### Unit tests
109111

110112
Some unit tests use [envtest](https://book.kubebuilder.io/reference/envtest.html) which requires Kubernetes binaries (e.g. `api-server`, `etcd` and `kubectl`) to be present on the host filesystem. Makefile takes care of installing all dependent binaries, however running the tests from IDE or via `go test` might not work out-of-the-box. The `envtest` uses env variable `KUBEBUILDER_ASSETS` that points to a directory with these binaries. To make the test work in IDE or `go test` the environment variable has to be correctly set.
@@ -118,20 +120,20 @@ KUBEBUILDER_ASSETS=$(./bin/setup-envtest use -p path 1.23) go test ./pkg...
118120

119121
### End to end tests
120122

121-
To run the end-to-end tests, you'll need [`kind`](https://kind.sigs.k8s.io) and [`chainsaw`](https://kyverno.github.io/chainsaw). Refer to their documentation for installation instructions.
123+
To run the end-to-end tests, you'll need [`kind`](https://kind.sigs.k8s.io) and [`chainsaw`](https://kyverno.github.io/chainsaw). They will be installed automatically in the project's local `bin/` directory.
122124

123-
Once they are installed, the tests can be executed with `make prepare-e2e`, which will build an image to use with the tests, followed by `make e2e`. Each call to the `e2e` target will set up a fresh `kind` cluster, making it safe to be executed multiple times with a single `prepare-e2e` step.
125+
Once they are installed, the tests can be executed with `make prepare-e2e`, which will build an image to use with the tests, followed by `make e2e`. Keep in mind that you need to call `make prepare-e2e` again after you make changes to operator code or manifests.
124126

125127
The tests are located under `tests/e2e` and are written to be used with `chainsaw`. Refer to their documentation to understand how tests are written.
126128

127129
To revert the changes made by the `make prepare-e2e` run `make reset`.
128130

129131
### OpenShift End to End tests
130-
To run the end-to-end tests written for OpenShift, you'll need a OpenShift cluster.
132+
To run the end-to-end tests written for OpenShift, you'll need a OpenShift cluster.
131133

132134
To install the OpenTelemetry operator, please follow the instructions in [Operator Lifecycle Manager (OLM)](https://github.com/open-telemetry/opentelemetry-operator/blob/main/CONTRIBUTING.md#operator-lifecycle-manager-olm)
133135

134-
Once the operator is installed, the tests can be executed using `make e2e-openshift`, which will call to the `e2e-openshift` target. Note that `kind` is disabled for the TestSuite as the requirement is to use an OpenShift cluster for these test cases.
136+
Once the operator is installed, the tests can be executed using `make e2e-openshift`, which will call to the `e2e-openshift` target. Note that `kind` is disabled for the TestSuite as the requirement is to use an OpenShift cluster for these test cases.
135137

136138
The tests are located under `tests/e2e-openshift` and are written to be used with `chainsaw`.
137139

Makefile

+17-10
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,24 @@ ensure-generate-is-noop: set-image-controller generate bundle
9494
@git diff -s --exit-code docs/api.md || (echo "Build failed: the api.md file has been changed but the generated api.md file isn't up to date. Run 'make api-docs' and update your PR." && git diff && exit 1)
9595

9696
.PHONY: all
97-
all: manager
98-
.PHONY: ci
99-
ci: test
97+
all: manager targetallocator operator-opamp-bridge
10098

101-
# Run tests
102-
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
103-
.PHONY: test
104-
test: generate fmt vet ensure-generate-is-noop envtest
105-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
99+
# No lint here, as CI runs it separately
100+
.PHONY: ci
101+
ci: generate fmt vet test ensure-generate-is-noop
106102

107103
# Build manager binary
108104
.PHONY: manager
109-
manager: generate fmt vet
105+
manager:
110106
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/manager_${ARCH} -ldflags "${COMMON_LDFLAGS} ${OPERATOR_LDFLAGS}" main.go
111107

112108
# Build target allocator binary
109+
.PHONY: targetallocator
113110
targetallocator:
114111
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/otel-allocator/bin/targetallocator_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/otel-allocator
115112

116113
# Build opamp bridge binary
114+
.PHONY: operator-opamp-bridge
117115
operator-opamp-bridge:
118116
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/operator-opamp-bridge/bin/opampbridge_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/operator-opamp-bridge
119117

@@ -176,6 +174,15 @@ release-artifacts: set-image-controller
176174
manifests: controller-gen
177175
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
178176

177+
# Run tests
178+
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
179+
.PHONY: test
180+
test: envtest
181+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
182+
183+
.PHONY: precommit
184+
precommit: generate fmt vet lint test ensure-generate-is-noop reset
185+
179186
# Run go fmt against code
180187
.PHONY: fmt
181188
fmt:
@@ -241,7 +248,7 @@ e2e-prometheuscr: chainsaw
241248
e2e-targetallocator: chainsaw
242249
$(CHAINSAW) test --test-dir ./tests/e2e-targetallocator
243250

244-
# end-to-end-test for Annotations/Labels Filters
251+
# end-to-end-test for Annotations/Labels Filters
245252
.PHONY: e2e-metadata-filters
246253
e2e-metadata-filters: chainsaw
247254
$(CHAINSAW) test --test-dir ./tests/e2e-metadata-filters

0 commit comments

Comments
 (0)