Skip to content

Commit

Permalink
Create a must-gather for the operator (#3150)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
iblancasa authored Oct 7, 2024
1 parent 98433bd commit e84193d
Show file tree
Hide file tree
Showing 13 changed files with 1,315 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .chloggen/3149-add-must-gather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation, collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add a must gather utility to help troubleshoot"

# One or more tracking issues related to the change
issues: [3149]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The new utility is available as part of a new container image.
To use the image in a running OpenShift cluster, you need to run the following command:
```sh
oc adm must-gather --image=ghcr.io/open-telemetry/opentelemetry-operator/must-gather -- /usr/bin/must-gather --operator-namespace opentelemetry-operator-system
```
See the [README](https://github.com/open-telemetry/opentelemetry-operator/blob/main/cmd/gather/README.md) for more details.
86 changes: 86 additions & 0 deletions .github/workflows/publish-must-gather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Publish must-gather image"

on:
push:
branches: [ main ]
tags: [ 'v*' ]

workflow_dispatch:

env:
PLATFORMS: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le

jobs:
publish:
name: Publish must-gather container image
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '~1.22.4'

- name: Unshallow
run: git fetch --prune --unshallow

- name: Build the binary for each supported architecture
run: |
for platform in $(echo $PLATFORMS | tr "," "\n"); do
arch=${platform#*/}
echo "Building must-gather for $arch"
make must-gather ARCH=$arch
done
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/open-telemetry/opentelemetry-operator/must-gather
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{raw}}
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log into Docker.io
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Package Registry
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push must-gather image
uses: docker/build-push-action@v6
with:
context: .
file: ./cmd/gather/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ OPERATOROPAMPBRIDGE_IMG ?= ${IMG_PREFIX}/${OPERATOROPAMPBRIDGE_IMG_REPO}:$(addpr
BRIDGETESTSERVER_IMG_REPO ?= e2e-test-app-bridge-server
BRIDGETESTSERVER_IMG ?= ${IMG_PREFIX}/${BRIDGETESTSERVER_IMG_REPO}:ve2e

MUSTGATHER_IMG ?= ${IMG_PREFIX}/must-gather

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -143,6 +145,10 @@ ci: generate fmt vet test ensure-generate-is-noop
manager: generate
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/manager_${ARCH} -ldflags "${COMMON_LDFLAGS} ${OPERATOR_LDFLAGS}" main.go

.PHONY: must-gather
must-gather:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/must-gather_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/gather/main.go

# Build target allocator binary
.PHONY: targetallocator
targetallocator:
Expand Down Expand Up @@ -362,6 +368,15 @@ container-bridge-test-server: GOOS = linux
container-bridge-test-server:
docker build --load -t ${BRIDGETESTSERVER_IMG} tests/test-e2e-apps/bridge-server

.PHONY: container-must-gather
container-must-gather: GOOS = linux
container-must-gather: must-gather
docker build -f cmd/gather/Dockerfile --load -t ${MUSTGATHER_IMG} .

.PHONY: container-must-gather-push
container-must-gather-push:
docker push ${MUSTGATHER_IMG}

.PHONY: start-kind
start-kind: kind
ifeq (true,$(START_KIND_CLUSTER))
Expand All @@ -388,7 +403,6 @@ else
$(MAKE) container-push
endif


.PHONY: load-image-target-allocator
load-image-target-allocator: container-target-allocator kind
ifeq (true,$(START_KIND_CLUSTER))
Expand Down
16 changes: 16 additions & 0 deletions cmd/gather/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM registry.access.redhat.com/ubi9-minimal:9.2

RUN INSTALL_PKGS=" \
rsync \
tar \
" && \
microdnf install -y $INSTALL_PKGS && \
microdnf clean all
WORKDIR /

ARG TARGETARCH
COPY bin/must-gather_${TARGETARCH} /usr/bin/must-gather

USER 65532:65532

ENTRYPOINT ["/usr/bin/must-gather"]
36 changes: 36 additions & 0 deletions cmd/gather/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# OpenTelemetry Operator Must-Gather

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.

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.

## What is a Must-Gather?

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).

## Usage

First, you will need to build and push the image:
```sh
make container-must-gather container-must-gather-push
```

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.

### Using the image from the Operator deployment

This is the recommended way to do it if you are not using OpenShift.

If you want to use the image in a running cluster, you need to run the following command:

```sh
oc adm must-gather --image=ghcr.io/open-telemetry/opentelemetry-operator/must-gather -- /usr/bin/must-gather --operator-namespace opentelemetry-operator-system
```

### Using it as a CLI

You only need to build and run:
```sh
make must-gather
./bin/must-gather_$(go env GOARCH) --help
```
Loading

0 comments on commit e84193d

Please sign in to comment.