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
25 changes: 23 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,37 @@ on:
- 'CODEOWNERS'
- 'LICENSE'
jobs:
workspace-sync:
name: workspace sync check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: 1.25
- name: Check go.work.sum is in sync
run: |
go work sync
git diff --exit-code go.work.sum || (echo "go.work.sum is out of sync — run 'make tidy' and commit the result" && exit 1)

golangci:
name: lint
name: lint (${{ matrix.module }})
runs-on: ubuntu-latest
strategy:
matrix:
module:
- .
- cmd/tool
- tests
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: 1.25
- name: golangci-lint
- name: golangci-lint (${{ matrix.module }})
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
working-directory: ${{ matrix.module }}
build:
name: CI Build
strategy:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*.swp
.idea
./backup
./backup-restore-operator
backup-restore-operator
operator
!cmd/operator
tool
!cmd/tool
/secretExamples
test-backup-location-local/
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters:
path: pkg/util
- linters:
- revive
path: cmd/operator/version/version.go
path: pkg/version/version.go
text: var-naming
paths:
- /zz_generated_
Expand Down
31 changes: 24 additions & 7 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 2 # the goreleaser config version
before:
hooks:
- go mod tidy
- ./scripts/tidy
builds:
- id: backup-restore-operator
main: ./cmd/operator/main.go
Expand All @@ -16,9 +16,9 @@ builds:
- -extldflags
- -static
- -s
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.Version={{.Version}}
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.GitCommit={{.Commit}}
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.Date={{.Date}}
- -X github.com/rancher/backup-restore-operator/pkg/version.Version={{.Version}}
- -X github.com/rancher/backup-restore-operator/pkg/version.GitCommit={{.Commit}}
- -X github.com/rancher/backup-restore-operator/pkg/version.Date={{.Date}}
flags:
- -trimpath
env:
Expand All @@ -35,15 +35,32 @@ builds:
binary: backup-restore-operator
ldflags:
- -s
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.Version={{.Version}}
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.GitCommit={{.Commit}}
- -X github.com/rancher/backup-restore-operator/cmd/operator/version.Date={{.Date}}
- -X github.com/rancher/backup-restore-operator/pkg/version.Version={{.Version}}
- -X github.com/rancher/backup-restore-operator/pkg/version.GitCommit={{.Commit}}
- -X github.com/rancher/backup-restore-operator/pkg/version.Date={{.Date}}
flags:
- -trimpath
env:
- CGO_ENABLED=0
skip: '{{ not (index .Env "GOOS_DARWIN_DEV") }}'

- id: bro-tool
main: ./cmd/tool/main.go
goos:
- linux
- darwin
- windows
binary: bro-tool
ldflags:
- -s
- -X github.com/rancher/backup-restore-operator/pkg/version.Version={{.Version}}
- -X github.com/rancher/backup-restore-operator/pkg/version.GitCommit={{.Commit}}
- -X github.com/rancher/backup-restore-operator/pkg/version.Date={{.Date}}
flags:
- -trimpath
env:
- CGO_ENABLED=0

archives:
- id: backup-restore-operator
builds:
Expand Down
60 changes: 60 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,66 @@

