Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ cache/
debug.test*

# Others
.envrc
.envrc

# must-gather
must-gather/must-gather/
must-gather/must-gather.local.*/
56 changes: 28 additions & 28 deletions must-gather/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
FROM --platform=$BUILDPLATFORM quay.io/konveyor/builder:ubi9-latest AS konveyor-builder
FROM --platform=$BUILDPLATFORM quay.io/konveyor/builder:ubi9-latest AS builder
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG RESTIC_BRANCH=konveyor-0.15.0
ARG VELERO_BRANCH=konveyor-dev
WORKDIR /build
RUN curl --location --output velero.tgz https://github.com/openshift/velero/archive/refs/heads/${VELERO_BRANCH}.tar.gz && \
tar -xzvf velero.tgz && cd velero-${VELERO_BRANCH} && \
VELERO_COMMIT=$(git ls-remote https://github.com/openshift/velero HEAD | awk '{printf $1}') && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -mod=mod -ldflags '-extldflags "-static" -X github.com/vmware-tanzu/velero/pkg/buildinfo.Version='"${VELERO_BRANCH}"' -X github.com/vmware-tanzu/velero/pkg/buildinfo.GitSHA='"${VELERO_COMMIT}" -o /velero github.com/vmware-tanzu/velero/cmd/velero && \
cd .. && rm -rf velero.tgz velero-${VELERO_BRANCH} && \
curl --location --output restic.tgz https://github.com/openshift/restic/archive/refs/heads/${RESTIC_BRANCH}.tar.gz && \
tar -xzvf restic.tgz && cd restic-${RESTIC_BRANCH} && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -mod=mod -ldflags '-extldflags "-static"' -o /restic github.com/restic/restic/cmd/restic && \
cd .. && rm -rf restic.tgz restic-${RESTIC_BRANCH}
ARG KOPIA_BRANCH=konveyor-dev
ARG RESTIC_BRANCH=konveyor-dev

FROM registry.access.redhat.com/ubi9/go-toolset:latest AS gobuilder
WORKDIR /workspace

RUN go install -v github.com/google/pprof@latest
COPY go.mod go.mod
COPY go.sum go.sum

FROM quay.io/openshift/origin-must-gather:latest AS builder
RUN go mod download

FROM registry.access.redhat.com/ubi9-minimal:latest
COPY cmd/main.go cmd/main.go
COPY pkg/ pkg/

RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod=mod -a -o gather cmd/main.go

RUN curl --location --output kopia.tgz https://github.com/migtools/kopia/archive/refs/heads/${KOPIA_BRANCH}.tar.gz && \
tar -xzvf kopia.tgz && cd kopia-${KOPIA_BRANCH} && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod=mod -a -ldflags '-extldflags "-static"' -o /kopia github.com/kopia/kopia && \
cd .. && rm -rf kopia.tgz kopia-${KOPIA_BRANCH}

RUN echo -ne "[centos-9-appstream]\nname = CentOS 9 (RPMs) - AppStream\nbaseurl = https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/\nenabled = 1\ngpgcheck = 0" > /etc/yum.repos.d/centos-9-appstream.repo
RUN microdnf -y install rsync tar gzip graphviz findutils
RUN curl --location --output restic.tgz https://github.com/openshift/restic/archive/refs/heads/${RESTIC_BRANCH}.tar.gz && \
tar -xzvf restic.tgz && cd restic-${RESTIC_BRANCH} && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod=mod -a -ldflags '-extldflags "-static"' -o /restic github.com/restic/restic/cmd/restic && \
cd .. && rm -rf restic.tgz restic-${RESTIC_BRANCH}

FROM registry.access.redhat.com/ubi9-minimal:latest

COPY --from=gobuilder /opt/app-root/src/go/bin/pprof /usr/bin/pprof
COPY --from=builder /usr/bin/oc /usr/bin/oc
COPY --from=konveyor-builder /velero /usr/bin/velero
COPY --from=konveyor-builder /restic /usr/bin/restic
# oc adm must-gather uses these packages to download the output
RUN microdnf -y install rsync tar

COPY collection-scripts/* /usr/bin/
COPY collection-scripts/debug/* /usr/bin/
COPY collection-scripts/logs/* /usr/bin/
COPY collection-scripts/time_window_gather /usr/bin/
COPY --from=builder /workspace/gather /usr/bin/gather
COPY --from=builder /kopia /usr/bin/kopia
COPY --from=builder /restic /usr/bin/restic

ENTRYPOINT /usr/bin/gather
ENTRYPOINT ["/usr/bin/gather"]
51 changes: 0 additions & 51 deletions must-gather/Makefile

This file was deleted.

110 changes: 50 additions & 60 deletions must-gather/README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,73 @@
# OADP must-gather
# OADP Must-gather

`must-gather` is a tool built on top of [OpenShift must-gather](https://github.com/openshift/must-gather)
that expands its capabilities to gather OADP operator specific resources

### Usage

**Full gather**
To test OADP Must-gather, run
```sh
oc adm must-gather --image=quay.io/konveyor/oadp-must-gather:latest
go run cmd/main.go -h
go run cmd/main.go
```

The command above will create a local directory with a dump of the OADP Operator state.

You will get a dump of:
- All namespaces where OADP operator is installed, including pod logs
- All velero.io resources located in those namespaces
- Prometheus metrics

**Essential-only gather**

Differences from full gather:
- Logs are only gathered from specified time window
- Skips collection of prometheus metrics. Removes duplicate logs from payload.
```
# Essential gather (available time windows: [1h, 6h, 24h, 72h, all])
oc adm must-gather --image=quay.io/konveyor/oadp-must-gather:latest -- /usr/bin/gather_24h_essential
To test OADP Must-gather with `oc adm must-gather`, run
```sh
podman build -t ttl.sh/oadp/must-gather-$(git rev-parse --short HEAD)-$(echo $RANDOM) -f Dockerfile . --platform=<cluster-architecture>
podman push <this-image>
oc adm must-gather --image=<this-image> -- /usr/bin/gather -h
oc adm must-gather --image=<this-image>
```
TODO mention e2e tests

#### Preview metrics on local Prometheus server
To test omg tool, create `omg.Dockerfile` file
```Dockerfile
FROM python:3.10.12-slim-bullseye

Get Prometheus metrics data directory dump (last day, might take a while):
```sh
oc adm must-gather --image quay.io/konveyor/oadp-must-gather:latest -- /usr/bin/gather_metrics_dump
WORKDIR /test-omg
COPY ./ ./
RUN pip install o-must-gather
```

Run local Prometheus instance with dumped data:
and run
```sh
make prometheus-run # and prometheus-cleanup when you're done
podman build -t omg-container -f omg.Dockerfile .
podman run -ti --rm omg-container bash
# inside container
omg use must-gather/clusters/
omg get backup -n <namespace> # and other OADP resources
```
The latest Prometheus data file (prom_data.tar.gz) in current directory/subdirectories is searched by default. Could be specified in ```PROMETHEUS_DUMP_PATH``` environment variable.

### Known Limitations

`velero backups` with phase `FailedValidation` could cause `must-gather` to be slow. In order to speed up the process, pass a timeout value to the command as follows,
To update OADP Must-gather `go.mod` dependencies, run
```sh
oc adm must-gather --image=quay.io/konveyor/oadp-must-gather:latest -- /usr/bin/gather_with_timeout <timeout_value_in_seconds>
go get github.com/openshift/oadp-operator@master
go get github.com/migtools/oadp-non-admin@master
# manually update github.com/openshift/velero version in replace section of go.mod to match OADP operator
go mod tidy
go mod verify
```
### Support for insecure TLS connections

If a custom CA cert is used, then must-gather pod fails to grab the output for velero logs/describe. In this case, the user can pass a flag to the must-gather command to allow insecure TLS connections.
Update it often. It must be updated prior to releases.

Possible necessary updates over the time
```sh
oc adm must-gather --image=quay.io/konveyor/oadp-must-gather:latest -- /usr/bin/gather_without_tls <true/false>
go get github.com/openshift/oc@<branch-or-commit>
go mod tidy
go mod verify
```
Note: By default the flag value is set to `false`

### Combining Options
## OADP release

It is not currently possible to combine multiple gather scripts, for example specifying a timeout value at the same time as allowing insecure TLS. However, it is possible in some cases to work around this limitation by setting internal variables on the must-gather command line, like this:
Prior to each release, OADP Must-gather must be updated.

To update OADP Must-gather `go.mod` dependencies, run
```sh
oc adm must-gather --image=quay.io/konveyor/oadp-must-gather:latest -- skip_tls=true /usr/bin/gather_with_timeout <timeout_value_in_seconds>
go get github.com/openshift/oadp-operator@<release-brach>
go get github.com/migtools/oadp-non-admin@<release-brach>
# manually update github.com/openshift/velero version in replace section of go.mod to match OADP operator
go mod tidy
go mod verify
```

In this case, the `skip_tls` variable is set before running the gather_with_timeout script, and the net effect is a combination of gather_with_timeout and gather_without_tls. The only other variables that can be specified this way are `logs_since`, with a default value of `72h`, and `request_timeout`, with a default value of `0s`.

### Development
You can build the image locally using the Dockerfile included.

A `makefile` is also provided. To use it, you must pass a repository via the command-line using the variable `IMAGE_NAME`.
You can also specify the registry using the variable `IMAGE_REGISTRY` (default is [quay.io](https://quay.io)) and the tag via `IMAGE_TAG` (default is `latest`).

The targets for `make` are as follows:
- `build`: builds the image with the supplied name and pushes it
- `docker-build`: builds the image but does not push it
- `docker-push`: pushes an already-built image

For example:
```sh
make build IMAGE_NAME=my-repo/must-gather
`must-gather/pkg/cli.go` file must be updated
```diff
const (
- mustGatherVersion = "1.5.0"
+ mustGatherVersion = "1.5.1"
mustGatherImage = "registry.redhat.io/oadp/oadp-mustgather-rhel9:v1.5"
```
would build the local repository as `quay.io/my-repo/must-gather:latest` and then push it.

> **Note:** If it is a minor release, `mustGatherImage` must also be updated.
26 changes: 26 additions & 0 deletions must-gather/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"os"

"github.com/spf13/cobra"

"github.com/openshift/oadp-operator/must-gather/pkg"
)

func init() {
pkg.CLI.Flags().DurationVarP(&pkg.RequestTimeout, "request-timeout", "r", pkg.DefaultRequestTimeout, "Timeout per OADP server request (like collecting logs from a backup)")
pkg.CLI.Flags().BoolVarP(&pkg.SkipTLS, "skip-tls", "s", false, "Run OADP server requests with insecure TLS connections (recommended if a custom CA certificate is used) (default false)")
// TODO caCertFile?
pkg.CLI.Flags().BoolP("help", "h", false, "Show OADP Must-gather help message.")

pkg.CLI.SetHelpCommand(&cobra.Command{Hidden: true, Use: ""})
}

func main() {
// TODO JSON output in the future?
err := pkg.CLI.Execute()
if err != nil {
os.Exit(1)
}
}
98 changes: 0 additions & 98 deletions must-gather/collection-scripts/_metrics_chart_template_part_1.html

This file was deleted.

Loading