Skip to content

Commit e84193d

Browse files
author
Israel Blancas
authored
Create a must-gather for the operator (#3150)
* Add must-gather tool to the operator image #3149 Signed-off-by: Israel Blancas <[email protected]> * Add some missing features Signed-off-by: Israel Blancas <[email protected]> * Add operator logs Signed-off-by: Israel Blancas <[email protected]> * Add changelog Signed-off-by: Israel Blancas <[email protected]> * Fix lint Signed-off-by: Israel Blancas <[email protected]> * Add documentation Signed-off-by: Israel Blancas <[email protected]> * Clarify K8s compatibility Signed-off-by: Israel Blancas <[email protected]> * Some fixes Signed-off-by: Israel Blancas <[email protected]> * Publish image Signed-off-by: Israel Blancas <[email protected]> * Fix release notes Signed-off-by: Israel Blancas <[email protected]> * Small improvements Signed-off-by: Israel Blancas <[email protected]> * Add unit tests Signed-off-by: Israel Blancas <[email protected]> * Apply changes requested in code review Signed-off-by: Israel Blancas <[email protected]> * Fix typo Signed-off-by: Israel Blancas <[email protected]> --------- Signed-off-by: Israel Blancas <[email protected]> Signed-off-by: Israel Blancas <[email protected]>
1 parent 98433bd commit e84193d

13 files changed

+1315
-1
lines changed

.chloggen/3149-add-must-gather.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: auto-instrumentation, collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Add a must gather utility to help troubleshoot"
9+
10+
# One or more tracking issues related to the change
11+
issues: [3149]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
The new utility is available as part of a new container image.
18+
19+
To use the image in a running OpenShift cluster, you need to run the following command:
20+
21+
```sh
22+
oc adm must-gather --image=ghcr.io/open-telemetry/opentelemetry-operator/must-gather -- /usr/bin/must-gather --operator-namespace opentelemetry-operator-system
23+
```
24+
25+
See the [README](https://github.com/open-telemetry/opentelemetry-operator/blob/main/cmd/gather/README.md) for more details.
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: "Publish must-gather image"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
8+
workflow_dispatch:
9+
10+
env:
11+
PLATFORMS: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
12+
13+
jobs:
14+
publish:
15+
name: Publish must-gather container image
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: '~1.22.4'
23+
24+
- name: Unshallow
25+
run: git fetch --prune --unshallow
26+
27+
- name: Build the binary for each supported architecture
28+
run: |
29+
for platform in $(echo $PLATFORMS | tr "," "\n"); do
30+
arch=${platform#*/}
31+
echo "Building must-gather for $arch"
32+
make must-gather ARCH=$arch
33+
done
34+
35+
- name: Docker meta
36+
id: docker_meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: |
40+
ghcr.io/open-telemetry/opentelemetry-operator/must-gather
41+
tags: |
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
type=semver,pattern={{raw}}
45+
type=ref,event=branch
46+
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v3
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Cache Docker layers
54+
uses: actions/cache@v4
55+
with:
56+
path: /tmp/.buildx-cache
57+
key: ${{ runner.os }}-buildx-${{ github.sha }}
58+
restore-keys: |
59+
${{ runner.os }}-buildx-
60+
61+
- name: Log into Docker.io
62+
uses: docker/login-action@v3
63+
if: ${{ github.event_name == 'push' }}
64+
with:
65+
username: ${{ secrets.DOCKER_USERNAME }}
66+
password: ${{ secrets.DOCKER_PASSWORD }}
67+
68+
- name: Login to GitHub Package Registry
69+
uses: docker/login-action@v3
70+
if: ${{ github.event_name == 'push' }}
71+
with:
72+
registry: ghcr.io
73+
username: ${{ github.repository_owner }}
74+
password: ${{ secrets.GITHUB_TOKEN }}
75+
76+
- name: Build and push must-gather image
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: .
80+
file: ./cmd/gather/Dockerfile
81+
platforms: ${{ env.PLATFORMS }}
82+
push: ${{ github.event_name != 'pull_request' }}
83+
tags: ${{ steps.docker_meta.outputs.tags }}
84+
labels: ${{ steps.docker_meta.outputs.labels }}
85+
cache-from: type=local,src=/tmp/.buildx-cache
86+
cache-to: type=local,dest=/tmp/.buildx-cache

Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ OPERATOROPAMPBRIDGE_IMG ?= ${IMG_PREFIX}/${OPERATOROPAMPBRIDGE_IMG_REPO}:$(addpr
3838
BRIDGETESTSERVER_IMG_REPO ?= e2e-test-app-bridge-server
3939
BRIDGETESTSERVER_IMG ?= ${IMG_PREFIX}/${BRIDGETESTSERVER_IMG_REPO}:ve2e
4040

41+
MUSTGATHER_IMG ?= ${IMG_PREFIX}/must-gather
42+
4143
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4244
ifeq (,$(shell go env GOBIN))
4345
GOBIN=$(shell go env GOPATH)/bin
@@ -143,6 +145,10 @@ ci: generate fmt vet test ensure-generate-is-noop
143145
manager: generate
144146
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/manager_${ARCH} -ldflags "${COMMON_LDFLAGS} ${OPERATOR_LDFLAGS}" main.go
145147

148+
.PHONY: must-gather
149+
must-gather:
150+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/must-gather_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/gather/main.go
151+
146152
# Build target allocator binary
147153
.PHONY: targetallocator
148154
targetallocator:
@@ -362,6 +368,15 @@ container-bridge-test-server: GOOS = linux
362368
container-bridge-test-server:
363369
docker build --load -t ${BRIDGETESTSERVER_IMG} tests/test-e2e-apps/bridge-server
364370

371+
.PHONY: container-must-gather
372+
container-must-gather: GOOS = linux
373+
container-must-gather: must-gather
374+
docker build -f cmd/gather/Dockerfile --load -t ${MUSTGATHER_IMG} .
375+
376+
.PHONY: container-must-gather-push
377+
container-must-gather-push:
378+
docker push ${MUSTGATHER_IMG}
379+
365380
.PHONY: start-kind
366381
start-kind: kind
367382
ifeq (true,$(START_KIND_CLUSTER))
@@ -388,7 +403,6 @@ else
388403
$(MAKE) container-push
389404
endif
390405

391-
392406
.PHONY: load-image-target-allocator
393407
load-image-target-allocator: container-target-allocator kind
394408
ifeq (true,$(START_KIND_CLUSTER))

cmd/gather/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM registry.access.redhat.com/ubi9-minimal:9.2
2+
3+
RUN INSTALL_PKGS=" \
4+
rsync \
5+
tar \
6+
" && \
7+
microdnf install -y $INSTALL_PKGS && \
8+
microdnf clean all
9+
WORKDIR /
10+
11+
ARG TARGETARCH
12+
COPY bin/must-gather_${TARGETARCH} /usr/bin/must-gather
13+
14+
USER 65532:65532
15+
16+
ENTRYPOINT ["/usr/bin/must-gather"]

cmd/gather/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# OpenTelemetry Operator Must-Gather
2+
3+
The OpenTelemetry Operator `must-gather` tool is designed to collect comprehensive information about OpenTelemetry components within an OpenShift cluster. This utility extends the functionality of [OpenShift must-gather](https://github.com/openshift/must-gather) by specifically targeting and retrieving data related to the OpenTelemetry Operator, helping in diagnostics and troubleshooting.
4+
5+
Note that you can use this utility too to gather information about the objects deployed by the OpenTelemetry Operator if you don't use OpenShift.
6+
7+
## What is a Must-Gather?
8+
9+
The `must-gather` tool is a utility that collects logs, cluster information, and resource configurations related to a specific operator or application in an OpenShift cluster. It helps cluster administrators and developers diagnose issues by providing a snapshot of the cluster's state related to the targeted component. More information [in the official documentation](https://docs.openshift.com/container-platform/4.16/support/gathering-cluster-data.html).
10+
11+
## Usage
12+
13+
First, you will need to build and push the image:
14+
```sh
15+
make container-must-gather container-must-gather-push
16+
```
17+
18+
To run the must-gather tool for the OpenTelemetry Operator, use one of the following commands, depending on how you want to source the image and the namespace where the operator is deployed.
19+
20+
### Using the image from the Operator deployment
21+
22+
This is the recommended way to do it if you are not using OpenShift.
23+
24+
If you want to use the image in a running cluster, you need to run the following command:
25+
26+
```sh
27+
oc adm must-gather --image=ghcr.io/open-telemetry/opentelemetry-operator/must-gather -- /usr/bin/must-gather --operator-namespace opentelemetry-operator-system
28+
```
29+
30+
### Using it as a CLI
31+
32+
You only need to build and run:
33+
```sh
34+
make must-gather
35+
./bin/must-gather_$(go env GOARCH) --help
36+
```

0 commit comments

Comments
 (0)