Developer tips, tricks, and workflows for the [rancher/backup-restore-operator](https://github.com/rancher/backup-restore-operator).

### Go Workspace (go.work)

This repository uses a [Go workspace](https://go.dev/ref/mod#workspaces) (`go.work`) to manage three independent Go modules together:

| Module | Path |
|---|---|
| `github.com/rancher/backup-restore-operator` | `.` (root) |
| `github.com/rancher/backup-restore-operator/cmd/tool` | `./cmd/tool` |
| `github.com/rancher/backup-restore-operator/tests` | `./tests` |

The workspace means you can run `go` commands from the repository root and have them resolve cross-module dependencies without needing to publish anything.

#### Day-to-day commands

```bash
# Build everything in the workspace (operator + bro-tool)
make build

# Build just bro-tool (from repo root via workspace)
go build -C cmd/tool -o bin/bro-tool .

# Test everything in the workspace
go test ./...

# Tidy all modules and sync go.work.sum in one step
make tidy

# Tidy a single module manually (run from that module's directory)
cd cmd/tool && go mod tidy

# Update go.work.sum after any go.mod change
go work sync
```

#### Adding dependencies

Always add dependencies to the **correct module's** `go.mod`, not the root. The rule of thumb:

- Dependency only used by `bro-tool` → `cd cmd/tool && go get <pkg>`
- Dependency only used by integration tests → `cd tests && go get <pkg>`
- Dependency used by the operator itself → `go get <pkg>` from the root

Never add `bro-tool`- or test-only dependencies to the root module. The root module is the BRO operator binary; bloating it affects the production image.

#### Workspace vs. standalone

The `go.work` file is checked in and should always be present for local development. Each sub-module also carries a `replace` directive in its own `go.mod` (e.g. `cmd/tool/go.mod` replaces the root module with `../../`) so the modules still resolve correctly in contexts where `go.work` is not active — such as individual module CI jobs or `go get` from external consumers.

If you ever need to test a module in true standalone mode (without the workspace), use `GOWORK=off`:

```bash
GOWORK=off go build ./...
```

#### IDE / gopls

Most editors using `gopls` pick up `go.work` automatically and provide full cross-module navigation and type checking. If your editor shows unresolved imports across modules, check that gopls is running from the repository root (where `go.work` lives), not from inside a sub-module directory.

---

### Developer Installation

To test your local changes, `cd` to the root of the cloned repository, and execute the following commands:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ Refer to [DEVELOPING.md](./DEVELOPING.md) for developer tips, tricks, and workfl
### Troubleshooting

Refer to [troubleshooting.md](./docs/troubleshooting.md) for troubleshooting commands.

---

### bro-tool

`bro-tool` is an unofficial companion CLI for support engineers and developers. It lets you inspect BRO ResourceSet configuration and check resource coverage **without a live cluster**.

> **No Warranty.** `bro-tool` is provided as-is and is **not** a supported SUSE/Rancher product. It carries no SLA and is not covered by any support agreement. This is in contrast to BRO itself, which is a supported product for paying customers.

Refer to [docs/bro-tool.md](./docs/bro-tool.md) for full usage documentation.
10 changes: 9 additions & 1 deletion cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/rancher/backup-restore-operator/pkg/version"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/signals"
"github.com/sirupsen/logrus"

"github.com/rancher/backup-restore-operator/cmd/operator/version"
"github.com/rancher/backup-restore-operator/pkg/operator"
backuputil "github.com/rancher/backup-restore-operator/pkg/util"
)
Expand All @@ -27,12 +28,14 @@ var (
ChartNamespace string
Debug bool
Trace bool
PrintVersion bool
)

func init() {
flag.StringVar(&KubeConfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.BoolVar(&Debug, "debug", false, "Enable debug logging.")
flag.BoolVar(&Trace, "trace", false, "Enable trace logging.")
flag.BoolVar(&PrintVersion, "version", false, "Print version information and exit.")

flag.Parse()
OperatorPVEnabled = os.Getenv("DEFAULT_PERSISTENCE_ENABLED")
Expand All @@ -43,6 +46,11 @@ func init() {
}

func main() {
if PrintVersion {
fmt.Println(version.FmtVersionInfo("backup-restore-operator"))
return
}

logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, ForceColors: true, TimestampFormat: LogFormat})
if Debug {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
7 changes: 0 additions & 7 deletions cmd/operator/version/version.go

This file was deleted.

81 changes: 81 additions & 0 deletions cmd/tool/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module github.com/rancher/backup-restore-operator/cmd/tool

go 1.25.0

replace github.com/rancher/backup-restore-operator => ../../

require (
github.com/rancher/backup-restore-operator v0.0.0
github.com/sirupsen/logrus v1.9.4
helm.sh/helm/v3 v3.20.0
k8s.io/apimachinery v0.35.0
k8s.io/client-go v0.35.0
sigs.k8s.io/yaml v1.6.0
)

require (
dario.cat/mergo v1.0.2 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/rancher/lasso v0.2.6 // indirect
github.com/rancher/wrangler/v3 v3.4.0 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.35.0 // indirect
k8s.io/apiextensions-apiserver v0.35.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
)
Loading
Loading