Skip to content

Commit 6305ef1

Browse files
swiatekmjaronoff97
andauthored
Clean up local workflow (open-telemetry#2774)
* bump to latest opamp (open-telemetry#2807) * Release 0.97.0 (open-telemetry#2806) * Release 0.97.0 * oops '' * Quiets some SUPER noisy logs (open-telemetry#2812) * Clean up local workflow --------- Co-authored-by: Jacob Aronoff <[email protected]>
1 parent 67117bc commit 6305ef1

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
@@ -93,27 +93,25 @@ ensure-generate-is-noop: set-image-controller generate bundle
9393
@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)
9494

9595
.PHONY: all
96-
all: manager
97-
.PHONY: ci
98-
ci: test
96+
all: manager targetallocator operator-opamp-bridge
9997

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

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

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

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

119117
# Run against the configured Kubernetes cluster in ~/.kube/config
@@ -175,6 +173,15 @@ release-artifacts: set-image-controller
175173
manifests: controller-gen
176174
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
177175

176+
# Run tests
177+
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
178+
.PHONY: test
179+
test: envtest
180+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
181+
182+
.PHONY: precommit
183+
precommit: generate fmt vet lint test ensure-generate-is-noop reset
184+
178185
# Run go fmt against code
179186
.PHONY: fmt
180187
fmt:

0 commit comments

Comments
 (0)