This file provides instructions for AI coding agents working in the KubeDB kubectl plugin Go repository.
kubectl-dba is the official kubectl plugin for KubeDB (Kubernetes database operator platform by AppsCode). It provides DBA-style commands for KubeDB-managed databases: describe, connect/exec, restart, pause/resume, debug, monitor, show credentials, generate appbinding/secrets for remote replicas, and insert/verify test data. Distributed as a single static binary via GitHub Releases and as the dba plugin in the krew-index.
Supported databases include: Cassandra, ClickHouse, Druid, Elasticsearch, Hazelcast, Ignite, Kafka, MariaDB, Memcached, MongoDB, MSSQLServer, MySQL, Oracle, PerconaXtraDB, PgBouncer, Pgpool, PostgreSQL, ProxySQL, RabbitMQ, Redis, SingleStore, Solr, ZooKeeper.
Builds run inside the ghcr.io/appscode/golang-dev:1.25 Docker image (set by BUILD_IMAGE). The output binary is bin/kubectl-dba-$(GOOS)-$(GOARCH).
# Default: format + build for host OS/ARCH
make
# Build only (host platform)
make build
# Cross-build a specific platform
make build GOOS=linux GOARCH=arm64
# Build all release platforms (linux/amd64, linux/arm, linux/arm64, windows/amd64, darwin/amd64, darwin/arm64)
make all-build
# Compressed release artifacts (.tar.gz / .zip + checksums)
make all-build COMPRESS=yes
# Format Go sources (runs hack/fmt.sh inside docker)
make fmt
# Run unit tests
make test
make unit-tests
# Lint (golangci-lint inside docker)
make lint
# Full CI pipeline: verify check-license lint build unit-tests
make ci
# License header management
make add-license
make check-license
# Verify go.mod / vendor / generated files are current
make verify # verify-gen + verify-modules
# Print version / build metadata
make version
# Generate krew plugin manifest (requires a git tag)
make gen-krew-manifest
# Remove build artifacts
make cleanRelease flow: make qa (non-prod, branch builds) and make release (only with APPSCODE_ENV=prod and a git tag). The .github/workflows/release.yml job runs make release COMPRESS=yes, uploads tarballs to GitHub Releases, then opens a PR to appscode/krew-index via hack/krew/plugin.yaml.
The hack/build.sh script injects ldflags (main.Version, main.GitTag, main.CommitHash, etc.) read by cmd/kubectl-dba/version.go.
cmd/kubectl-dba/
main.go # Entry point: calls cmds.NewKubeDBCommand
version.go # Build-time ldflag variables -> gomodules.xyz/x/version
pkg/
cmds/ # Cobra command wiring (one file per top-level command)
root.go # NewKubeDBCommand builds the command tree and groups
describe.go connect.go exec.go data.go debug.go monitor.go
pause.go resume.go restart.go remote_replica.go mssql.go
show_credentials.go completion.go options.go
common/ # Shared SQL helpers (mssql, mysql, postgres)
connect/ # `kubectl dba connect` per-database implementations
credentials/ # `kubectl dba show-credentials` per-database implementations
data/ # `kubectl dba data insert/drop/verify` test-data clients
redisutil/ # Redis cluster helpers
debug/ # `kubectl dba debug` per-database collectors + gitops.go
describer/ # `kubectl dba describe` printers (kubectl describe-style)
events/ # Event sorting helpers
lib/ # Shared client helpers
monitor/ # `kubectl dba monitor` (Prometheus, alerts, dashboards)
alerts/ connection/ dashboard/
pauser/ resumer/ # Per-database pause/resume logic + archiver
printer/ # Table/YAML printers
remote_replica/ # AppBinding + Secret generation for MySQL/Postgres replicas
restarter/ # Per-database restart logic
hack/
build.sh test.sh fmt.sh coverage.sh e2e.sh # Wrapped by Makefile
krew/plugin.yaml # krew manifest template (populated by gen-krew-manifest)
gendocs/ # Tool to regenerate kubectl-dba reference docs
license/ # License header template (used by ltag)
scripts/
.github/workflows/
ci.yml # PR/push: runs `make ci`
release.yml # Tag push: cross-build, GitHub Release, krew PR
release-tracker.yml update-docs.yml
vendor/ # Vendored deps (built with GOFLAGS=-mod=vendor)
pkg/cmds.NewKubeDBCommand(in, out, err) *cobra.Command(pkg/cmds/root.go) - assembles the root Cobra command, kubeconfig flags viagenericclioptions.NewConfigFlags, and grouped subcommands usingk8s.io/kubectl/pkg/util/templates.cmd/kubectl-dba/main.go- thinmainthat constructs the root command, callslogs.Init, and executes.- Per-command constructors follow the convention
NewCmd<Verb>(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command(seedescribe.go,restart.go,pause.go,resume.go,show_credentials.go). Connection-style commands use the shorterNewCmd<Verb>(f cmdutil.Factory)form (connect.go,exec.go,data.go,debug.go,monitor.go,remote_replica.go,mssql.go). - Command groups defined in
root.go: Troubleshooting/Debugging, Database Ops, Pause/Resume, Database Connection, Data Insert/Verify, Debug, Remote Replica appbinding, MSSQLServer, Metrics. - Per-database engine packages (
pkg/connect,pkg/data,pkg/debug,pkg/pauser,pkg/resumer,pkg/restarter,pkg/credentials,pkg/describer) each follow the same one-file-per-database layout (mysql.go,postgres.go,mongodb.go,redis.go, ...) plus a smallconst.go/helpers.go/common.goand a top-level dispatcher (e.g.pauser.go,resumer.go,restarter.go,show_cred.go).
- Unit tests run via
make test(alias formake unit-tests), which invokeshack/test.sh cmd pkginside the build container. The script just runsgo test -installsuffix "static" ./cmd/... ./pkg/...withGOFLAGS=-mod=vendor. hack/coverage.shgenerates coverage output;hack/e2e.shis reserved for e2e runs.- CI (
.github/workflows/ci.yml) runsmake ci(verify check-license lint build unit-tests) on Go 1.25 / Ubuntu 24.04 for every PR and push tomaster. - There are currently no
_test.gofiles outside vendor; most validation is via build + lint + manual/cluster testing.
Module path: kubedb.dev/cli, Go 1.25.5.
Internal (KubeDB / AppsCode ecosystem):
kubedb.dev/apimachinery- KubeDB CRD types (Database, Ops, Archiver, Schema, etc.)kubedb.dev/db-client-go- shared per-engine client helpers used byconnect/data/debugkmodules.xyz/client-go,kmodules.xyz/custom-resources,kmodules.xyz/cert-manager-util,kmodules.xyz/monitoring-agent-apikubeops.dev/petset- PetSet (StatefulSet replacement) typesstash.appscode.dev/apimachinery- Stash backup CRDsgomodules.xyz/x(version, logs),gomodules.xyz/go-sh,gomodules.xyz/pointer,gomodules.xyz/runtime
External:
github.com/spf13/cobra- CLI frameworkk8s.io/{api,apimachinery,cli-runtime,client-go,component-base,kubectl}v0.34.x - Kubernetes client andkubectlplugin scaffoldingsigs.k8s.io/controller-runtimev0.22.4 (replaced with thekmodules/controller-runtimefork)github.com/cert-manager/cert-managerv1.19.4- Database drivers / clients:
github.com/go-sql-driver/mysql,github.com/redis/go-redis/v9,github.com/elastic/go-elasticsearch/v{5..9},github.com/opensearch-project/opensearch-go/v{1..3}(all indirect viadb-client-go) github.com/prometheus/{client_golang,common}- metrics integration
go.mod replace directives (do not casually edit):
github.com/Masterminds/sprig/v3 => github.com/gomodules/sprig/v3 v3.2.3-0.20220405051441-0a8a99bac1b8
sigs.k8s.io/controller-runtime => github.com/kmodules/controller-runtime v0.22.5-0.20251227114913-f011264689cd
github.com/imdario/mergo => github.com/imdario/mergo v0.3.6
k8s.io/apiserver => github.com/kmodules/apiserver v0.34.4-0.20251227112449-07fa35efc6fc
Builds use vendored dependencies (GOFLAGS=-mod=vendor). After bumping any module, run make verify-modules to refresh go.mod/go.sum/vendor/.
- License headers (
hack/license/) are required on every Go file; enforce withmake add-license/make check-license(usesltag). golangci.ymlenables the standard linter set plusunparam, withgofmtconfigured to rewriteinterface{}toanyandgoimportsenabled. Generated files (generated.*\.go) andclient/,vendor/are excluded.- Use
cmdutil.Factoryandgenericiooptions.IOStreamsfromk8s.io/cli-runtimefor all new subcommands - never callkubectlconfig helpers directly. - Per-database parallel structure: when adding support for a new engine, add a sibling file in each relevant
pkg/<feature>/<engine>.goand wire it into the dispatcher (pkg/<feature>/<feature>.goor the correspondingpkg/cmds/<verb>.go). - The plugin binary is named
kubectl-dba(krew name:dba); preserve this when editingMakefile,hack/krew/plugin.yaml, or release workflow asset names. - Do not commit
bin/,.go/, orvendor/changes that are not the result of a deliberate dependency update.