From c2133550f72aab2d10b8b0f007ba486e5d128554 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Tue, 3 Feb 2026 17:47:45 -0800 Subject: [PATCH] rpk: bump golangci-lint to v2 and fix issues This bump increased the accuracy and the report showed up to 100 issues. One of the major changes that were not fixed by the `--fix` flag were: - Package naming: common -> better names - net, os, utils -> netutil, osutil, rpkutil to avoid collision with standard naming packages - Context handling in the container package. We were using a context.Background with a timeout instead of the command context. There are further improvements to be made as moving away from some of the code in rpkutil and eliminating the containerutil package but these will be handled in separate commits to not hinder the review of this one. In addition we are also bumping the golangci-lint version in our Github Actions. --- .github/workflows/lint-golang.yml | 6 +- src/go/.goreleaser.yaml | 10 +- src/go/rpk/.golangci.yml | 176 +++++++++--------- src/go/rpk/Makefile | 2 +- src/go/rpk/build.sh | 2 +- src/go/rpk/cmd/rpk/BUILD | 2 +- src/go/rpk/pkg/cli/cloud/BUILD | 4 +- src/go/rpk/pkg/cli/cloud/byoc/BUILD | 2 +- src/go/rpk/pkg/cli/cloud/byoc/install.go | 2 +- src/go/rpk/pkg/cli/cloud/login.go | 6 +- src/go/rpk/pkg/cli/cloud/logout.go | 2 +- src/go/rpk/pkg/cli/cloud/mcp/BUILD | 2 +- src/go/rpk/pkg/cli/cloud/mcp/mcp.go | 34 ++-- src/go/rpk/pkg/cli/cluster/config/edit.go | 2 +- src/go/rpk/pkg/cli/cluster/config/export.go | 4 +- src/go/rpk/pkg/cli/cluster/config/get.go | 4 +- src/go/rpk/pkg/cli/cluster/config/import.go | 4 +- src/go/rpk/pkg/cli/cluster/config/reset.go | 2 +- src/go/rpk/pkg/cli/cluster/config/set.go | 11 +- .../pkg/cli/cluster/maintenance/disable.go | 4 +- .../rpk/pkg/cli/cluster/maintenance/enable.go | 11 +- .../rpk/pkg/cli/cluster/maintenance/status.go | 4 +- .../pkg/cli/cluster/partitions/move_status.go | 4 +- .../cluster/partitions/transfer_leadership.go | 8 +- .../cli/cluster/partitions/unsafe_recover.go | 2 +- src/go/rpk/pkg/cli/cluster/storage/mount.go | 4 +- .../pkg/cli/cluster/storage/recovery/start.go | 9 +- src/go/rpk/pkg/cli/cluster/storage/unmount.go | 2 +- src/go/rpk/pkg/cli/connect/BUILD | 2 +- src/go/rpk/pkg/cli/connect/connect.go | 2 +- src/go/rpk/pkg/cli/connect/install.go | 6 +- src/go/rpk/pkg/cli/connect/upgrade.go | 4 +- src/go/rpk/pkg/cli/container/BUILD | 4 +- .../container/{common => containerutil}/BUILD | 4 +- .../{common => containerutil}/client.go | 2 +- .../{common => containerutil}/common.go | 49 ++--- .../{common => containerutil}/context.go | 2 +- .../{common => containerutil}/test.go | 2 +- src/go/rpk/pkg/cli/container/purge.go | 33 ++-- src/go/rpk/pkg/cli/container/start.go | 133 +++++++------ src/go/rpk/pkg/cli/container/status.go | 10 +- src/go/rpk/pkg/cli/container/stop.go | 17 +- src/go/rpk/pkg/cli/debug/bundle/BUILD | 12 +- src/go/rpk/pkg/cli/debug/bundle/bundle.go | 6 +- .../pkg/cli/debug/bundle/bundle_k8s_linux.go | 12 +- .../rpk/pkg/cli/debug/bundle/bundle_linux.go | 10 +- .../cli/debug/{common => debugbundle}/BUILD | 18 ++ .../debug/{common => debugbundle}/common.go | 4 +- .../{common => debugbundle}/common_test.go | 2 +- src/go/rpk/pkg/cli/debug/remotebundle/BUILD | 2 +- .../pkg/cli/debug/remotebundle/download.go | 8 +- .../rpk/pkg/cli/debug/remotebundle/start.go | 10 +- src/go/rpk/pkg/cli/generate/BUILD | 2 +- src/go/rpk/pkg/cli/generate/app.go | 2 +- src/go/rpk/pkg/cli/generate/graf/graph.go | 2 +- src/go/rpk/pkg/cli/generate/graf/row.go | 2 +- .../rpk/pkg/cli/generate/graf/singlestat.go | 2 +- src/go/rpk/pkg/cli/generate/grafana.go | 5 +- src/go/rpk/pkg/cli/generate/license.go | 2 +- src/go/rpk/pkg/cli/group/BUILD | 2 +- src/go/rpk/pkg/cli/group/describe.go | 4 +- src/go/rpk/pkg/cli/group/group.go | 2 +- src/go/rpk/pkg/cli/group/seek.go | 12 +- src/go/rpk/pkg/cli/plugin/BUILD | 2 +- src/go/rpk/pkg/cli/plugin/install.go | 2 +- src/go/rpk/pkg/cli/profile/BUILD | 4 +- src/go/rpk/pkg/cli/profile/create.go | 12 +- src/go/rpk/pkg/cli/profile/edit.go | 6 +- src/go/rpk/pkg/cli/profile/edit_gobals.go | 6 +- src/go/rpk/pkg/cli/profile/prompt.go | 5 +- src/go/rpk/pkg/cli/profile/validate.go | 6 +- src/go/rpk/pkg/cli/redpanda/BUILD | 20 +- .../redpanda/admin/brokers/decommission.go | 8 +- src/go/rpk/pkg/cli/redpanda/config.go | 2 +- src/go/rpk/pkg/cli/redpanda/start.go | 12 +- src/go/rpk/pkg/cli/redpanda/stop.go | 10 +- src/go/rpk/pkg/cli/redpanda/stop_test.go | 8 +- src/go/rpk/pkg/cli/redpanda/tune/BUILD | 4 +- src/go/rpk/pkg/cli/redpanda/tune/help.go | 4 +- src/go/rpk/pkg/cli/redpanda/tune/tune.go | 2 +- src/go/rpk/pkg/cli/registry/schema/get.go | 12 +- src/go/rpk/pkg/cli/root.go | 6 +- src/go/rpk/pkg/cli/security/secret/create.go | 6 +- src/go/rpk/pkg/cli/shadow/BUILD | 2 +- src/go/rpk/pkg/cli/shadow/config.go | 10 +- src/go/rpk/pkg/cli/shadow/update.go | 6 +- src/go/rpk/pkg/cli/topic/BUILD | 2 +- src/go/rpk/pkg/cli/topic/add_partitions.go | 2 +- src/go/rpk/pkg/cli/topic/config.go | 2 +- src/go/rpk/pkg/cli/topic/consume.go | 2 +- src/go/rpk/pkg/cli/topic/describe_storage.go | 2 +- src/go/rpk/pkg/cli/topic/trim.go | 4 +- src/go/rpk/pkg/cli/topic/utils.go | 8 +- src/go/rpk/pkg/cli/transform/buildpack/BUILD | 4 +- .../pkg/cli/transform/buildpack/buildpack.go | 6 +- src/go/rpk/pkg/config/BUILD | 6 +- src/go/rpk/pkg/config/config.go | 6 +- src/go/rpk/pkg/config/config_test.go | 4 +- src/go/rpk/pkg/config/params.go | 2 +- src/go/rpk/pkg/config/profile_doc.go | 58 +++--- src/go/rpk/pkg/config/redpanda_yaml.go | 2 +- src/go/rpk/pkg/config/rpk_yaml.go | 4 +- src/go/rpk/pkg/{net => netutil}/BUILD | 21 +++ src/go/rpk/pkg/{net => netutil}/hostport.go | 2 +- .../rpk/pkg/{net => netutil}/hostport_test.go | 2 +- src/go/rpk/pkg/{net => netutil}/interfaces.go | 7 +- src/go/rpk/pkg/oauth/BUILD | 2 +- src/go/rpk/pkg/oauth/load.go | 2 +- src/go/rpk/pkg/{os => osutil}/BUILD | 35 ++++ src/go/rpk/pkg/{os => osutil}/commands.go | 2 +- src/go/rpk/pkg/{os => osutil}/directory.go | 2 +- src/go/rpk/pkg/{os => osutil}/file.go | 15 +- src/go/rpk/pkg/{os => osutil}/file_all.go | 2 +- src/go/rpk/pkg/{os => osutil}/file_test.go | 2 +- src/go/rpk/pkg/{os => osutil}/file_windows.go | 2 +- src/go/rpk/pkg/{os => osutil}/lock.go | 2 +- src/go/rpk/pkg/{os => osutil}/proc.go | 6 +- src/go/rpk/pkg/{os => osutil}/proc_test.go | 12 +- src/go/rpk/pkg/plugin/BUILD | 2 +- src/go/rpk/pkg/plugin/plugin.go | 2 +- src/go/rpk/pkg/{utils => rpkutil}/BUILD | 30 +++ .../pkg/{utils => rpkutil}/chained_error.go | 2 +- src/go/rpk/pkg/{utils => rpkutil}/collect.go | 2 +- src/go/rpk/pkg/{utils => rpkutil}/files.go | 2 +- .../rpk/pkg/{utils => rpkutil}/files_test.go | 6 +- src/go/rpk/pkg/{utils => rpkutil}/os.go | 2 +- .../pkg/{utils => rpkutil}/regex_filter.go | 2 +- .../{utils => rpkutil}/regex_filter_test.go | 2 +- src/go/rpk/pkg/schemaregistry/BUILD | 2 +- src/go/rpk/pkg/schemaregistry/client.go | 4 +- src/go/rpk/pkg/system/BUILD | 8 +- src/go/rpk/pkg/system/cgroup.go | 6 +- src/go/rpk/pkg/system/grub.go | 18 +- src/go/rpk/pkg/system/grub_test.go | 16 +- src/go/rpk/pkg/system/metrics.go | 6 +- src/go/rpk/pkg/system/ntp.go | 6 +- src/go/rpk/pkg/system/runtime_options.go | 6 +- src/go/rpk/pkg/system/systemd/BUILD | 2 +- src/go/rpk/pkg/system/systemd/dbus.go | 4 +- src/go/rpk/pkg/system/utils.go | 4 +- src/go/rpk/pkg/tuners/BUILD | 20 +- src/go/rpk/pkg/tuners/aio.go | 4 +- src/go/rpk/pkg/tuners/aio_test.go | 8 +- src/go/rpk/pkg/tuners/cpu/BUILD | 4 +- src/go/rpk/pkg/tuners/cpu/tuner.go | 6 +- src/go/rpk/pkg/tuners/disk/BUILD | 16 +- src/go/rpk/pkg/tuners/disk/block_device.go | 4 +- .../rpk/pkg/tuners/disk/block_device_test.go | 8 +- src/go/rpk/pkg/tuners/disk/block_devices.go | 18 +- .../rpk/pkg/tuners/disk/block_devices_test.go | 4 +- src/go/rpk/pkg/tuners/disk_tuner.go | 4 +- .../rpk/pkg/tuners/executors/commands/BUILD | 8 +- .../tuners/executors/commands/backup_file.go | 4 +- .../pkg/tuners/executors/commands/execute.go | 6 +- .../executors/commands/write_file_lines.go | 4 +- src/go/rpk/pkg/tuners/factory/BUILD | 8 +- src/go/rpk/pkg/tuners/factory/factory.go | 18 +- src/go/rpk/pkg/tuners/fstrim.go | 12 +- src/go/rpk/pkg/tuners/fstrim_test.go | 10 +- src/go/rpk/pkg/tuners/hwloc/BUILD | 4 +- src/go/rpk/pkg/tuners/hwloc/hwloc_cmd.go | 6 +- src/go/rpk/pkg/tuners/iotune.go | 4 +- src/go/rpk/pkg/tuners/iotune/BUILD | 4 +- src/go/rpk/pkg/tuners/iotune/io_tune.go | 6 +- src/go/rpk/pkg/tuners/irq/BUILD | 16 +- src/go/rpk/pkg/tuners/irq/balance_service.go | 14 +- .../pkg/tuners/irq/balance_service_test.go | 38 ++-- src/go/rpk/pkg/tuners/irq/cpu_masks.go | 17 +- src/go/rpk/pkg/tuners/irq/device_info.go | 10 +- src/go/rpk/pkg/tuners/irq/device_info_test.go | 12 +- src/go/rpk/pkg/tuners/irq/irq_tuner_mode.go | 13 +- src/go/rpk/pkg/tuners/irq/proc_file.go | 4 +- src/go/rpk/pkg/tuners/irq/proc_file_test.go | 4 +- src/go/rpk/pkg/tuners/irq/utils.go | 4 +- src/go/rpk/pkg/tuners/net_checkers.go | 8 +- src/go/rpk/pkg/tuners/net_tuners.go | 8 +- src/go/rpk/pkg/tuners/net_tuners_test.go | 18 +- src/go/rpk/pkg/tuners/network/BUILD | 4 +- src/go/rpk/pkg/tuners/network/nic.go | 6 +- src/go/rpk/pkg/tuners/network/nics.go | 5 +- src/go/rpk/pkg/tuners/redpanda_checkers.go | 8 +- src/go/rpk/pkg/tuners/swappiness_test.go | 12 +- 182 files changed, 863 insertions(+), 763 deletions(-) rename src/go/rpk/pkg/cli/container/{common => containerutil}/BUILD (93%) rename src/go/rpk/pkg/cli/container/{common => containerutil}/client.go (99%) rename src/go/rpk/pkg/cli/container/{common => containerutil}/common.go (93%) rename src/go/rpk/pkg/cli/container/{common => containerutil}/context.go (99%) rename src/go/rpk/pkg/cli/container/{common => containerutil}/test.go (99%) rename src/go/rpk/pkg/cli/debug/{common => debugbundle}/BUILD (51%) rename src/go/rpk/pkg/cli/debug/{common => debugbundle}/common.go (98%) rename src/go/rpk/pkg/cli/debug/{common => debugbundle}/common_test.go (98%) rename src/go/rpk/pkg/{net => netutil}/BUILD (52%) rename src/go/rpk/pkg/{net => netutil}/hostport.go (99%) rename src/go/rpk/pkg/{net => netutil}/hostport_test.go (99%) rename src/go/rpk/pkg/{net => netutil}/interfaces.go (89%) rename src/go/rpk/pkg/{os => osutil}/BUILD (51%) rename src/go/rpk/pkg/{os => osutil}/commands.go (98%) rename src/go/rpk/pkg/{os => osutil}/directory.go (98%) rename src/go/rpk/pkg/{os => osutil}/file.go (91%) rename src/go/rpk/pkg/{os => osutil}/file_all.go (98%) rename src/go/rpk/pkg/{os => osutil}/file_test.go (98%) rename src/go/rpk/pkg/{os => osutil}/file_windows.go (97%) rename src/go/rpk/pkg/{os => osutil}/lock.go (98%) rename src/go/rpk/pkg/{os => osutil}/proc.go (96%) rename src/go/rpk/pkg/{os => osutil}/proc_test.go (87%) rename src/go/rpk/pkg/{utils => rpkutil}/BUILD (52%) rename src/go/rpk/pkg/{utils => rpkutil}/chained_error.go (97%) rename src/go/rpk/pkg/{utils => rpkutil}/collect.go (97%) rename src/go/rpk/pkg/{utils => rpkutil}/files.go (99%) rename src/go/rpk/pkg/{utils => rpkutil}/files_test.go (87%) rename src/go/rpk/pkg/{utils => rpkutil}/os.go (98%) rename src/go/rpk/pkg/{utils => rpkutil}/regex_filter.go (99%) rename src/go/rpk/pkg/{utils => rpkutil}/regex_filter_test.go (99%) diff --git a/.github/workflows/lint-golang.yml b/.github/workflows/lint-golang.yml index d876aed973571..391b7b43564e4 100644 --- a/.github/workflows/lint-golang.yml +++ b/.github/workflows/lint-golang.yml @@ -20,14 +20,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Setup go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: stable cache-dependency-path: src/go/rpk/go.mod - name: Run golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v9 with: version: latest args: --timeout 10m --verbose diff --git a/src/go/.goreleaser.yaml b/src/go/.goreleaser.yaml index 0fe03298f1e17..5ff0caa7fa41b 100644 --- a/src/go/.goreleaser.yaml +++ b/src/go/.goreleaser.yaml @@ -9,7 +9,7 @@ builds: - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}} - - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}} + - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}} env: - CGO_ENABLED=0 goos: @@ -26,7 +26,7 @@ builds: - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}} - - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}} + - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}} env: - 'CGO_ENABLED={{ if index .Env "CGO_ENABLED" }}{{ .Env.CGO_ENABLED }}{{ else }}0{{ end }}' tags: @@ -44,7 +44,7 @@ builds: - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}} - - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}} + - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}} env: - CGO_ENABLED=0 goos: @@ -60,7 +60,7 @@ builds: - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}} - - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}} + - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}} env: - CGO_ENABLED=0 goos: @@ -76,7 +76,7 @@ builds: - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}} - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}} - - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}} + - -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}} env: - CGO_ENABLED=0 goos: diff --git a/src/go/rpk/.golangci.yml b/src/go/rpk/.golangci.yml index 0345c5aebd86f..610e9c376ef24 100644 --- a/src/go/rpk/.golangci.yml +++ b/src/go/rpk/.golangci.yml @@ -1,26 +1,15 @@ +version: "2" run: - allow-parallel-runners: true tests: false - -# golangci-lint by default ignores some staticcheck and vet raised issues that -# are actually important to catch. The following ensures that we do not ignore -# those tools ever. -issues: - exclude-use-default: false - -# We opt out of all suggested linters and manually pick what we want. -# Please do not use enable-all. + allow-parallel-runners: true linters: - disable-all: true + # golangci-lint by default ignores some staticcheck and vet raised issues that + # are actually important to catch. The following ensures that we do not ignore + # those tools ever. + default: none + # We opt out of all suggested linters and manually pick what we want. + # Please do not use enable-all. enable: - # Enabled by default linters: - - gosimple - - govet - - ineffassign - - staticcheck - - typecheck - - unused - # Disabled by default - asciicheck - bidichk - bodyclose @@ -29,79 +18,94 @@ linters: - errname - errorlint - godot - - gofmt - - gofumpt - - goimports - goprintffuncname + - govet + - ineffassign - misspell - nilerr - noctx - nolintlint - revive - - usetesting + - staticcheck - unconvert + - unused + - usetesting - wastedassign - whitespace - -linters-settings: - # We do not want to enforce every usage of fmt.Errorf to use %w. - errorlint: - errorf: false - - # If we want to opt out of a lint, we require an explanation. - nolintlint: - allow-unused: false - require-explanation: true - require-specific: true - - # Revive is yet another metalinter with a lot of useful lints. - # The below opts in to all the ones we would like to use. - revive: - ignore-generated-header: true - severity: warning - confidence: 0.6 - rules: - - name: atomic - - name: blank-imports - - name: bool-literal-in-expr - - name: call-to-gc - - name: confusing-results - - name: constant-logical-expr - - name: context-as-argument - - name: context-keys-type - - name: defer - - name: dot-imports - - name: duplicated-imports - - name: early-return - - name: error-naming - - name: error-return - - name: error-strings - arguments: - - out.Die - - out.MaybeDie - - out.DieString - - out.MaybeDieString - - name: get-return - - name: identical-branches - - name: if-return - - name: modifies-value-receiver - - name: optimize-operands-order - - name: package-comments - disabled: true # disabling this in favor of https://github.com/redpanda-data/redpanda/issues/6340 - - name: range - - name: range-val-in-closure - - name: receiver-naming - - name: string-of-int - - name: struct-tag - - name: superfluous-else - - name: time-equal - - name: time-naming - - name: unconditional-recursion - - name: unnecessary-stmt - - name: unreachable-code - - name: unused-parameter - - name: unused-receiver - - name: useless-break - - name: var-declaration - - name: var-naming - - name: waitgroup-by-value + settings: + errorlint: + # We do not want to enforce every usage of fmt.Errorf to use %w. + errorf: false + nolintlint: + # If we want to opt out of a lint, we require an explanation. + require-explanation: true + require-specific: true + allow-unused: false + # Revive is yet another metalinter with a lot of useful lints. + # The below opts in to all the ones we would like to use. + revive: + confidence: 0.6 + severity: warning + rules: + - name: atomic + - name: blank-imports + - name: bool-literal-in-expr + - name: call-to-gc + - name: confusing-results + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + - name: defer + - name: dot-imports + - name: duplicated-imports + - name: early-return + - name: error-naming + - name: error-return + - name: error-strings + exclude: ["Redpanda"] + arguments: + - out.Die + - out.MaybeDie + - out.DieString + - out.MaybeDieString + - name: get-return + - name: identical-branches + - name: if-return + - name: modifies-value-receiver + - name: optimize-operands-order + - name: package-comments + disabled: true + - name: range + - name: range-val-in-closure + - name: receiver-naming + - name: string-of-int + - name: struct-tag + - name: superfluous-else + - name: time-equal + - name: time-naming + - name: unconditional-recursion + - name: unnecessary-stmt + - name: unreachable-code + - name: unused-parameter + - name: unused-receiver + - name: useless-break + - name: var-declaration + - name: var-naming + - name: waitgroup-by-value + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/src/go/rpk/Makefile b/src/go/rpk/Makefile index ede7b0d63218d..e620831e69e70 100644 --- a/src/go/rpk/Makefile +++ b/src/go/rpk/Makefile @@ -30,7 +30,7 @@ VER := $(or $(VERSION),local-dev) IMG_TAG:= $(or $(VERSION),latest) BUILD_TIME=$(shell date -Iseconds) VER_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version' -CONT_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common' +CONT_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil' LDFLAGS=-X $(VER_PKG).version=$(VER) -X $(VER_PKG).rev=$(REV) -X $(CONT_PKG).tag=$(IMG_TAG) -X ${VER_PKG}.hostOs=${GOOS} -X ${VER_PKG}.hostArch=${GOARCH} -X ${VER_PKG}.buildTime=${BUILD_TIME} diff --git a/src/go/rpk/build.sh b/src/go/rpk/build.sh index 3e619591132f9..6cb6d9d98a9b0 100755 --- a/src/go/rpk/build.sh +++ b/src/go/rpk/build.sh @@ -22,7 +22,7 @@ out_dir="$(go env GOOS)-$(go env GOARCH)" mkdir -p "${out_dir}" ver_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version' -cont_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common' +cont_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil' go build \ -ldflags "-X ${ver_pkg}.version=${version} -X ${ver_pkg}.rev=${rev} -X ${cont_pkg}.tag=${img_tag} -X ${ver_pkg}.buildTime=${buildTime} -X ${ver_pkg}.hostOs=${hostOs} -X ${ver_pkg}.hostArch=${hostArch}" \ diff --git a/src/go/rpk/cmd/rpk/BUILD b/src/go/rpk/cmd/rpk/BUILD index 261295600e8ef..9e54af3e11148 100644 --- a/src/go/rpk/cmd/rpk/BUILD +++ b/src/go/rpk/cmd/rpk/BUILD @@ -21,7 +21,7 @@ go_binary( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version": "{STABLE_GIT_LATEST_TAG}", "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev": "{STABLE_GIT_COMMIT}", "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime": "{FORMATTED_DATE}", - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag": "{STABLE_GIT_LATEST_TAG}", + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag": "{STABLE_GIT_LATEST_TAG}", }, ) diff --git a/src/go/rpk/pkg/cli/cloud/BUILD b/src/go/rpk/pkg/cli/cloud/BUILD index fc9d4ff43a61f..b9e3a3f1018a6 100644 --- a/src/go/rpk/pkg/cli/cloud/BUILD +++ b/src/go/rpk/pkg/cli/cloud/BUILD @@ -15,12 +15,12 @@ go_library( "//src/go/rpk/pkg/cli/cloud/cluster", "//src/go/rpk/pkg/cli/cloud/mcp", "//src/go/rpk/pkg/cli/cloud/resourcegroup", - "//src/go/rpk/pkg/cli/container/common", + "//src/go/rpk/pkg/cli/container/containerutil", "//src/go/rpk/pkg/cli/profile", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth", "//src/go/rpk/pkg/oauth/providers/auth0", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", diff --git a/src/go/rpk/pkg/cli/cloud/byoc/BUILD b/src/go/rpk/pkg/cli/cloud/byoc/BUILD index dc01170fc0093..68353a20e3433 100644 --- a/src/go/rpk/pkg/cli/cloud/byoc/BUILD +++ b/src/go/rpk/pkg/cli/cloud/byoc/BUILD @@ -14,7 +14,7 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth", "//src/go/rpk/pkg/oauth/providers/auth0", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/plugin", "//src/go/rpk/pkg/publicapi", diff --git a/src/go/rpk/pkg/cli/cloud/byoc/install.go b/src/go/rpk/pkg/cli/cloud/byoc/install.go index 1356146fa7c48..1653db59c0976 100644 --- a/src/go/rpk/pkg/cli/cloud/byoc/install.go +++ b/src/go/rpk/pkg/cli/cloud/byoc/install.go @@ -22,7 +22,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/plugin" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi" diff --git a/src/go/rpk/pkg/cli/cloud/login.go b/src/go/rpk/pkg/cli/cloud/login.go index 38127de08f700..3e5a9dc2b438e 100644 --- a/src/go/rpk/pkg/cli/cloud/login.go +++ b/src/go/rpk/pkg/cli/cloud/login.go @@ -12,7 +12,7 @@ package cloud import ( "fmt" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/profile" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth" @@ -137,7 +137,7 @@ rpk will talk to a localhost:9092 cluster until you swap to a different profile. // unless the user used --no-profile. if noProfile { // The current profile is seemingly pointing to a container cluster. - if p.Name == common.ContainerProfileName { + if p.Name == containerutil.ContainerProfileName { fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)\n", p.Name) fmt.Println("To talk to a cloud cluster, use 'rpk cloud cluster select'.") return @@ -158,7 +158,7 @@ rpk will talk to a localhost:9092 cluster until you swap to a different profile. return } - if p.Name == common.ContainerProfileName { + if p.Name == containerutil.ContainerProfileName { fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)\n", p.Name) } else { fmt.Printf("You are talking to a self hosted cluster (rpk profile name: %q)\n", p.Name) diff --git a/src/go/rpk/pkg/cli/cloud/logout.go b/src/go/rpk/pkg/cli/cloud/logout.go index 0ef786ed854a3..5bda21ab6cd39 100644 --- a/src/go/rpk/pkg/cli/cloud/logout.go +++ b/src/go/rpk/pkg/cli/cloud/logout.go @@ -13,7 +13,7 @@ import ( "fmt" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" diff --git a/src/go/rpk/pkg/cli/cloud/mcp/BUILD b/src/go/rpk/pkg/cli/cloud/mcp/BUILD index 3c824973c2b23..9c30783dd3932 100644 --- a/src/go/rpk/pkg/cli/cloud/mcp/BUILD +++ b/src/go/rpk/pkg/cli/cloud/mcp/BUILD @@ -10,7 +10,7 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth/authtoken", "//src/go/rpk/pkg/oauth/providers/auth0", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/publicapi", "@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/controlplane/v1:controlplane", diff --git a/src/go/rpk/pkg/cli/cloud/mcp/mcp.go b/src/go/rpk/pkg/cli/cloud/mcp/mcp.go index e4b010884a1f6..262528807edf9 100644 --- a/src/go/rpk/pkg/cli/cloud/mcp/mcp.go +++ b/src/go/rpk/pkg/cli/cloud/mcp/mcp.go @@ -26,7 +26,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/authtoken" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi" "github.com/spf13/afero" @@ -61,14 +61,14 @@ Writes an mcpServer entry with name "redpandaCloud" into the appropriate config Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { cfg, err := p.Load(fs) - out.MaybeDie(err, "Failed to load rpk config: %w", err) + out.MaybeDie(err, "failed to load rpk config: %w", err) args := []string{"cloud", "mcp", "stdio"} if allowDelete { args = append(args, "--allow-delete") } configFile, err := installMCPConfig(cfg, mcpClient, "redpandaCloud", args) - out.MaybeDie(err, "Failed to install MCP configuration: %v", err) + out.MaybeDie(err, "failed to install MCP configuration: %v", err) fmt.Printf("Successfully installed Redpanda Cloud MCP server to %s.\n", makePathPretty(configFile)) }, } @@ -90,14 +90,14 @@ func newStdioCommand(fs afero.Fs, p *config.Params) *cobra.Command { Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { cfg, err := p.Load(fs) - out.MaybeDie(err, "Failed to load config: %w", err) + out.MaybeDie(err, "failed to load config: %w", err) // Start out with empty token, and use the maybeReloadToken function to update. cl := publicapi.NewCloudClientSet(cfg.DevOverrides().PublicAPIURL, "") // Create dataplane client set with dynamic transport for MCP dataplaneClientSet, err := publicapi.NewDataPlaneClientSet("", "") - out.MaybeDie(err, "Failed to create dataplane client set: %v", err) + out.MaybeDie(err, "failed to create dataplane client set: %v", err) var m sync.RWMutex var tokenOK bool @@ -228,7 +228,7 @@ Use --install to configure the MCP client instead of serving stdio.`, }, Run: func(cmd *cobra.Command, _ []string) { cfg, err := p.Load(fs) - out.MaybeDie(err, "Failed to load config: %w", err) + out.MaybeDie(err, "failed to load config: %w", err) authToken := cfg.VirtualProfile().CurrentAuth().AuthToken @@ -243,30 +243,30 @@ Use --install to configure the MCP client instead of serving stdio.`, cluster, err := cl.Cluster.GetCluster(cmd.Context(), connect.NewRequest(&controlplanev1.GetClusterRequest{ Id: clusterID, })) - out.MaybeDie(err, "Failed to get cluster: %v", err) + out.MaybeDie(err, "failed to get cluster: %v", err) dataplaneURL = cluster.Msg.GetCluster().GetDataplaneApi().GetUrl() actualClusterID = clusterID if dataplaneURL == "" { - out.Die("Cluster %s does not have a dataplane API URL", clusterID) + out.Die("cluster %s does not have a dataplane API URL", clusterID) } } else { // Serverless cluster serverlessCluster, err := cl.Serverless.GetServerlessCluster(cmd.Context(), connect.NewRequest(&controlplanev1.GetServerlessClusterRequest{ Id: serverlessClusterID, })) - out.MaybeDie(err, "Failed to get serverless cluster: %v", err) + out.MaybeDie(err, "failed to get serverless cluster: %v", err) dataplaneURL = serverlessCluster.Msg.GetServerlessCluster().GetDataplaneApi().GetUrl() actualClusterID = serverlessClusterID if dataplaneURL == "" { - out.Die("Serverless cluster %s does not have a dataplane API URL", serverlessClusterID) + out.Die("serverless cluster %s does not have a dataplane API URL", serverlessClusterID) } } // Create a dataplane client set for this specific dataplane dataplaneClient, err := publicapi.NewDataPlaneClientSet(dataplaneURL, authToken) - out.MaybeDie(err, "Failed to create dataplane client: %v", err) + out.MaybeDie(err, "failed to create dataplane client: %v", err) var m sync.RWMutex var tokenOK bool @@ -312,7 +312,7 @@ Use --install to configure the MCP client instead of serving stdio.`, mcpServer, err := dataplaneClient.MCPServer.GetMCPServer(cmd.Context(), connect.NewRequest(&dataplanev1alpha3.GetMCPServerRequest{ Id: mcpServerID, })) - out.MaybeDie(err, "Failed to get MCP server: %v", err) + out.MaybeDie(err, "failed to get MCP server: %v", err) mcpServerURL := mcpServer.Msg.GetMcpServer().GetUrl() if mcpServerURL == "" { @@ -336,7 +336,7 @@ Use --install to configure the MCP client instead of serving stdio.`, args = append(args, "--mcp-server-id", mcpServerID) configFile, err := installMCPConfig(cfg, mcpClient, mcpServerName, args) - out.MaybeDie(err, "Failed to install MCP configuration: %v", err) + out.MaybeDie(err, "failed to install MCP configuration: %v", err) fmt.Printf("Successfully installed MCP server for '%s' (cluster: %s, server: %s) to %s.\n", mcpServerName, actualClusterID, mcpServerID, makePathPretty(configFile)) return } @@ -353,13 +353,13 @@ Use --install to configure the MCP client instead of serving stdio.`, } }), ) - out.MaybeDie(err, "Failed to create remote MCP client: %v", err) + out.MaybeDie(err, "failed to create remote MCP client: %v", err) defer remoteClient.Close() // Initialize the remote client fmt.Fprintf(os.Stderr, "Starting remote MCP client\n") if err := remoteClient.Start(cmd.Context()); err != nil { - out.MaybeDie(err, "Failed to start remote MCP client: %v", err) + out.MaybeDie(err, "failed to start remote MCP client: %v", err) } initRequest := mcp.InitializeRequest{} @@ -372,7 +372,7 @@ Use --install to configure the MCP client instead of serving stdio.`, fmt.Fprintf(os.Stderr, "Initializing remote MCP client\n") _, err = remoteClient.Initialize(cmd.Context(), initRequest) - out.MaybeDie(err, "Failed to initialize remote MCP client: %v", err) + out.MaybeDie(err, "failed to initialize remote MCP client: %v", err) // Create local MCP server that will proxy to the remote client var clusterType string @@ -397,7 +397,7 @@ Use --install to configure the MCP client instead of serving stdio.`, // Add all tools from remote server to local server // Currently this is static and will not add/remove tools at runtime. if err := addRemoteToolsToServer(cmd.Context(), remoteClient, localServer); err != nil { - out.MaybeDie(err, "Failed to register remote tools: %v", err) + out.MaybeDie(err, "failed to register remote tools: %v", err) } fmt.Fprintf(os.Stderr, "Proxy server ready, starting stdio server\n") diff --git a/src/go/rpk/pkg/cli/cluster/config/edit.go b/src/go/rpk/pkg/cli/cluster/config/edit.go index fb52f0b21808f..255b96e5b1ce7 100644 --- a/src/go/rpk/pkg/cli/cluster/config/edit.go +++ b/src/go/rpk/pkg/cli/cluster/config/edit.go @@ -116,7 +116,7 @@ func executeEdit( if err != nil { return fmt.Errorf("error opening file %s on editor %s: %v", filename, editor, err) } - child := exec.Command(eArgs[0], eArgs[1:]...) + child := exec.CommandContext(ctx, eArgs[0], eArgs[1:]...) child.Stdout = os.Stdout child.Stderr = os.Stderr child.Stdin = os.Stdin diff --git a/src/go/rpk/pkg/cli/cluster/config/export.go b/src/go/rpk/pkg/cli/cluster/config/export.go index 09232fffab456..df8717254c902 100644 --- a/src/go/rpk/pkg/cli/cluster/config/export.go +++ b/src/go/rpk/pkg/cli/cluster/config/export.go @@ -95,7 +95,7 @@ func exportConfig( fmt.Fprintf(&sb, "%s: []", name) } default: - out.Die("Unexpected property value type: %s: %T", name, curValue) + out.Die("unexpected property value type: %s: %T", name, curValue) } } else { scalarVal := "" @@ -109,7 +109,7 @@ func exportConfig( case nil: // Leave scalarVal empty default: - out.Die("Unexpected property value type: %s: %T", name, curValue) + out.Die("unexpected property value type: %s: %T", name, curValue) } if len(scalarVal) > 0 { diff --git a/src/go/rpk/pkg/cli/cluster/config/get.go b/src/go/rpk/pkg/cli/cluster/config/get.go index 72b4ed8d96ec2..fee293ef62c6e 100644 --- a/src/go/rpk/pkg/cli/cluster/config/get.go +++ b/src/go/rpk/pkg/cli/cluster/config/get.go @@ -65,7 +65,7 @@ output, use the 'edit' and 'export' commands respectively.`, val, exists := currentConfig[key] if !exists { - out.Die("Property '%s' not found", key) + out.Die("property '%s' not found", key) } else { // currentConfig is the result of json.Unmarshal into a // map[string]interface{}. Due to json rules, all numbers @@ -81,7 +81,7 @@ output, use the 'edit' and 'export' commands respectively.`, // Intentionally bare output, so that the output can be readily // consumed in a script. bytes, err := yaml.Marshal(val) - out.MaybeDie(err, "Unexpected non-YAML-encodable value %v", val) + out.MaybeDie(err, "unexpected non-YAML-encodable value %v", val) fmt.Print(string(bytes)) } }, diff --git a/src/go/rpk/pkg/cli/cluster/config/import.go b/src/go/rpk/pkg/cli/cluster/config/import.go index 06fcb690ea450..b3fbe3ea6cc83 100644 --- a/src/go/rpk/pkg/cli/cluster/config/import.go +++ b/src/go/rpk/pkg/cli/cluster/config/import.go @@ -249,7 +249,7 @@ func importConfig( fmt.Printf("Successfully updated configuration. New configuration version is %d.\n", result.ConfigVersion) status, err := client.ClusterConfigStatus(ctx, true) - out.MaybeDie(err, "unable to check if the cluster needs to be restarted: %v\nCheck the status with 'rpk cluster config status'.", err) + out.MaybeDie(err, "unable to check if the cluster needs to be restarted: %v; check the status with 'rpk cluster config status'", err) for _, value := range status { if value.Restart { fmt.Print("\nCluster needs to be restarted. See more details with 'rpk cluster config status'.\n") @@ -325,7 +325,7 @@ from the YAML file, it is reset to its default value. `, err = importConfig(cmd.Context(), client, filename, currentConfig, currentFullConfig, schema, all) if fe := (*formattedError)(nil); errors.As(err, &fe) { fmt.Fprint(os.Stderr, err) - out.Die("No changes were made") + out.Die("no changes were made") } out.MaybeDie(err, "error updating config: %v", err) }, diff --git a/src/go/rpk/pkg/cli/cluster/config/reset.go b/src/go/rpk/pkg/cli/cluster/config/reset.go index de7deed42cd37..a025759321c92 100644 --- a/src/go/rpk/pkg/cli/cluster/config/reset.go +++ b/src/go/rpk/pkg/cli/cluster/config/reset.go @@ -69,7 +69,7 @@ WARNING: this should only be used when redpanda is not running. // Encode output outBytes, err := yaml.Marshal(content) - out.MaybeDie(err, "Serialization error: %v", configCacheFile, err) + out.MaybeDie(err, "serialization error: %v", configCacheFile, err) // Write back output err = afero.WriteFile(fs, configCacheFile, outBytes, 0o755) diff --git a/src/go/rpk/pkg/cli/cluster/config/set.go b/src/go/rpk/pkg/cli/cluster/config/set.go index 25002c131a33c..524d2a15cc763 100644 --- a/src/go/rpk/pkg/cli/cluster/config/set.go +++ b/src/go/rpk/pkg/cli/cluster/config/set.go @@ -124,9 +124,10 @@ Use the flag '--no-confirm' to avoid the confirmation prompt.`, // Handle the result based on state state := finalOp.GetState() if completedInTime { - if state == controlplanev1.Operation_STATE_COMPLETED { + switch state { + case controlplanev1.Operation_STATE_COMPLETED: fmt.Printf("Configuration update completed successfully. Operation ID: %s\n", operationID) - } else if state == controlplanev1.Operation_STATE_FAILED { + case controlplanev1.Operation_STATE_FAILED: fmt.Printf("Configuration update failed. Operation ID: %s\n", operationID) } } else { @@ -151,7 +152,7 @@ Use the flag '--no-confirm' to avoid the confirmation prompt.`, if he.Response.StatusCode == 400 { ve, err := formatValidationError(err, he) out.MaybeDie(err, "error setting config: %v", err) - out.Die("No changes were made: %v", ve) + out.Die("no changes were made: %v", ve) } } @@ -159,7 +160,7 @@ Use the flag '--no-confirm' to avoid the confirmation prompt.`, fmt.Printf("Successfully updated configuration. New configuration version is %d.\n", result.ConfigVersion) status, err := client.ClusterConfigStatus(cmd.Context(), true) - out.MaybeDie(err, "unable to check if the cluster needs to be restarted: %v\nCheck the status with 'rpk cluster config status'.", err) + out.MaybeDie(err, "unable to check if the cluster needs to be restarted: %v; check the status with 'rpk cluster config status'", err) for _, value := range status { if value.Restart { fmt.Print("\nCluster needs to be restarted. See more details with 'rpk cluster config status'.\n") @@ -189,7 +190,7 @@ func validateConfigSelfHosted(schema rpadmin.ConfigSchema, args []string, noConf confirmed, err := out.Confirm("Warning: disabling Tiered Storage may lead to data loss. If you only want to pause Tiered Storage temporarily, use the 'cloud_storage_enable_segment_uploads' option. Abort?") out.MaybeDie(err, "unable to read user input: %v", err) if confirmed { - out.Die("Aborted by user.") + out.Die("aborted by user") } } } diff --git a/src/go/rpk/pkg/cli/cluster/maintenance/disable.go b/src/go/rpk/pkg/cli/cluster/maintenance/disable.go index a26eff2b07873..c77d1535f197d 100644 --- a/src/go/rpk/pkg/cli/cluster/maintenance/disable.go +++ b/src/go/rpk/pkg/cli/cluster/maintenance/disable.go @@ -46,7 +46,7 @@ func newDisableCommand(fs afero.Fs, p *config.Params) *cobra.Command { out.MaybeDie(err, "unable to initialize admin client: %v", err) b, err := client.Broker(cmd.Context(), nodeID) - out.MaybeDie(err, "error retrieving broker status. The node %d is likely dead?: %v\n", nodeID, err) + out.MaybeDie(err, "error retrieving broker status; the node %d is likely dead: %v", nodeID, err) if b.Maintenance == nil { out.Die("maintenance mode not supported or upgrade in progress?") @@ -57,7 +57,7 @@ func newDisableCommand(fs afero.Fs, p *config.Params) *cobra.Command { if he.Response.StatusCode == 404 { body, bodyErr := he.DecodeGenericErrorBody() if bodyErr == nil { - out.Die("Not found: %s", body.Message) + out.Die("not found: %s", body.Message) } } } diff --git a/src/go/rpk/pkg/cli/cluster/maintenance/enable.go b/src/go/rpk/pkg/cli/cluster/maintenance/enable.go index 81e5ece42e072..6d6ca1f626e2f 100644 --- a/src/go/rpk/pkg/cli/cluster/maintenance/enable.go +++ b/src/go/rpk/pkg/cli/cluster/maintenance/enable.go @@ -63,15 +63,16 @@ node exists that is already in maintenance mode then an error will be returned. err = client.EnableMaintenanceMode(cmd.Context(), nodeID) var he *rpadmin.HTTPResponseError if errors.As(err, &he) { - if he.Response.StatusCode == 404 { + switch he.Response.StatusCode { + case 404: body, bodyErr := he.DecodeGenericErrorBody() if bodyErr == nil { - out.Die("Not found: %s", body.Message) + out.Die("not found: %s", body.Message) } - } else if he.Response.StatusCode == 400 { + case 400: body, bodyErr := he.DecodeGenericErrorBody() if bodyErr == nil { - out.Die("Cannot enable maintenance mode: %s", body.Message) + out.Die("cannot enable maintenance mode: %s", body.Message) } } } @@ -101,7 +102,7 @@ node exists that is already in maintenance mode then an error will be returned. } if err != nil { if retries <= 0 { - out.Die("Error retrieving broker status while watching the progress: %v", err) + out.Die("error retrieving broker status while watching the progress: %v", err) } retries-- time.Sleep(time.Second * 2) diff --git a/src/go/rpk/pkg/cli/cluster/maintenance/status.go b/src/go/rpk/pkg/cli/cluster/maintenance/status.go index 7dba2a1fab620..14416728e66a5 100644 --- a/src/go/rpk/pkg/cli/cluster/maintenance/status.go +++ b/src/go/rpk/pkg/cli/cluster/maintenance/status.go @@ -94,11 +94,11 @@ Notes: out.MaybeDie(err, "unable to request brokers: %v", err) if len(brokers) == 0 { - out.Die("No brokers found. Check broker address configuration.") + out.Die("no brokers found; check broker address configuration") } if brokers[0].Maintenance == nil { - out.Die("Maintenance mode is not supported in this cluster") + out.Die("maintenance mode is not supported in this cluster") } table := newMaintenanceReportTable() diff --git a/src/go/rpk/pkg/cli/cluster/partitions/move_status.go b/src/go/rpk/pkg/cli/cluster/partitions/move_status.go index 69944b423eabc..5638fc176272b 100644 --- a/src/go/rpk/pkg/cli/cluster/partitions/move_status.go +++ b/src/go/rpk/pkg/cli/cluster/partitions/move_status.go @@ -45,14 +45,14 @@ func newPartitionMovementsStatusCommand(fs afero.Fs, p *config.Params) *cobra.Co // If partition(s) is specified but no topic(s) is specified, exit. if len(topics) <= 0 && len(partitions) > 0 { - out.Die("specify at least one topic when --partition is used, exiting.") + out.Die("specify at least one topic when --partition is used, exiting") } cl, err := adminapi.NewClient(cmd.Context(), fs, p) out.MaybeDie(err, "unable to initialize admin client: %v", err) response, err = cl.Reconfigurations(cmd.Context()) - out.MaybeDie(err, "unable to list partition movements: %v\n", err) + out.MaybeDie(err, "unable to list partition movements: %v", err) if len(response) == 0 { out.Exit("There are no ongoing partition movements.") diff --git a/src/go/rpk/pkg/cli/cluster/partitions/transfer_leadership.go b/src/go/rpk/pkg/cli/cluster/partitions/transfer_leadership.go index 2c814b12bbcd8..34225325b82ae 100644 --- a/src/go/rpk/pkg/cli/cluster/partitions/transfer_leadership.go +++ b/src/go/rpk/pkg/cli/cluster/partitions/transfer_leadership.go @@ -68,12 +68,12 @@ brokers automatically. if len(topicArg) > 0 { // foo -p 0:1 _, _, partition, target, err := extractNTPTarget(topicArg[0], partitionArg) - out.MaybeDie(err, "failed to extract topic/partition: %s\n", err) + out.MaybeDie(err, "failed to extract topic/partition: %s", err) ns, topic := formatNT(topicArg[0]) partDetails, err := cl.GetPartition(cmd.Context(), ns, topic, partition) - out.MaybeDie(err, "failed to get partition details: %s\n", err) + out.MaybeDie(err, "failed to get partition details: %s", err) source := partDetails.LeaderID @@ -85,10 +85,10 @@ brokers automatically. } } else { // -p foo/0:1 ns, topic, partition, target, err := extractNTPTarget("", partitionArg) - out.MaybeDie(err, "failed to extract topic/partition: %s\n", err) + out.MaybeDie(err, "failed to extract topic/partition: %s", err) partDetails, err := cl.GetPartition(cmd.Context(), ns, topic, partition) - out.MaybeDie(err, "failed to get partition details: %s\n", err) + out.MaybeDie(err, "failed to get partition details: %s", err) source := partDetails.LeaderID diff --git a/src/go/rpk/pkg/cli/cluster/partitions/unsafe_recover.go b/src/go/rpk/pkg/cli/cluster/partitions/unsafe_recover.go index 140dbc4e6952e..3727f832b4ba5 100644 --- a/src/go/rpk/pkg/cli/cluster/partitions/unsafe_recover.go +++ b/src/go/rpk/pkg/cli/cluster/partitions/unsafe_recover.go @@ -44,7 +44,7 @@ using the '--dry' flag. Run: func(cmd *cobra.Command, _ []string) { f := p.Formatter if f.Kind != "text" && f.Kind != "help" && !dry { - out.Die("Format type %q is only valid for dry runs (--dry)", f.Kind) + out.Die("format type %q is only valid for dry runs (--dry)", f.Kind) } if h, ok := f.Help([]rpadmin.MajorityLostPartitions{}); ok { out.Exit(h) diff --git a/src/go/rpk/pkg/cli/cluster/storage/mount.go b/src/go/rpk/pkg/cli/cluster/storage/mount.go index 8b07a74638971..24cb830fd3703 100644 --- a/src/go/rpk/pkg/cli/cluster/storage/mount.go +++ b/src/go/rpk/pkg/cli/cluster/storage/mount.go @@ -62,10 +62,10 @@ with my-new-topic as the new topic name var id int if p.CheckFromCloud() { if ns != "" && strings.ToLower(ns) != "kafka" { - out.Die("Namespace %q not allowed. Only kafka topics can be mounted in Redpanda Cloud clusters", ns) + out.Die("namespace %q not allowed; only kafka topics can be mounted in Redpanda Cloud clusters", ns) } if an != "" && strings.ToLower(an) != "kafka" { - out.Die("Failed to parse '--to' flag: namespace %q not allowed. Only kafka topics can be mounted in Redpanda Cloud clusters", an) + out.Die("failed to parse '--to' flag: namespace %q not allowed; only kafka topics can be mounted in Redpanda Cloud clusters", an) } cl, err := publicapi.DataplaneClientFromRpkProfile(p) out.MaybeDie(err, "unable to initialize cloud client: %v", err) diff --git a/src/go/rpk/pkg/cli/cluster/storage/recovery/start.go b/src/go/rpk/pkg/cli/cluster/storage/recovery/start.go index d6b42417bf3f7..d4a79a06d9013 100644 --- a/src/go/rpk/pkg/cli/cluster/storage/recovery/start.go +++ b/src/go/rpk/pkg/cli/cluster/storage/recovery/start.go @@ -56,15 +56,16 @@ to restore from. For more information, visit https://docs.redpanda.com/current/m _, err = client.StartAutomatedRecovery(ctx, uuidOverride) var he *rpadmin.HTTPResponseError if errors.As(err, &he) { - if he.Response.StatusCode == 404 { + switch he.Response.StatusCode { + case 404: body, bodyErr := he.DecodeGenericErrorBody() if bodyErr == nil { - out.Die("Not found: %s", body.Message) + out.Die("not found: %s", body.Message) } - } else if he.Response.StatusCode == 400 { + case 400: body, bodyErr := he.DecodeGenericErrorBody() if bodyErr == nil { - out.Die("Cannot start topic recovery: %s", body.Message) + out.Die("cannot start topic recovery: %s", body.Message) } } } diff --git a/src/go/rpk/pkg/cli/cluster/storage/unmount.go b/src/go/rpk/pkg/cli/cluster/storage/unmount.go index 36fd6e8ee3bf5..ad0f20d717680 100644 --- a/src/go/rpk/pkg/cli/cluster/storage/unmount.go +++ b/src/go/rpk/pkg/cli/cluster/storage/unmount.go @@ -62,7 +62,7 @@ Unmount topic 'my-topic' from the cluster in the 'my-namespace' var id int if p.CheckFromCloud() { if ns != "" && strings.ToLower(ns) != "kafka" { - out.Die("Namespace %q not allowed. Only kafka topics can be unmounted in Redpanda Cloud clusters", ns) + out.Die("namespace %q not allowed; only kafka topics can be unmounted in Redpanda Cloud clusters", ns) } cl, err := publicapi.DataplaneClientFromRpkProfile(p) out.MaybeDie(err, "unable to initialize cloud client: %v", err) diff --git a/src/go/rpk/pkg/cli/connect/BUILD b/src/go/rpk/pkg/cli/connect/BUILD index d842a7ed101ef..7ddfc0f410350 100644 --- a/src/go/rpk/pkg/cli/connect/BUILD +++ b/src/go/rpk/pkg/cli/connect/BUILD @@ -16,7 +16,7 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/fips", "//src/go/rpk/pkg/httpapi", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/plugin", "//src/go/rpk/pkg/redpanda", diff --git a/src/go/rpk/pkg/cli/connect/connect.go b/src/go/rpk/pkg/cli/connect/connect.go index b15ea52526816..f863006362169 100644 --- a/src/go/rpk/pkg/cli/connect/connect.go +++ b/src/go/rpk/pkg/cli/connect/connect.go @@ -71,7 +71,7 @@ func NewCommand(fs afero.Fs, p *config.Params, execFn func(string, []string) err } fmt.Fprintln(os.Stderr, "Downloading latest Redpanda Connect") path, _, err := installConnect(cmd.Context(), fs, "latest") - out.MaybeDie(err, "unable to install Redpanda Connect: %v; if running on an air-gapped environment you may install 'redpanda-connect' with your package manager.", err) + out.MaybeDie(err, "unable to install Redpanda Connect: %v; if running in an air-gapped environment you may install 'redpanda-connect' with your package manager", err) pluginPath = path } if pluginExists { diff --git a/src/go/rpk/pkg/cli/connect/install.go b/src/go/rpk/pkg/cli/connect/install.go index 1cea01ee901d3..7b687c5d68da3 100644 --- a/src/go/rpk/pkg/cli/connect/install.go +++ b/src/go/rpk/pkg/cli/connect/install.go @@ -16,7 +16,7 @@ import ( "regexp" "strings" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/plugin" "github.com/spf13/afero" @@ -51,10 +51,10 @@ You may force the installation of Redpanda Connect using the --force flag. if version != "latest" { out.Exit("Redpanda connect is already installed. Use --force to force installation, or delete current version with 'rpk connect uninstall' first") } - out.Exit("Redpanda connect is already installed.\nIf you want to upgrade to the latest version, please run 'rpk connect upgrade'.") + out.Exit("Redpanda connect is already installed.\nIf you want to upgrade to the latest version, please run 'rpk connect upgrade'") } _, installedVersion, err := installConnect(cmd.Context(), fs, version) - out.MaybeDie(err, "unable to install Redpanda Connect: %v; if running on an air-gapped environment you may install 'redpanda-connect' with your package manager.", err) + out.MaybeDie(err, "unable to install Redpanda Connect: %v; if running in an air-gapped environment you may install 'redpanda-connect' with your package manager", err) fmt.Printf("Redpanda Connect %v successfully installed.\n", installedVersion) }, diff --git a/src/go/rpk/pkg/cli/connect/upgrade.go b/src/go/rpk/pkg/cli/connect/upgrade.go index 58ea3945c83fe..5e9ff33dc3fde 100644 --- a/src/go/rpk/pkg/cli/connect/upgrade.go +++ b/src/go/rpk/pkg/cli/connect/upgrade.go @@ -34,14 +34,14 @@ func upgradeCommand(fs afero.Fs) *cobra.Command { out.MaybeDie(err, "unable to determine managed plugin path: %w", err) connect, pluginExists := plugin.ListPlugins(fs, plugin.UserPaths()).Find("connect") if !pluginExists { - out.Die("Redpanda Connect plugin not found. You may install it running 'rpk connect install'") + out.Die("unable to find Redpanda Connect plugin. You may install it running 'rpk connect install'") } // A user may have installed version of 'rpk connect' either // manually or using a package manager (air-gapped). An attempt to // upgrade can result in having multiple copies of connect. Instead, // we kindly ask to re-install. if !connect.Managed { - out.Die("Found a self-managed Redpanda Connect plugin; unfortunately, we cannot upgrade it with this installation. Run rpk connect uninstall && rpk connect install, or to continue managing Connect manually, use our redpanda-connect package.") + out.Die("found a self-managed Redpanda Connect plugin; unfortunately, we cannot upgrade it with this installation. Run rpk connect uninstall && rpk connect install, or to continue managing Connect manually, use our redpanda-connect package") } art, version, err := getConnectArtifact(cmd.Context(), "latest") out.MaybeDieErr(err) diff --git a/src/go/rpk/pkg/cli/container/BUILD b/src/go/rpk/pkg/cli/container/BUILD index 4219ff76bdc06..48449ecd35204 100644 --- a/src/go/rpk/pkg/cli/container/BUILD +++ b/src/go/rpk/pkg/cli/container/BUILD @@ -12,11 +12,11 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container", visibility = ["//visibility:public"], deps = [ - "//src/go/rpk/pkg/cli/container/common", + "//src/go/rpk/pkg/cli/container/containerutil", "//src/go/rpk/pkg/cli/profile", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/httpapi", - "//src/go/rpk/pkg/net", + "//src/go/rpk/pkg/netutil", "//src/go/rpk/pkg/out", "@com_github_avast_retry_go//:retry-go", "@com_github_docker_docker//api/types/container", diff --git a/src/go/rpk/pkg/cli/container/common/BUILD b/src/go/rpk/pkg/cli/container/containerutil/BUILD similarity index 93% rename from src/go/rpk/pkg/cli/container/common/BUILD rename to src/go/rpk/pkg/cli/container/containerutil/BUILD index da115e319710d..2f5d78e2d2b5a 100644 --- a/src/go/rpk/pkg/cli/container/common/BUILD +++ b/src/go/rpk/pkg/cli/container/containerutil/BUILD @@ -1,14 +1,14 @@ load("@rules_go//go:def.bzl", "go_library") go_library( - name = "common", + name = "containerutil", srcs = [ "client.go", "common.go", "context.go", "test.go", ], - importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common", + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil", visibility = ["//visibility:public"], deps = [ "//src/go/rpk/pkg/config", diff --git a/src/go/rpk/pkg/cli/container/common/client.go b/src/go/rpk/pkg/cli/container/containerutil/client.go similarity index 99% rename from src/go/rpk/pkg/cli/container/common/client.go rename to src/go/rpk/pkg/cli/container/containerutil/client.go index 3d6cd7bfce7e6..ed7adb267eab6 100644 --- a/src/go/rpk/pkg/cli/container/common/client.go +++ b/src/go/rpk/pkg/cli/container/containerutil/client.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package common +package containerutil import ( "context" diff --git a/src/go/rpk/pkg/cli/container/common/common.go b/src/go/rpk/pkg/cli/container/containerutil/common.go similarity index 93% rename from src/go/rpk/pkg/cli/container/common/common.go rename to src/go/rpk/pkg/cli/container/containerutil/common.go index a54ec65a8ddb5..d5cf0c3ce3688 100644 --- a/src/go/rpk/pkg/cli/container/common/common.go +++ b/src/go/rpk/pkg/cli/container/containerutil/common.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package common +package containerutil import ( "bytes" @@ -95,11 +95,10 @@ func DefaultCtx() (context.Context, context.CancelFunc) { return context.WithTimeout(context.Background(), defaultDockerClientTimeout) } -func GetExistingNodes(c Client) ([]*NodeState, error) { +func GetExistingNodes(ctx context.Context, c Client) ([]*NodeState, error) { regExp := `^/rp-((node-[\d])|console)+` filters := filters.NewArgs() filters.Add("name", regExp) - ctx, _ := DefaultCtx() containers, err := c.ContainerList( ctx, container.ListOptions{ @@ -132,7 +131,7 @@ func GetExistingNodes(c Client) ([]*NodeState, error) { } } - nodes[i], err = GetState(c, uint(nodeID), isConsole) + nodes[i], err = GetState(ctx, c, uint(nodeID), isConsole) if err != nil { return nil, err } @@ -140,8 +139,7 @@ func GetExistingNodes(c Client) ([]*NodeState, error) { return nodes, nil } -func GetState(c Client, nodeID uint, isConsole bool) (*NodeState, error) { - ctx, _ := DefaultCtx() +func GetState(ctx context.Context, c Client, nodeID uint, isConsole bool) (*NodeState, error) { name := RedpandaName(nodeID) if isConsole { name = ConsoleContainerName @@ -223,9 +221,7 @@ func GetState(c Client, nodeID uint, isConsole bool) (*NodeState, error) { // CreateNetwork Creates a network for the cluster's containers and returns its // ID. If it exists already, it returns the existing network's ID. -func CreateNetwork(c Client, subnet, gateway string) (string, error) { - ctx, _ := DefaultCtx() - +func CreateNetwork(ctx context.Context, c Client, subnet, gateway string) (string, error) { args := filters.NewArgs() args.Add("name", redpandaNetwork) networks, err := c.NetworkList( @@ -267,8 +263,7 @@ func CreateNetwork(c Client, subnet, gateway string) (string, error) { } // RemoveNetwork deletes the Redpanda network if it exists. -func RemoveNetwork(c Client) error { - ctx, _ := DefaultCtx() +func RemoveNetwork(ctx context.Context, c Client) error { err := c.NetworkRemove(ctx, redpandaNetwork) if c.IsErrNotFound(err) { return nil @@ -277,6 +272,7 @@ func RemoveNetwork(c Client) error { } func CreateNode( + ctx context.Context, c Client, nodeID, kafkaPort, proxyPort, schemaRegPort, rpcPort, adminPort uint, netID, image string, @@ -317,7 +313,7 @@ func CreateNode( if err != nil { return nil, err } - ip, err := nodeIP(c, netID, nodeID) + ip, err := nodeIP(ctx, c, netID, nodeID) if err != nil { return nil, err } @@ -380,7 +376,6 @@ func CreateNode( }, } - ctx, _ := DefaultCtx() container, err := c.ContainerCreate( ctx, &containerConfig, @@ -400,11 +395,11 @@ func CreateNode( }, nil } -func PullImage(c Client, img string) error { +func PullImage(ctx context.Context, c Client, img string) error { fmt.Printf("Pulling image: %s\n", img) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + pullCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) defer cancel() - res, err := c.ImagePull(ctx, img, image.PullOptions{}) + res, err := c.ImagePull(pullCtx, img, image.PullOptions{}) if res != nil { defer res.Close() buf := bytes.Buffer{} @@ -414,10 +409,11 @@ func PullImage(c Client, img string) error { if err != nil { return err } - return ctx.Err() + return pullCtx.Err() } func CreateConsoleNode( + ctx context.Context, c Client, nodeID uint, netID, image string, @@ -455,7 +451,7 @@ func CreateConsoleNode( }}, }, } - ip, err := nodeIP(c, netID, nodeID) + ip, err := nodeIP(ctx, c, netID, nodeID) if err != nil { return nil, err } @@ -469,7 +465,6 @@ func CreateConsoleNode( }, }, } - ctx, _ := DefaultCtx() consoleContainer, err := c.ContainerCreate( ctx, &containerConfig, @@ -490,8 +485,7 @@ func CreateConsoleNode( }, nil } -func CheckIfImgPresent(c Client, img string) (bool, error) { - ctx, _ := DefaultCtx() +func CheckIfImgPresent(ctx context.Context, c Client, img string) (bool, error) { imgFilters := filters.NewArgs( filters.Arg("reference", img), ) @@ -524,8 +518,7 @@ func getHostPort( return uint(0), nil } -func nodeIP(c Client, netID string, id uint) (string, error) { - ctx, _ := DefaultCtx() +func nodeIP(ctx context.Context, c Client, netID string, id uint) (string, error) { networkResource, err := c.NetworkInspect(ctx, netID, network.InspectOptions{}) if err != nil { return "", err @@ -555,23 +548,21 @@ func nodeIP(c Client, netID string, id uint) (string, error) { func WrapIfConnErr(err error) error { if client.IsErrConnectionFailed(err) { - msg := `Unable to connect to docker. + return errors.New(`unable to connect to docker. This can happen for a couple of reasons: - The Docker daemon isn't running. - You are running 'rpk container' as a user that cannot execute Docker commands. -- You have not installed Docker. Please follow the instructions at https://docs.docker.com/engine/install/ to install it and then try again. -` - return errors.New(msg) +- You have not installed Docker. Please follow the instructions at https://docs.docker.com/engine/install/ to install it and then try again`) } return err } -func CreateProfile(fs afero.Fs, c Client, y *config.RpkYaml) error { +func CreateProfile(ctx context.Context, fs afero.Fs, c Client, y *config.RpkYaml) error { if p := y.Profile(ContainerProfileName); p != nil { return ErrContainerProfileExists } var kaAddresses, aAddresses, srAddresses []string - existingNodes, err := GetExistingNodes(c) + existingNodes, err := GetExistingNodes(ctx, c) if err != nil { return fmt.Errorf("unable to get the existing nodes: %v", err) } diff --git a/src/go/rpk/pkg/cli/container/common/context.go b/src/go/rpk/pkg/cli/container/containerutil/context.go similarity index 99% rename from src/go/rpk/pkg/cli/container/common/context.go rename to src/go/rpk/pkg/cli/container/containerutil/context.go index f4f7a7f7069b1..5dfe429dfb9f7 100644 --- a/src/go/rpk/pkg/cli/container/common/context.go +++ b/src/go/rpk/pkg/cli/container/containerutil/context.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package common +package containerutil import ( "encoding/json" diff --git a/src/go/rpk/pkg/cli/container/common/test.go b/src/go/rpk/pkg/cli/container/containerutil/test.go similarity index 99% rename from src/go/rpk/pkg/cli/container/common/test.go rename to src/go/rpk/pkg/cli/container/containerutil/test.go index 614a584c6b2a9..fefb113276c8f 100644 --- a/src/go/rpk/pkg/cli/container/common/test.go +++ b/src/go/rpk/pkg/cli/container/containerutil/test.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package common +package containerutil import ( "context" diff --git a/src/go/rpk/pkg/cli/container/purge.go b/src/go/rpk/pkg/cli/container/purge.go index 2b6eb2a5bfe68..d5048c660f643 100644 --- a/src/go/rpk/pkg/cli/container/purge.go +++ b/src/go/rpk/pkg/cli/container/purge.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/api/types/container" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/profile" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" @@ -32,12 +32,12 @@ func newPurgeCommand(fs afero.Fs, p *config.Params) *cobra.Command { Short: "Stop and remove an existing local container cluster's data", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, _ []string) { - c, err := common.NewDockerClient(cmd.Context()) + c, err := containerutil.NewDockerClient(cmd.Context()) out.MaybeDie(err, "unable to create docker client: %v", err) defer c.Close() - purged, err := purgeCluster(c) - out.MaybeDieErr(common.WrapIfConnErr(err)) + purged, err := purgeCluster(cmd.Context(), c) + out.MaybeDieErr(containerutil.WrapIfConnErr(err)) if !purged { return @@ -46,16 +46,16 @@ func newPurgeCommand(fs afero.Fs, p *config.Params) *cobra.Command { out.MaybeDie(err, "rpk unable to load config: %v", err) y, ok := cfg.ActualRpkYaml() - if !ok || y.Profile(common.ContainerProfileName) == nil { + if !ok || y.Profile(containerutil.ContainerProfileName) == nil { // rpk.yaml file nor profile exist, we exit. return } - cleared, err := profile.DeleteProfile(fs, y, common.ContainerProfileName) + cleared, err := profile.DeleteProfile(fs, y, containerutil.ContainerProfileName) if err != nil { - fmt.Fprintf(os.Stderr, "unable to delete %q profile: %v; you may delete the profile manually running 'rpk profile delete %v'", common.ContainerProfileName, err, common.ContainerProfileName) + fmt.Fprintf(os.Stderr, "unable to delete %q profile: %v; you may delete the profile manually running 'rpk profile delete %v'", containerutil.ContainerProfileName, err, containerutil.ContainerProfileName) return } - fmt.Printf("Deleted profile %q.\n", common.ContainerProfileName) + fmt.Printf("Deleted profile %q.\n", containerutil.ContainerProfileName) if cleared { fmt.Println("This was the selected profile; rpk will use defaults until a new profile is selected or a new container is created.") } @@ -65,8 +65,8 @@ func newPurgeCommand(fs afero.Fs, p *config.Params) *cobra.Command { return command } -func purgeCluster(c common.Client) (purged bool, rerr error) { - nodes, err := common.GetExistingNodes(c) +func purgeCluster(ctx context.Context, c containerutil.Client) (purged bool, rerr error) { + nodes, err := containerutil.GetExistingNodes(ctx, c) if err != nil { return false, err } @@ -74,11 +74,11 @@ func purgeCluster(c common.Client) (purged bool, rerr error) { fmt.Print("No nodes to remove.\nYou may start a new local cluster with 'rpk container start'\n") return false, nil } - err = stopCluster(c) + err = stopCluster(ctx, c) if err != nil { return false, err } - grp, _ := errgroup.WithContext(context.Background()) + grp, grpCtx := errgroup.WithContext(ctx) for _, node := range nodes { node := node id := node.ID @@ -89,13 +89,12 @@ func purgeCluster(c common.Client) (purged bool, rerr error) { fmt.Printf(msg+"\n", args...) } grp.Go(func() error { - ctx, _ := common.DefaultCtx() - name := common.RedpandaName(id) + name := containerutil.RedpandaName(id) if node.Console { - name = common.ConsoleContainerName + name = containerutil.ConsoleContainerName } err := c.ContainerRemove( - ctx, + grpCtx, name, container.RemoveOptions{ RemoveVolumes: true, @@ -117,7 +116,7 @@ func purgeCluster(c common.Client) (purged bool, rerr error) { if err != nil { return false, err } - err = common.RemoveNetwork(c) + err = containerutil.RemoveNetwork(ctx, c) if err != nil { return false, err } diff --git a/src/go/rpk/pkg/cli/container/start.go b/src/go/rpk/pkg/cli/container/start.go index 3ede96b9c480d..2fdca4ab4db5f 100644 --- a/src/go/rpk/pkg/cli/container/start.go +++ b/src/go/rpk/pkg/cli/container/start.go @@ -28,9 +28,9 @@ import ( "github.com/avast/retry-go" "github.com/docker/docker/pkg/stdcopy" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - vnet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" + vnet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -137,7 +137,7 @@ Start a three-broker cluster, selecting the Admin API port for each broker: if nodes < 1 { out.Die("--nodes should be 1 or greater") } - c, err := common.NewDockerClient(cmd.Context()) + c, err := containerutil.NewDockerClient(cmd.Context()) out.MaybeDie(err, "unable to create docker client: %v", err) defer c.Close() @@ -148,19 +148,19 @@ Start a three-broker cluster, selecting the Admin API port for each broker: out.MaybeDie(err, "unable to parse container ports: %v", err) configKvs := collectFlags(os.Args, "--set") - isRestarted, err := startCluster(c, nodes, checkBrokers, retries, image, consoleImage, pull, cPorts, configKvs, subnet, gateway) + isRestarted, err := startCluster(cmd.Context(), c, nodes, checkBrokers, retries, image, consoleImage, pull, cPorts, configKvs, subnet, gateway) if err != nil { if errors.As(err, &portInUseError{}) { out.Die("unable to start cluster: %v\nYou may select different ports to start the cluster using our listener flags. Check '--help' text for more information", err) } - out.Die("unable to start cluster: %v", common.WrapIfConnErr(err)) + out.Die("unable to start cluster: %v", containerutil.WrapIfConnErr(err)) } if noProfile || isRestarted { return } - dockerNodes, err := renderClusterInfo(c) + dockerNodes, err := renderClusterInfo(cmd.Context(), c) out.MaybeDie(err, "unable to render cluster info: %v; you may run 'rpk container status' to retrieve the cluster info", err) cfg, err := p.Load(fs) @@ -169,18 +169,18 @@ Start a three-broker cluster, selecting the Admin API port for each broker: y, err := cfg.ActualRpkYamlOrEmpty() out.MaybeDie(err, "rpk unable to load config: %v", err) - err = common.CreateProfile(fs, c, y) + err = containerutil.CreateProfile(cmd.Context(), fs, c, y) if err == nil { - fmt.Printf("\nCreated %q profile.\n", common.ContainerProfileName) + fmt.Printf("\nCreated %q profile.\n", containerutil.ContainerProfileName) renderClusterInteract(dockerNodes, true) return } - if errors.Is(err, common.ErrContainerProfileExists) { + if errors.Is(err, containerutil.ErrContainerProfileExists) { fmt.Printf(`Unable to create a profile for the rpk container: %v. You can retry profile creation by running: rpk profile delete %s; rpk profile create --from-rpk-container -`, err, common.ContainerProfileName) +`, err, containerutil.ContainerProfileName) return } else { out.Die("unable to create a profile for the rpk container: %v", err) @@ -190,8 +190,8 @@ You can retry profile creation by running: command.Flags().UintVarP(&nodes, "nodes", "n", 1, "The number of brokers (nodes) to start") command.Flags().UintVar(&retries, "retries", 10, "The amount of times to check for the cluster before considering it unstable and exiting") - command.Flags().StringVar(&image, "image", common.DefaultRedpandaImage(), "An arbitrary Redpanda container image to use") - command.Flags().StringVar(&consoleImage, "console-image", common.DefaultConsoleImage(), "An arbitrary Redpanda Console container image to use") + command.Flags().StringVar(&image, "image", containerutil.DefaultRedpandaImage(), "An arbitrary Redpanda container image to use") + command.Flags().StringVar(&consoleImage, "console-image", containerutil.DefaultConsoleImage(), "An arbitrary Redpanda Console container image to use") command.Flags().BoolVar(&pull, "pull", false, "Force pull the container image used") command.Flags().BoolVar(&noProfile, "no-profile", false, "If true, rpk will not create an rpk profile after creating a cluster") command.Flags().String("set", "", "Redpanda configuration property to set upon start. Follows 'rpk redpanda config set' format") @@ -229,9 +229,10 @@ func collectFlags(args []string, flag string) []string { } func startCluster( - c common.Client, + ctx context.Context, + c containerutil.Client, n uint, - check func([]node) func() error, + check func(context.Context, []node) func() error, retries uint, image, consoleImage string, pull bool, @@ -240,14 +241,14 @@ func startCluster( subnet, gateway string, ) (isRestarted bool, rerr error) { // Check if cluster exists and start it again. - restarted, err := restartCluster(c, check, retries) + restarted, err := restartCluster(ctx, c, check, retries) if err != nil { return false, err } // If a cluster was restarted, there's nothing else to do. if len(restarted) != 0 { fmt.Print("Found an existing cluster:\n\n") - renderClusterInfo(c) + renderClusterInfo(ctx, c) if len(restarted) != int(n) { fmt.Print("\nTo change the number of nodes, first purge the existing cluster with\n'rpk container purge'.\n\n") } @@ -256,33 +257,33 @@ func startCluster( if pull { fmt.Println("Force pulling images...") - err = common.PullImage(c, image) + err = containerutil.PullImage(ctx, c, image) if err != nil { return false, fmt.Errorf("unable to pull Redpanda image: %v", err) } - err = common.PullImage(c, consoleImage) + err = containerutil.PullImage(ctx, c, consoleImage) if err != nil { return false, fmt.Errorf("unable to pull Redpanda Console image: %v", err) } } else { fmt.Println("Checking for a local image...") - err := checkPresentAndPull(c, image) + err := checkPresentAndPull(ctx, c, image) if err != nil { return false, fmt.Errorf("unable to check Redpanda image: %v", err) } - err = checkPresentAndPull(c, consoleImage) + err = checkPresentAndPull(ctx, c, consoleImage) if err != nil { return false, fmt.Errorf("unable to check Redpanda Console image: %v", err) } } // Create the docker network if it doesn't exist already - netID, err := common.CreateNetwork(c, subnet, gateway) + netID, err := containerutil.CreateNetwork(ctx, c, subnet, gateway) if err != nil { return false, err } - err = verifyPortsInUse(clusterPorts) + err = verifyPortsInUse(ctx, clusterPorts) if err != nil { return false, err } @@ -297,7 +298,8 @@ func startCluster( seedAdminPort = clusterPorts.adminPorts[0] ) - seedState, err := common.CreateNode( + seedState, err := containerutil.CreateNode( + ctx, c, seedID, seedKafkaPort, @@ -314,7 +316,7 @@ func startCluster( } fmt.Println("Starting cluster...") - err = startNode(c, seedState.ContainerID) + err = startNode(ctx, c, seedState.ContainerID) if err != nil { return false, err } @@ -331,7 +333,7 @@ func startCluster( mu := sync.Mutex{} - grp, _ := errgroup.WithContext(context.Background()) + grp, grpCtx := errgroup.WithContext(ctx) for nodeID := uint(1); nodeID < n; nodeID++ { id := nodeID @@ -351,7 +353,8 @@ func startCluster( strconv.Itoa(config.DevDefault().Redpanda.RPCServer.Port), ), } - state, err := common.CreateNode( + state, err := containerutil.CreateNode( + grpCtx, c, id, kafkaPort, @@ -366,7 +369,7 @@ func startCluster( if err != nil { return err } - err = startNode(c, state.ContainerID) + err = startNode(grpCtx, c, state.ContainerID) if err != nil { return err } @@ -388,11 +391,11 @@ func startCluster( return false, fmt.Errorf("error restarting the cluster: %v", err) } fmt.Println("Waiting for the cluster to be ready...") - err = waitForCluster(check(nodes), retries) + err = waitForCluster(check(ctx, nodes), retries) if err != nil { - var failedNodeState *common.NodeState + var failedNodeState *containerutil.NodeState for _, n := range nodes { - state, sErr := common.GetState(c, n.id, false) + state, sErr := containerutil.GetState(ctx, c, n.id, false) if sErr != nil { return false, fmt.Errorf("%v\nunable to get Docker container (%v) logs: %v", n.id, err, sErr) } @@ -407,7 +410,7 @@ func startCluster( return false, fmt.Errorf("unable to start the cluster on time: %v; you may run 'rpk container purge' and start again increasing the number of retries with the '--retries' flag", err) } - errStr, cErr := getContainerErr(failedNodeState, c) + errStr, cErr := getContainerErr(ctx, failedNodeState, c) if cErr != nil { return false, fmt.Errorf("%v\nunable to get Docker container logs: %v", err, cErr) } @@ -419,22 +422,22 @@ func startCluster( fmt.Println("Starting Redpanda Console...") consoleID := uint(len(nodes)) - consoleState, err := common.CreateConsoleNode(c, consoleID, netID, consoleImage, clusterPorts.consolePort, kafkaAddr, srAddr, adminAddr) + consoleState, err := containerutil.CreateConsoleNode(ctx, c, consoleID, netID, consoleImage, clusterPorts.consolePort, kafkaAddr, srAddr, adminAddr) if err != nil { return false, err } - if err := startNode(c, consoleState.ContainerID); err != nil { + if err := startNode(ctx, c, consoleState.ContainerID); err != nil { return false, err } consoleNode := node{consoleID, nodeAddr(consoleState.HostConsolePort)} fmt.Println("Waiting for Redpanda Console to be ready...") - err = waitForCluster(checkConsole(consoleNode), retries) + err = waitForCluster(checkConsole(ctx, consoleNode), retries) if err != nil { - state, sErr := common.GetState(c, consoleNode.id, true) + state, sErr := containerutil.GetState(ctx, c, consoleNode.id, true) if sErr != nil { return false, fmt.Errorf("%v\nunable to get Docker container logs: %v", err, sErr) } - errStr, cErr := getContainerErr(state, c) + errStr, cErr := getContainerErr(ctx, state, c) if cErr != nil { return false, fmt.Errorf("%v\nunable to get Docker container logs: %v", err, cErr) } @@ -447,10 +450,10 @@ func startCluster( } func restartCluster( - c common.Client, check func([]node) func() error, retries uint, + ctx context.Context, c containerutil.Client, check func(context.Context, []node) func() error, retries uint, ) ([]node, error) { // Check if a cluster is running - states, err := common.GetExistingNodes(c) + states, err := containerutil.GetExistingNodes(ctx, c) if err != nil { return nil, err } @@ -462,27 +465,26 @@ func restartCluster( if len(states) == 1 && states[0].Console { return nil, fmt.Errorf("stranded Redpanda Console container detected; please run 'rpk container purge' and try again") } - grp, _ := errgroup.WithContext(context.Background()) + grp, grpCtx := errgroup.WithContext(ctx) mu := sync.Mutex{} var ( rpNodes []node consoleNode node - consoleState *common.NodeState + consoleState *containerutil.NodeState ) for _, s := range states { state := s grp.Go(func() error { if !state.Running { - ctx, _ := common.DefaultCtx() // Console node needs to start after the Redpanda nodes start. if !state.Console { - err = c.ContainerStart(ctx, state.ContainerID, container.StartOptions{}) + err = c.ContainerStart(grpCtx, state.ContainerID, container.StartOptions{}) if err != nil { return err } } - state, err = common.GetState(c, state.ID, state.Console) + state, err = containerutil.GetState(grpCtx, c, state.ID, state.Console) if err != nil { return err } @@ -506,9 +508,9 @@ func restartCluster( return nil, fmt.Errorf("error restarting the cluster: %v", err) } fmt.Printf("Waiting for the cluster to be ready...\n\n") - err = waitForCluster(check(rpNodes), retries) + err = waitForCluster(check(ctx, rpNodes), retries) if err != nil { - errStr, cErr := getContainerErr(states[0], c) + errStr, cErr := getContainerErr(ctx, states[0], c) if cErr != nil { return nil, fmt.Errorf("%v\nunable to get Docker container logs: %v", err, cErr) } @@ -516,21 +518,20 @@ func restartCluster( } if consoleState != nil && !consoleState.Running { - ctx, _ := common.DefaultCtx() err = c.ContainerStart(ctx, consoleState.ContainerID, container.StartOptions{}) if err != nil { return nil, fmt.Errorf("unable to start the Redpanda Console container: %v", err) } - state, err := common.GetState(c, consoleState.ID, consoleState.Console) + state, err := containerutil.GetState(ctx, c, consoleState.ID, consoleState.Console) if err != nil { return nil, fmt.Errorf("unable to inspect Redpanda Console container after start: %v", err) } consoleNode = node{state.ID, nodeAddr(state.HostConsolePort)} } - err = waitForCluster(checkConsole(consoleNode), retries) + err = waitForCluster(checkConsole(ctx, consoleNode), retries) if err != nil { if consoleState != nil { - errStr, cErr := getContainerErr(consoleState, c) + errStr, cErr := getContainerErr(ctx, consoleState, c) if cErr != nil { return nil, fmt.Errorf("%v\nunable to get Docker container logs: %v", err, cErr) } @@ -541,13 +542,12 @@ func restartCluster( return rpNodes, nil } -func startNode(c common.Client, containerID string) error { - ctx, _ := common.DefaultCtx() +func startNode(ctx context.Context, c containerutil.Client, containerID string) error { err := c.ContainerStart(ctx, containerID, container.StartOptions{}) return err } -func checkBrokers(nodes []node) func() error { +func checkBrokers(ctx context.Context, nodes []node) func() error { return func() error { addrs := make([]string, 0, len(nodes)) for _, n := range nodes { @@ -557,7 +557,7 @@ func checkBrokers(nodes []node) func() error { if err != nil { return err } - brokers, err := kadm.NewClient(cl).ListBrokers(context.Background()) + brokers, err := kadm.NewClient(cl).ListBrokers(ctx) if err != nil { return err } @@ -572,7 +572,7 @@ func checkBrokers(nodes []node) func() error { } } -func checkConsole(node node) func() error { +func checkConsole(ctx context.Context, node node) func() error { return func() error { cl := httpapi.NewClient( httpapi.Host("http://"+node.addr), @@ -580,7 +580,7 @@ func checkConsole(node node) func() error { ) // We use the /admin/startup to check if the console is healthy, if we // receive a 200 then we are good. httpapi errs on != 2xx. - err := cl.Get(context.Background(), "/admin/startup", nil, nil) + err := cl.Get(ctx, "/admin/startup", nil, nil) if err != nil { return fmt.Errorf("console is not healthy; error while checking console status: %v", err) } @@ -598,8 +598,8 @@ func waitForCluster(check func() error, retries uint) error { ) } -func renderClusterInfo(c common.Client) ([]*common.NodeState, error) { - nodes, err := common.GetExistingNodes(c) +func renderClusterInfo(ctx context.Context, c containerutil.Client) ([]*containerutil.NodeState, error) { + nodes, err := containerutil.GetExistingNodes(ctx, c) if err != nil { return nil, err } @@ -609,7 +609,7 @@ func renderClusterInfo(c common.Client) ([]*common.NodeState, error) { } tw := out.NewTable("Node-ID", "Status", "Kafka-Address", "Admin-Address", "Proxy-Address", "Schema-Registry-Address") - var consoleNode *common.NodeState + var consoleNode *containerutil.NodeState defer func() { tw.Flush() if consoleNode != nil && consoleNode.Running { @@ -652,7 +652,7 @@ func renderClusterInfo(c common.Client) ([]*common.NodeState, error) { return nodes, nil } -func renderClusterInteract(nodes []*common.NodeState, withProfile bool) { +func renderClusterInteract(nodes []*containerutil.NodeState, withProfile bool) { var ( brokers []string adminAddrs []string @@ -705,9 +705,7 @@ func nodeAddr(port uint) string { // getContainerErr attempts to fetch the latest stderr output from the first // Redpanda node. It may reveal reasons for failing to start. -func getContainerErr(state *common.NodeState, c common.Client) (string, error) { - ctx, _ := common.DefaultCtx() - +func getContainerErr(ctx context.Context, state *containerutil.NodeState, c containerutil.Client) (string, error) { json, err := c.ContainerInspect(ctx, state.ContainerID) if err != nil { return "", fmt.Errorf("could not inspect container: %v", err) @@ -814,10 +812,11 @@ func parseContainerPortFlags(nNodes int, adminPorts, kafkaPorts, proxyPorts, rpc }, nil } -func verifyPortsInUse(cPorts clusterPorts) error { +func verifyPortsInUse(ctx context.Context, cPorts clusterPorts) error { check := func(ports []uint, listener string) error { for _, p := range ports { - server, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", p)) + var lc net.ListenConfig + server, err := lc.Listen(ctx, "tcp", fmt.Sprintf("127.0.0.1:%d", p)) // if it fails then the port might be in use if err != nil { return portInUseError{p, listener} @@ -853,15 +852,15 @@ func (p portInUseError) Error() string { return fmt.Sprintf("%v port %v already in use", p.listener, p.port) } -func checkPresentAndPull(c common.Client, image string) error { - rpPresent, checkErr := common.CheckIfImgPresent(c, image) +func checkPresentAndPull(ctx context.Context, c containerutil.Client, image string) error { + rpPresent, checkErr := containerutil.CheckIfImgPresent(ctx, c, image) if checkErr != nil { fmt.Printf("Error trying to list local images: %v\n", checkErr) } if !rpPresent { // If the image isn't present locally, try to pull it. fmt.Printf("Version %q not found locally\n", image) - err := common.PullImage(c, image) + err := containerutil.PullImage(ctx, c, image) if err != nil { return fmt.Errorf("could not pull image: %v", err) } diff --git a/src/go/rpk/pkg/cli/container/status.go b/src/go/rpk/pkg/cli/container/status.go index ea9595c22dd97..6ada2a3e0e262 100644 --- a/src/go/rpk/pkg/cli/container/status.go +++ b/src/go/rpk/pkg/cli/container/status.go @@ -10,7 +10,7 @@ package container import ( - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" @@ -23,19 +23,19 @@ func newStatusCommand(fs afero.Fs, p *config.Params) *cobra.Command { Short: "Get status", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, _ []string) { - c, err := common.NewDockerClient(cmd.Context()) + c, err := containerutil.NewDockerClient(cmd.Context()) out.MaybeDieErr(err) defer c.Close() - nodes, err := renderClusterInfo(c) - out.MaybeDieErr(common.WrapIfConnErr(err)) + nodes, err := renderClusterInfo(cmd.Context(), c) + out.MaybeDieErr(containerutil.WrapIfConnErr(err)) cfg, err := p.Load(fs) out.MaybeDie(err, "rpk unable to load config: %v", err) y, ok := cfg.ActualRpkYaml() var withProfile bool - if ok && y.Profile(common.ContainerProfileName) != nil && y.CurrentProfile == common.ContainerProfileName { + if ok && y.Profile(containerutil.ContainerProfileName) != nil && y.CurrentProfile == containerutil.ContainerProfileName { withProfile = true } renderClusterInteract(nodes, withProfile) diff --git a/src/go/rpk/pkg/cli/container/stop.go b/src/go/rpk/pkg/cli/container/stop.go index 04f2d515a81f5..1cb997b0ee0f1 100644 --- a/src/go/rpk/pkg/cli/container/stop.go +++ b/src/go/rpk/pkg/cli/container/stop.go @@ -15,7 +15,7 @@ import ( "sync" "github.com/docker/docker/api/types/container" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/spf13/cobra" ) @@ -25,19 +25,19 @@ func newStopCommand() *cobra.Command { Short: "Stop an existing local container cluster", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { - c, err := common.NewDockerClient(cmd.Context()) + c, err := containerutil.NewDockerClient(cmd.Context()) if err != nil { return err } defer c.Close() - return common.WrapIfConnErr(stopCluster(c)) + return containerutil.WrapIfConnErr(stopCluster(cmd.Context(), c)) }, } return command } -func stopCluster(c common.Client) error { - nodes, err := common.GetExistingNodes(c) +func stopCluster(ctx context.Context, c containerutil.Client) error { + nodes, err := containerutil.GetExistingNodes(ctx, c) if err != nil { return err } @@ -54,18 +54,17 @@ func stopCluster(c common.Client) error { defer mu.Unlock() fmt.Printf(msg+"\n", args...) } - go func(state *common.NodeState) { + go func(state *containerutil.NodeState) { defer wg.Done() - name := common.RedpandaName(state.ID) + name := containerutil.RedpandaName(state.ID) if state.Console { - name = common.ConsoleContainerName + name = containerutil.ConsoleContainerName } // If the node was stopped already, do nothing. if !state.Running { printf("%s was stopped already.", name) return } - ctx := context.Background() // Redpanda sometimes takes a while to stop, so 20 // seconds is a safe estimate timeout := 20 // seconds diff --git a/src/go/rpk/pkg/cli/debug/bundle/BUILD b/src/go/rpk/pkg/cli/debug/bundle/BUILD index 53e90f88fb38b..a6e417eade98b 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/BUILD +++ b/src/go/rpk/pkg/cli/debug/bundle/BUILD @@ -19,14 +19,14 @@ go_library( ], "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/adminapi", - "//src/go/rpk/pkg/cli/debug/common", + "//src/go/rpk/pkg/cli/debug/debugbundle", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/kafka", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/system/syslog", - "//src/go/rpk/pkg/utils", "@build_buf_gen_go_redpandadata_core_protocolbuffers_go//redpanda/core/admin/v2:admin", "@com_connectrpc_connect//:connect", "@com_github_avast_retry_go//:retry-go", @@ -86,14 +86,14 @@ go_library( ], "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/adminapi", - "//src/go/rpk/pkg/cli/debug/common", + "//src/go/rpk/pkg/cli/debug/debugbundle", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/kafka", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/system/syslog", - "//src/go/rpk/pkg/utils", "@build_buf_gen_go_redpandadata_core_protocolbuffers_go//redpanda/core/admin/v2:admin", "@com_connectrpc_connect//:connect", "@com_github_avast_retry_go//:retry-go", diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle.go b/src/go/rpk/pkg/cli/debug/bundle/bundle.go index 77d8c18dfcfe4..446819e78f883 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle.go @@ -18,7 +18,7 @@ import ( "time" "github.com/docker/go-units" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" @@ -61,7 +61,7 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { outFile string uploadURL string timeout time.Duration - opts common.DebugBundleSharedOptions + opts debugbundle.DebugBundleSharedOptions ) cmd := &cobra.Command{ Use: "bundle", @@ -144,7 +144,7 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { } out.MaybeDie(err, "unable to create bundle: %v", err) if uploadURL != "" { - err = common.UploadBundle(cmd.Context(), path, uploadURL) + err = debugbundle.UploadBundle(cmd.Context(), path, uploadURL) out.MaybeDie(err, "unable to upload bundle: %v", err) fmt.Println("Successfully uploaded the bundle") } diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go b/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go index d73b54b2b77cd..e0e9bfabd66ec 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go @@ -30,7 +30,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/redpanda-data/common-go/rpadmin" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/spf13/afero" "go.uber.org/zap" @@ -259,7 +259,7 @@ func adminAddressesFromK8S(ctx context.Context, namespace string) ([]string, err return nil, fmt.Errorf("unable to list pods in the service %q: %v", svc.Name, err) } - clusterDomain := getClusterDomain() + clusterDomain := getClusterDomain(ctx) // Get the admin addresses from ContainerPort. var adminAddresses []string for _, p := range pods.Items { @@ -281,10 +281,10 @@ func adminAddressesFromK8S(ctx context.Context, namespace string) ([]string, err // getClusterDomain returns Kubernetes cluster domain, default to // "cluster.local.". -func getClusterDomain() string { +func getClusterDomain(ctx context.Context) string { const apiSvc = "kubernetes.default.svc" - cname, err := net.LookupCNAME(apiSvc) + cname, err := net.DefaultResolver.LookupCNAME(ctx, apiSvc) if err != nil { return "cluster.local." } @@ -417,7 +417,7 @@ func saveSingleAdminAPICalls(ctx context.Context, ps *stepParams, fs afero.Fs, p continue } - aName := common.SanitizeName(a) + aName := debugbundle.SanitizeName(a) r := []func() error{ func() error { return requestAndSave(ctx, ps, fmt.Sprintf("admin/node_config_%v.json", aName), cl.RawNodeConfig) @@ -494,7 +494,7 @@ func saveMetricsAPICalls(ctx context.Context, ps *stepParams, fs afero.Fs, p *co "public_metrics": metricStream(cl, "/public_metrics"), } - aName := common.SanitizeName(a) + aName := debugbundle.SanitizeName(a) for endpointName, endpoint := range endpoints { endpointPoller := func() error { err := requestAndSave(ctx, ps, fmt.Sprintf("metrics/%v/t0_%s.txt", aName, endpointName), endpoint) diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go b/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go index ada25d0ea33ec..966c62f51f0b8 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go @@ -37,13 +37,13 @@ import ( "github.com/beevik/ntp" "github.com/docker/go-units" "github.com/hashicorp/go-multierror" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - osutil "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + osutil "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system/syslog" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/twmb/franz-go/pkg/kadm" "github.com/twmb/franz-go/pkg/kgo" @@ -64,7 +64,7 @@ func determineFilepath(fs afero.Fs, rp *config.RedpandaYaml, path string, isFlag if path == "" { timestamp := time.Now().Unix() if rp.Redpanda.AdvertisedRPCAPI != nil { - path = fmt.Sprintf("%v-%d-bundle.zip", common.SanitizeName(rp.Redpanda.AdvertisedRPCAPI.Address), timestamp) + path = fmt.Sprintf("%v-%d-bundle.zip", debugbundle.SanitizeName(rp.Redpanda.AdvertisedRPCAPI.Address), timestamp) } else { path = fmt.Sprintf("%d-bundle.zip", timestamp) } @@ -952,7 +952,7 @@ func saveIP(ctx context.Context, ps *stepParams) step { func saveEthtool(ctx context.Context, ps *stepParams) step { return func() error { netDir := "/sys/class/net" - interfaces := utils.ListFilesInPath(ps.fs, netDir) + interfaces := rpkutil.ListFilesInPath(ps.fs, netDir) for _, iface := range interfaces { if exists, err := afero.Exists(ps.fs, filepath.Join(netDir, iface, "device")); err != nil || !exists { // skip virtual interfaces diff --git a/src/go/rpk/pkg/cli/debug/common/BUILD b/src/go/rpk/pkg/cli/debug/debugbundle/BUILD similarity index 51% rename from src/go/rpk/pkg/cli/debug/common/BUILD rename to src/go/rpk/pkg/cli/debug/debugbundle/BUILD index 8fdaeee6dcb29..149eb038e0b5d 100644 --- a/src/go/rpk/pkg/cli/debug/common/BUILD +++ b/src/go/rpk/pkg/cli/debug/debugbundle/BUILD @@ -17,3 +17,21 @@ go_test( embed = [":common"], deps = ["@com_github_stretchr_testify//require"], ) + +go_library( + name = "debugbundle", + srcs = ["common.go"], + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle", + visibility = ["//visibility:public"], + deps = [ + "//src/go/rpk/pkg/httpapi", + "@com_github_spf13_pflag//:pflag", + ], +) + +go_test( + name = "debugbundle_test", + srcs = ["common_test.go"], + embed = [":debugbundle"], + deps = ["@com_github_stretchr_testify//require"], +) diff --git a/src/go/rpk/pkg/cli/debug/common/common.go b/src/go/rpk/pkg/cli/debug/debugbundle/common.go similarity index 98% rename from src/go/rpk/pkg/cli/debug/common/common.go rename to src/go/rpk/pkg/cli/debug/debugbundle/common.go index 416b841be8327..49b5b0cf80bf2 100644 --- a/src/go/rpk/pkg/cli/debug/common/common.go +++ b/src/go/rpk/pkg/cli/debug/debugbundle/common.go @@ -1,4 +1,4 @@ -package common +package debugbundle import ( "context" @@ -51,7 +51,7 @@ func SanitizeName(name string) string { forbidden := []string{"<", ">", ":", `"`, "/", `\`, "|", "?", "*"} r := name for _, s := range forbidden { - r = strings.Replace(r, s, "-", -1) + r = strings.ReplaceAll(r, s, "-") } return r } diff --git a/src/go/rpk/pkg/cli/debug/common/common_test.go b/src/go/rpk/pkg/cli/debug/debugbundle/common_test.go similarity index 98% rename from src/go/rpk/pkg/cli/debug/common/common_test.go rename to src/go/rpk/pkg/cli/debug/debugbundle/common_test.go index 02fc88f06ae62..225462ead217c 100644 --- a/src/go/rpk/pkg/cli/debug/common/common_test.go +++ b/src/go/rpk/pkg/cli/debug/debugbundle/common_test.go @@ -1,4 +1,4 @@ -package common +package debugbundle import ( "testing" diff --git a/src/go/rpk/pkg/cli/debug/remotebundle/BUILD b/src/go/rpk/pkg/cli/debug/remotebundle/BUILD index 44687beeddc2f..a0f6f83b489ca 100644 --- a/src/go/rpk/pkg/cli/debug/remotebundle/BUILD +++ b/src/go/rpk/pkg/cli/debug/remotebundle/BUILD @@ -13,7 +13,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//src/go/rpk/pkg/adminapi", - "//src/go/rpk/pkg/cli/debug/common", + "//src/go/rpk/pkg/cli/debug/debugbundle", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/out", "@com_github_docker_go_units//:go-units", diff --git a/src/go/rpk/pkg/cli/debug/remotebundle/download.go b/src/go/rpk/pkg/cli/debug/remotebundle/download.go index bfbd46462ef57..58aa4e48a2374 100644 --- a/src/go/rpk/pkg/cli/debug/remotebundle/download.go +++ b/src/go/rpk/pkg/cli/debug/remotebundle/download.go @@ -22,7 +22,7 @@ import ( "time" "github.com/redpanda-data/common-go/rpadmin" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" @@ -68,7 +68,7 @@ Use the flag '--no-confirm' to avoid the confirmation prompt. } ready, _ := filterCompletedBrokers(status) if len(ready) == 0 { - out.Die("There are no bundles ready for download; to check status run 'rpk debug remote-bundle status'") + out.Die("there are no bundles ready for download; to check status run 'rpk debug remote-bundle status'") } if len(ready) != len(status) { fmt.Printf("WARNING: There are (%d) bundles not ready to download; to check the status run 'rpk debug remote-bundle status'\n", len(status)-len(ready)) @@ -106,7 +106,7 @@ Use the flag '--no-confirm' to avoid the confirmation prompt. fmt.Printf("\nSuccessfully downloaded remote debug bundle to %v\n", downloadPath) if uploadURL != "" { - err = common.UploadBundle(cmd.Context(), downloadPath, uploadURL) + err = debugbundle.UploadBundle(cmd.Context(), downloadPath, uploadURL) out.MaybeDie(err, "unable to upload bundle: %v", err) fmt.Println("Successfully uploaded the bundle") } @@ -148,7 +148,7 @@ func downloadBundle(ctx context.Context, fs afero.Fs, downloadPath string, statu wr, err := w.CreateHeader(&zip.FileHeader{ // Each individual zip file will be stored under a directory // with the broker address. - Name: filepath.Join(downloadRoot, common.SanitizeName(broker), jobID+".zip"), + Name: filepath.Join(downloadRoot, debugbundle.SanitizeName(broker), jobID+".zip"), Method: zip.Deflate, Modified: time.Now(), }) diff --git a/src/go/rpk/pkg/cli/debug/remotebundle/start.go b/src/go/rpk/pkg/cli/debug/remotebundle/start.go index f468eba05e81d..811cfa74892ed 100644 --- a/src/go/rpk/pkg/cli/debug/remotebundle/start.go +++ b/src/go/rpk/pkg/cli/debug/remotebundle/start.go @@ -21,7 +21,7 @@ import ( "github.com/google/uuid" "github.com/redpanda-data/common-go/rpadmin" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/debugbundle" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" @@ -176,11 +176,7 @@ Waiting for collection to complete... fmt.Printf("%sJob-ID %v status: %v/%v ready (%v errored)...", statusCR, jobID, len(ready), len(status), len(errorred)) if len(ready)+len(errorred) == len(status) { if len(ready) == 0 { - out.Die(` -The debug bundle collection process with Job-ID %v has completed, but no bundles were successfully created. -To check the status, run: - rpk debug remote-bundle status -`, jobID) + out.Die(`the debug bundle collection process with Job-ID %v has completed, but no bundles were successfully created; to check the status, run 'rpk debug remote-bundle status'`, jobID) } fmt.Printf(` The debug bundle collection process with Job-ID %v has completed. To download the bundles, run: @@ -212,7 +208,7 @@ status, run: } type remoteBundleOptions struct { - common.DebugBundleSharedOptions + debugbundle.DebugBundleSharedOptions controllerLogsSizeLimitBytes int32 logsSizeLimitBytes int32 labelSelectorMap map[string]string diff --git a/src/go/rpk/pkg/cli/generate/BUILD b/src/go/rpk/pkg/cli/generate/BUILD index a6f1348c40a5c..27ae8aac6bd0e 100644 --- a/src/go/rpk/pkg/cli/generate/BUILD +++ b/src/go/rpk/pkg/cli/generate/BUILD @@ -26,7 +26,7 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/httpapi", "//src/go/rpk/pkg/kafka", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/publicapi", "@build_buf_gen_go_redpandadata_gatekeeper_protocolbuffers_go//redpanda/api/gatekeeper/v1alpha1", diff --git a/src/go/rpk/pkg/cli/generate/app.go b/src/go/rpk/pkg/cli/generate/app.go index a7c4f25a1c91d..1f6b1c1b1cbf1 100644 --- a/src/go/rpk/pkg/cli/generate/app.go +++ b/src/go/rpk/pkg/cli/generate/app.go @@ -28,7 +28,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" diff --git a/src/go/rpk/pkg/cli/generate/graf/graph.go b/src/go/rpk/pkg/cli/generate/graf/graph.go index 88118cf3e4431..399d64f87715f 100644 --- a/src/go/rpk/pkg/cli/generate/graf/graph.go +++ b/src/go/rpk/pkg/cli/generate/graf/graph.go @@ -34,7 +34,7 @@ func (*GraphPanel) Type() string { } func (p *GraphPanel) GetGridPos() *GridPos { - return &p.BasePanel.GridPos + return &p.GridPos } func (p GraphPanel) MarshalJSON() ([]byte, error) { diff --git a/src/go/rpk/pkg/cli/generate/graf/row.go b/src/go/rpk/pkg/cli/generate/graf/row.go index 47d819e886871..38f0989cd96b0 100644 --- a/src/go/rpk/pkg/cli/generate/graf/row.go +++ b/src/go/rpk/pkg/cli/generate/graf/row.go @@ -21,7 +21,7 @@ func (*RowPanel) Type() string { } func (p *RowPanel) GetGridPos() *GridPos { - return &p.BasePanel.GridPos + return &p.GridPos } func (p *RowPanel) MarshalJSON() ([]byte, error) { diff --git a/src/go/rpk/pkg/cli/generate/graf/singlestat.go b/src/go/rpk/pkg/cli/generate/graf/singlestat.go index 6fc9c200604a1..cff378d86bf22 100644 --- a/src/go/rpk/pkg/cli/generate/graf/singlestat.go +++ b/src/go/rpk/pkg/cli/generate/graf/singlestat.go @@ -47,7 +47,7 @@ func (*SingleStatPanel) Type() string { } func (p *SingleStatPanel) GetGridPos() *GridPos { - return &p.BasePanel.GridPos + return &p.GridPos } func (p *SingleStatPanel) MarshalJSON() ([]byte, error) { diff --git a/src/go/rpk/pkg/cli/generate/grafana.go b/src/go/rpk/pkg/cli/generate/grafana.go index 33dfa1e24841b..a3c8e27e392ef 100644 --- a/src/go/rpk/pkg/cli/generate/grafana.go +++ b/src/go/rpk/pkg/cli/generate/grafana.go @@ -135,7 +135,7 @@ To see a list of all available dashboards, use the '--dashboard help' flag. switch { case dashboard == "legacy": if datasource == "" { - out.Die(`Error: required legacy flag "datasource" not set; please set the flag to the redpanda metrics endpoint where rpk should get the metrics metadata. i.e. redpanda_host:9644/public_metrics`) + out.Die(`required legacy flag "datasource" not set; please set the flag to the redpanda metrics endpoint where rpk should get the metrics metadata, e.g. redpanda_host:9644/public_metrics`) } jsonOut, err := executeGrafanaDashboard(metricsEndpoint, datasource) out.MaybeDie(err, "unable to generate the grafana dashboard: %v", err) @@ -223,8 +223,7 @@ func decompressAndPrint(fs fs.FS, path string, writer io.Writer) error { } func executeGrafanaDashboard(metricsEndpoint string, datasource string) (string, error) { - if !(strings.HasPrefix(metricsEndpoint, "http://") || - strings.HasPrefix(metricsEndpoint, "https://")) { + if !strings.HasPrefix(metricsEndpoint, "http://") && !strings.HasPrefix(metricsEndpoint, "https://") { metricsEndpoint = fmt.Sprintf("http://%s", metricsEndpoint) } diff --git a/src/go/rpk/pkg/cli/generate/license.go b/src/go/rpk/pkg/cli/generate/license.go index c31417f186b13..80ad88f96aa4d 100644 --- a/src/go/rpk/pkg/cli/generate/license.go +++ b/src/go/rpk/pkg/cli/generate/license.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi" "github.com/spf13/afero" diff --git a/src/go/rpk/pkg/cli/group/BUILD b/src/go/rpk/pkg/cli/group/BUILD index 5037a6c0eb108..10025520cff24 100644 --- a/src/go/rpk/pkg/cli/group/BUILD +++ b/src/go/rpk/pkg/cli/group/BUILD @@ -14,7 +14,7 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/kafka", "//src/go/rpk/pkg/out", - "//src/go/rpk/pkg/utils", + "//src/go/rpk/pkg/rpkutil", "@com_github_cespare_xxhash//:xxhash", "@com_github_lithammer_go_jump_consistent_hash//:go-jump-consistent-hash", "@com_github_spf13_afero//:afero", diff --git a/src/go/rpk/pkg/cli/group/describe.go b/src/go/rpk/pkg/cli/group/describe.go index e3d08ca7bb161..df508cfe705d5 100644 --- a/src/go/rpk/pkg/cli/group/describe.go +++ b/src/go/rpk/pkg/cli/group/describe.go @@ -19,7 +19,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" @@ -418,5 +418,5 @@ func regexGroups(adm *kadm.Client, expressions []string) ([]string, error) { return nil, fmt.Errorf("unable to list groups: %w", err) } - return utils.RegexListedItems(groups.Groups(), expressions) + return rpkutil.RegexListedItems(groups.Groups(), expressions) } diff --git a/src/go/rpk/pkg/cli/group/group.go b/src/go/rpk/pkg/cli/group/group.go index 0df930e693eb1..d6322b7c8aa79 100644 --- a/src/go/rpk/pkg/cli/group/group.go +++ b/src/go/rpk/pkg/cli/group/group.go @@ -121,7 +121,7 @@ The STATE columns shows which state the group is in: }) if vsi == -1 { - out.Die("Invalid group state argument: %s", state) + out.Die("invalid group state argument: %s", state) } normalizedFilterStates[i] = validStates[vsi] diff --git a/src/go/rpk/pkg/cli/group/seek.go b/src/go/rpk/pkg/cli/group/seek.go index 6493fbcd85cba..d1ffdec7b6fab 100644 --- a/src/go/rpk/pkg/cli/group/seek.go +++ b/src/go/rpk/pkg/cli/group/seek.go @@ -99,12 +99,12 @@ Seek group G to the beginning of a topic it was not previously consuming: n++ } } - switch { - case n == 0: - out.Die("Must specify one --to flag.") - case n == 1: + switch n { + case 0: + out.Die("must specify one --to flag") + case 1: default: - out.Die("Cannot specify multiple --to flags.") + out.Die("cannot specify multiple --to flags") } tset := make(map[string]bool) @@ -221,7 +221,7 @@ func seek( tps := current.TopicsSet() for topic := range topics { if _, exists := tps[topic]; !exists && !allowNewTopics { - out.Die("Cannot commit new topic %q without --allow-new-topics.", topic) + out.Die("cannot commit new topic %q without --allow-new-topics", topic) } tps[topic] = map[int32]struct{}{} // ensure exists } diff --git a/src/go/rpk/pkg/cli/plugin/BUILD b/src/go/rpk/pkg/cli/plugin/BUILD index 401e4afe447b3..375b90f34cd19 100644 --- a/src/go/rpk/pkg/cli/plugin/BUILD +++ b/src/go/rpk/pkg/cli/plugin/BUILD @@ -11,7 +11,7 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/plugin", visibility = ["//visibility:public"], deps = [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/plugin", "@com_github_spf13_afero//:afero", diff --git a/src/go/rpk/pkg/cli/plugin/install.go b/src/go/rpk/pkg/cli/plugin/install.go index 21e1e4d94098b..73ae7024a575a 100644 --- a/src/go/rpk/pkg/cli/plugin/install.go +++ b/src/go/rpk/pkg/cli/plugin/install.go @@ -15,7 +15,7 @@ import ( "os" "runtime" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/plugin" "github.com/spf13/afero" diff --git a/src/go/rpk/pkg/cli/profile/BUILD b/src/go/rpk/pkg/cli/profile/BUILD index 058fbc3db30af..b505293baf03e 100644 --- a/src/go/rpk/pkg/cli/profile/BUILD +++ b/src/go/rpk/pkg/cli/profile/BUILD @@ -24,12 +24,12 @@ go_library( visibility = ["//visibility:public"], deps = [ "//src/go/rpk/pkg/adminapi", - "//src/go/rpk/pkg/cli/container/common", + "//src/go/rpk/pkg/cli/container/containerutil", "//src/go/rpk/pkg/cobraext", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth/authtoken", "//src/go/rpk/pkg/oauth/providers/auth0", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/publicapi", "@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/controlplane/v1:controlplane", diff --git a/src/go/rpk/pkg/cli/profile/create.go b/src/go/rpk/pkg/cli/profile/create.go index 6a6306ce3c1e9..ace6a7dc63788 100644 --- a/src/go/rpk/pkg/cli/profile/create.go +++ b/src/go/rpk/pkg/cli/profile/create.go @@ -19,7 +19,7 @@ import ( controlplanev1 "buf.build/gen/go/redpandadata/cloud/protocolbuffers/go/redpanda/api/controlplane/v1" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" - container "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common" + container "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cobraext" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/authtoken" @@ -253,7 +253,7 @@ func CreateFlow( if err != nil { return fmt.Errorf("unable to create docker client: %v", err) } - err = container.CreateProfile(fs, c, yAct) //nolint:contextcheck // No need to pass the context, the underlying functions use a context with timeout. + err = container.CreateProfile(ctx, fs, c, yAct) if err != nil { return fmt.Errorf("unable to create profile from rpk container: %v", err) } @@ -292,8 +292,8 @@ func CreateFlow( } case fromProfile != "": - switch { - case fromProfile == "current": + switch fromProfile { + case "current": dup := *cfg.VirtualProfile() p = &dup default: @@ -327,8 +327,8 @@ func CreateFlow( case fromRedpanda != "": var nodeCfg config.RpkNodeConfig - switch { - case fromRedpanda == "current": + switch fromRedpanda { + case "current": nodeCfg = cfg.VirtualRedpandaYaml().Rpk default: raw, err := afero.ReadFile(fs, fromRedpanda) diff --git a/src/go/rpk/pkg/cli/profile/edit.go b/src/go/rpk/pkg/cli/profile/edit.go index 562491acb82e5..c22596a0a775c 100644 --- a/src/go/rpk/pkg/cli/profile/edit.go +++ b/src/go/rpk/pkg/cli/profile/edit.go @@ -14,7 +14,7 @@ import ( "fmt" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -37,7 +37,7 @@ uncomment it and provide a value. `, Args: cobra.MaximumNArgs(1), ValidArgsFunction: ValidProfiles(fs, p), - Run: func(_ *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, args []string) { cfg, err := p.Load(fs) out.MaybeDie(err, "rpk unable to load config: %v", err) y, err := cfg.ActualRpkYamlOrEmpty() @@ -59,7 +59,7 @@ uncomment it and provide a value. original := *p preFromCloud := p.FromCloud preCloudDetails := p.CloudCluster - update, err := rpkos.EditTmpYAMLFileWithEncoder(fs, *p, config.ProfileToDocumentedYAML) + update, err := rpkos.EditTmpYAMLFileWithEncoder(cmd.Context(), fs, *p, config.ProfileToDocumentedYAML) out.MaybeDieErr(err) if preFromCloud { diff --git a/src/go/rpk/pkg/cli/profile/edit_gobals.go b/src/go/rpk/pkg/cli/profile/edit_gobals.go index 942d04e8bed0c..d4d01620e26be 100644 --- a/src/go/rpk/pkg/cli/profile/edit_gobals.go +++ b/src/go/rpk/pkg/cli/profile/edit_gobals.go @@ -13,7 +13,7 @@ import ( "fmt" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -28,13 +28,13 @@ func newEditGlobalsCommand(fs afero.Fs, p *config.Params) *cobra.Command { This command opens your default editor to edit the rpk global configurations. `, Args: cobra.ExactArgs(0), - Run: func(*cobra.Command, []string) { + Run: func(cmd *cobra.Command, _ []string) { cfg, err := p.Load(fs) out.MaybeDie(err, "rpk unable to load config: %v", err) y, err := cfg.ActualRpkYamlOrEmpty() out.MaybeDie(err, "rpk unable to load config: %v", err) - y.Globals, err = rpkos.EditTmpYAMLFile(fs, y.Globals) + y.Globals, err = rpkos.EditTmpYAMLFile(cmd.Context(), fs, y.Globals) out.MaybeDieErr(err) err = y.Write(fs) diff --git a/src/go/rpk/pkg/cli/profile/prompt.go b/src/go/rpk/pkg/cli/profile/prompt.go index 653c08bd4fb12..4944ec34188c4 100644 --- a/src/go/rpk/pkg/cli/profile/prompt.go +++ b/src/go/rpk/pkg/cli/profile/prompt.go @@ -275,9 +275,10 @@ func splitPromptParens(s string) ([]string, error) { } if inQuote { - if c == '\\' { + switch c { + case '\\': inEsc = true - } else if c == '"' { + case '"': inQuote = false } current = append(current, c) diff --git a/src/go/rpk/pkg/cli/profile/validate.go b/src/go/rpk/pkg/cli/profile/validate.go index 69a88df90c433..4012500142942 100644 --- a/src/go/rpk/pkg/cli/profile/validate.go +++ b/src/go/rpk/pkg/cli/profile/validate.go @@ -63,7 +63,7 @@ Validate a specific profile: y, ok := cfg.ActualRpkYaml() if !ok { - out.Die("No rpk.yaml configuration file found") + out.Die("no rpk.yaml configuration file found") } // Determine which profile to validate @@ -75,12 +75,12 @@ Validate a specific profile: } if profileName == "" { - out.Die("No profile specified and no current profile set") + out.Die("no profile specified and no current profile set") } profile := y.Profile(profileName) if profile == nil { - out.Die("Profile %q not found", profileName) + out.Die("profile %q not found", profileName) } auth := profile.ActualAuth() diff --git a/src/go/rpk/pkg/cli/redpanda/BUILD b/src/go/rpk/pkg/cli/redpanda/BUILD index f3932d85d39b9..69d3d2cb2a5a5 100644 --- a/src/go/rpk/pkg/cli/redpanda/BUILD +++ b/src/go/rpk/pkg/cli/redpanda/BUILD @@ -22,16 +22,16 @@ go_library( "//src/go/rpk/pkg/cloud", "//src/go/rpk/pkg/cobraext", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/factory", "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/iotune", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_fatih_color//:color", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", @@ -58,16 +58,16 @@ go_library( "//src/go/rpk/pkg/cloud", "//src/go/rpk/pkg/cobraext", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/factory", "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/iotune", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_fatih_color//:color", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", @@ -92,11 +92,11 @@ go_test( deps = select({ "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/iotune", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_spf13_pflag//:pflag", "@com_github_stretchr_testify//require", @@ -104,11 +104,11 @@ go_test( ], "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/iotune", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_spf13_pflag//:pflag", "@com_github_stretchr_testify//require", diff --git a/src/go/rpk/pkg/cli/redpanda/admin/brokers/decommission.go b/src/go/rpk/pkg/cli/redpanda/admin/brokers/decommission.go index c93d4b3cb8a17..93bfd377f1ba4 100644 --- a/src/go/rpk/pkg/cli/redpanda/admin/brokers/decommission.go +++ b/src/go/rpk/pkg/cli/redpanda/admin/brokers/decommission.go @@ -80,11 +80,11 @@ cluster is unreachable), use the --skip-liveness-check flag. // Old brokers (< v22.1) don't have maintenance mode, so we must // check if b.Maintenance is not nil. if b.Maintenance != nil && b.Maintenance.Draining { - out.Die(`Node cannot be decommissioned while it is in maintenance mode. -Take the node out of maintenance mode first by running: + out.Die(`node cannot be decommissioned while it is in maintenance mode +take the node out of maintenance mode first by running: rpk cluster maintenance disable %v -To bypass the node version check re-run this with --skip-liveness-check; see this command's -help text for more details on why.`, broker) +to bypass the node version check re-run this with --skip-liveness-check; see this command's +help text for more details on why`, broker) } } } diff --git a/src/go/rpk/pkg/cli/redpanda/config.go b/src/go/rpk/pkg/cli/redpanda/config.go index 2a1259f219775..801d08b27defd 100644 --- a/src/go/rpk/pkg/cli/redpanda/config.go +++ b/src/go/rpk/pkg/cli/redpanda/config.go @@ -22,7 +22,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cobraext" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - vnet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" + vnet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" diff --git a/src/go/rpk/pkg/cli/redpanda/start.go b/src/go/rpk/pkg/cli/redpanda/start.go index b58b05044454d..4482d180d1045 100644 --- a/src/go/rpk/pkg/cli/redpanda/start.go +++ b/src/go/rpk/pkg/cli/redpanda/start.go @@ -23,8 +23,8 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cloud" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" - vos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" + vos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" rp "github.com/redpanda-data/redpanda/src/go/rpk/pkg/redpanda" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/factory" @@ -857,11 +857,11 @@ func parseNamedAddress( if addr == "" { return nil, nil } - scheme, hostport, err := net.ParseHostMaybeScheme(addr) + scheme, hostport, err := netutil.ParseHostMaybeScheme(addr) if err != nil { return nil, err } - host, port := net.SplitHostPortDefault(hostport, defaultPort) + host, port := netutil.SplitHostPortDefault(hostport, defaultPort) return &config.NamedSocketAddress{ Address: host, @@ -896,11 +896,11 @@ func parseNamedAuthNAddress( if err != nil { return nil, err } - scheme, hostport, err := net.ParseHostMaybeScheme(addr) + scheme, hostport, err := netutil.ParseHostMaybeScheme(addr) if err != nil { return nil, err } - host, port := net.SplitHostPortDefault(hostport, defaultPort) + host, port := netutil.SplitHostPortDefault(hostport, defaultPort) return &config.NamedAuthNSocketAddress{ Address: host, diff --git a/src/go/rpk/pkg/cli/redpanda/stop.go b/src/go/rpk/pkg/cli/redpanda/stop.go index ae73397aba4f4..f59c783d46a25 100644 --- a/src/go/rpk/pkg/cli/redpanda/stop.go +++ b/src/go/rpk/pkg/cli/redpanda/stop.go @@ -19,9 +19,9 @@ import ( "time" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/spf13/cobra" "go.uber.org/zap" @@ -51,7 +51,7 @@ running.`, func executeStop(fs afero.Fs, y *config.RedpandaYaml, timeout time.Duration) error { pidFile := y.PIDFile() - isLocked, err := os.CheckLocked(pidFile) + isLocked, err := osutil.CheckLocked(pidFile) if err != nil { zap.L().Sugar().Debugf("error checking if the PID file is locked: %v", err) } @@ -64,7 +64,7 @@ func executeStop(fs afero.Fs, y *config.RedpandaYaml, timeout time.Duration) err ) return nil } - pidStr, err := utils.ReadEnsureSingleLine(fs, pidFile) + pidStr, err := rpkutil.ReadEnsureSingleLine(fs, pidFile) if err != nil { return err } @@ -119,7 +119,7 @@ func poll(pid int, stop <-chan bool, stoppedRunning chan<- bool) { case <-stop: return default: - isRunning, err := os.IsRunningPID(afero.NewOsFs(), pid) + isRunning, err := osutil.IsRunningPID(afero.NewOsFs(), pid) if err != nil { zap.L().Sugar().Error(err) } else if !isRunning { diff --git a/src/go/rpk/pkg/cli/redpanda/stop_test.go b/src/go/rpk/pkg/cli/redpanda/stop_test.go index 2570180de212b..e749670f6447e 100644 --- a/src/go/rpk/pkg/cli/redpanda/stop_test.go +++ b/src/go/rpk/pkg/cli/redpanda/stop_test.go @@ -20,8 +20,8 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/redpanda" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -67,7 +67,7 @@ func TestStopCommand(t *testing.T) { require.NotNil(t, ecmd.Process) pid := ecmd.Process.Pid - _, err = utils.WriteBytes( + _, err = rpkutil.WriteBytes( fs, []byte(strconv.Itoa(pid)), conf.PIDFile(), @@ -85,7 +85,7 @@ func TestStopCommand(t *testing.T) { err = c.Execute() require.NoError(t, err) - isStillRunning, err := os.IsRunningPID( + isStillRunning, err := osutil.IsRunningPID( fs, ecmd.Process.Pid, ) diff --git a/src/go/rpk/pkg/cli/redpanda/tune/BUILD b/src/go/rpk/pkg/cli/redpanda/tune/BUILD index c9a3fa0d8f83e..0325293fd81d7 100644 --- a/src/go/rpk/pkg/cli/redpanda/tune/BUILD +++ b/src/go/rpk/pkg/cli/redpanda/tune/BUILD @@ -13,11 +13,11 @@ go_library( "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/out", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/factory", "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_fatih_color//:color", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", @@ -26,11 +26,11 @@ go_library( "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/out", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/factory", "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_fatih_color//:color", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", diff --git a/src/go/rpk/pkg/cli/redpanda/tune/help.go b/src/go/rpk/pkg/cli/redpanda/tune/help.go index 9dc765e3b6609..6f307df46db8d 100644 --- a/src/go/rpk/pkg/cli/redpanda/tune/help.go +++ b/src/go/rpk/pkg/cli/redpanda/tune/help.go @@ -16,7 +16,7 @@ import ( "fmt" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/cobra" ) @@ -43,7 +43,7 @@ func newHelpCommand() *cobra.Command { } tuner := args[0] tunerList := strings.Join( - utils.GetKeysFromStringMap(tunersHelp), + rpkutil.GetKeysFromStringMap(tunersHelp), ", ", ) if _, contains := tunersHelp[tuner]; !contains { diff --git a/src/go/rpk/pkg/cli/redpanda/tune/tune.go b/src/go/rpk/pkg/cli/redpanda/tune/tune.go index 315a19f9ab52d..3793aafe104df 100644 --- a/src/go/rpk/pkg/cli/redpanda/tune/tune.go +++ b/src/go/rpk/pkg/cli/redpanda/tune/tune.go @@ -170,7 +170,7 @@ func tune( // We exit with code 1 when it's enabled and not supported except // for disk_write_cache since it's only supported for GCP. // We also allow clocksource to fail, see #6444. - exit1 = exit1 || enabled && !supported && !(tunerName == "disk_write_cache" || tunerName == "clocksource") + exit1 = exit1 || enabled && !supported && tunerName != "disk_write_cache" && tunerName != "clocksource" continue } zap.L().Sugar().Debugf("Tuner parameters %+v", params) diff --git a/src/go/rpk/pkg/cli/registry/schema/get.go b/src/go/rpk/pkg/cli/registry/schema/get.go index f6896e090fe94..db380f55e7d30 100644 --- a/src/go/rpk/pkg/cli/registry/schema/get.go +++ b/src/go/rpk/pkg/cli/registry/schema/get.go @@ -80,15 +80,15 @@ To print schema metadata properties, use the '--print-metadata' flag. if schemaFile != "" { n++ } - switch { - case n == 0: - out.Die("Must specify at least one of --schema-version, --id, or --schema.") - case n == 1: + switch n { + case 0: + out.Die("must specify at least one of --schema-version, --id, or --schema") + case 1: default: - out.Die("Must specify only one of --schema-version, --id, or --schema.") + out.Die("must specify only one of --schema-version, --id, or --schema") } if len(args) == 0 && (sversion != "" || schemaFile != "") { - out.Die("Subject must be specified for --schema-version or --schema.") + out.Die("subject must be specified for --schema-version or --schema") } var ss []sr.SubjectSchema diff --git a/src/go/rpk/pkg/cli/root.go b/src/go/rpk/pkg/cli/root.go index b208b5a60dc17..ff46bfa6ccd6d 100644 --- a/src/go/rpk/pkg/cli/root.go +++ b/src/go/rpk/pkg/cli/root.go @@ -56,10 +56,10 @@ func Execute() { p := new(config.Params) runXHelp := func() { for _, o := range p.FlagOverrides { - switch { - case o == "help": + switch o { + case "help": fmt.Print(config.ParamsHelp()) - case o == "list": + case "list": fmt.Print(config.ParamsList()) default: return diff --git a/src/go/rpk/pkg/cli/security/secret/create.go b/src/go/rpk/pkg/cli/security/secret/create.go index bb7efe7381ae3..3e765b7656362 100644 --- a/src/go/rpk/pkg/cli/security/secret/create.go +++ b/src/go/rpk/pkg/cli/security/secret/create.go @@ -116,7 +116,7 @@ func getScopeNames() []string { var scopeNames []string for name := range dataplanev1.Scope_value { if name != dataplanev1.Scope_SCOPE_UNSPECIFIED.String() { - s := strings.Replace(name, "SCOPE_", "", -1) + s := strings.ReplaceAll(name, "SCOPE_", "") s = strings.ToLower(s) scopeNames = append(scopeNames, s) } @@ -128,7 +128,7 @@ func mapNameToScope() map[string]dataplanev1.Scope { nameByScope := make(map[string]dataplanev1.Scope) for name, enum := range dataplanev1.Scope_value { if name != dataplanev1.Scope_SCOPE_UNSPECIFIED.String() { - s := strings.Replace(name, "SCOPE_", "", -1) + s := strings.ReplaceAll(name, "SCOPE_", "") s = strings.ToLower(s) nameByScope[s] = dataplanev1.Scope(enum) } @@ -141,7 +141,7 @@ func mapScopeToName() map[dataplanev1.Scope]string { for name, enum := range dataplanev1.Scope_value { if name != dataplanev1.Scope_SCOPE_UNSPECIFIED.String() { - s := strings.Replace(name, "SCOPE_", "", -1) + s := strings.ReplaceAll(name, "SCOPE_", "") s = strings.ToLower(s) scopeByName[dataplanev1.Scope(enum)] = s } diff --git a/src/go/rpk/pkg/cli/shadow/BUILD b/src/go/rpk/pkg/cli/shadow/BUILD index ea2f85808a70f..5331cbf3b3733 100644 --- a/src/go/rpk/pkg/cli/shadow/BUILD +++ b/src/go/rpk/pkg/cli/shadow/BUILD @@ -24,7 +24,7 @@ go_library( "//src/go/rpk/pkg/adminapi", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth/providers/auth0", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/publicapi", "@build_buf_gen_go_redpandadata_cloud_connectrpc_go//redpanda/api/controlplane/v1/controlplanev1connect", diff --git a/src/go/rpk/pkg/cli/shadow/config.go b/src/go/rpk/pkg/cli/shadow/config.go index 20b4212978ebd..955ec02ccbddf 100644 --- a/src/go/rpk/pkg/cli/shadow/config.go +++ b/src/go/rpk/pkg/cli/shadow/config.go @@ -19,7 +19,7 @@ import ( adminv2comments "github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2" commonv1comments "github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -365,7 +365,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, for _, line := range lines { line = strings.TrimSpace(line) if line != "" { - sb.WriteString(fmt.Sprintf("%s# %s\n", indentStr, line)) + fmt.Fprintf(sb, "%s# %s\n", indentStr, line) } } } @@ -374,7 +374,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, fieldName := string(field.Name()) // Write the field name - sb.WriteString(fmt.Sprintf("%s%s:", indentStr, fieldName)) + fmt.Fprintf(sb, "%s%s:", indentStr, fieldName) // Handle different field types if field.IsMap() { @@ -477,9 +477,9 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, // Strip enum prefix to match rpk command expectations strippedName := stripEnumPrefix(enumValue) if enumComment != "" { - sb.WriteString(fmt.Sprintf(" %s # %s\n", strippedName, enumComment)) + fmt.Fprintf(sb, " %s # %s\n", strippedName, enumComment) } else { - sb.WriteString(fmt.Sprintf(" %s\n", strippedName)) + fmt.Fprintf(sb, " %s\n", strippedName) } } else { sb.WriteString(" 0\n") diff --git a/src/go/rpk/pkg/cli/shadow/update.go b/src/go/rpk/pkg/cli/shadow/update.go index 197c2ee3e6026..0d5af100510e8 100644 --- a/src/go/rpk/pkg/cli/shadow/update.go +++ b/src/go/rpk/pkg/cli/shadow/update.go @@ -22,7 +22,7 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi" "github.com/spf13/afero" @@ -106,14 +106,14 @@ Update a Shadow Link configuration: } // Second part: open editor and get updated configuration. - updatedCfg, err := rpkos.EditTmpYAMLFile(fs, originalCfg) + updatedCfg, err := rpkos.EditTmpYAMLFile(cmd.Context(), fs, originalCfg) out.MaybeDie(err, "unable to edit Shadow Link configuration: %v", err) err = validateParsedShadowLinkConfig(updatedCfg) out.MaybeDie(err, "invalid Shadow Link configuration: %v", err) if updatedCfg.Name != originalCfg.Name { - out.Die("Shadow Link name cannot be changed; if you need to rename, please delete and recreate the shadow link") + out.Die("shadow link name cannot be changed; if you need to rename, please delete and recreate the shadow link") } // Third part: calculate diff. diff --git a/src/go/rpk/pkg/cli/topic/BUILD b/src/go/rpk/pkg/cli/topic/BUILD index cf86fac87fb24..59655a672111c 100644 --- a/src/go/rpk/pkg/cli/topic/BUILD +++ b/src/go/rpk/pkg/cli/topic/BUILD @@ -24,9 +24,9 @@ go_library( "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/kafka", "//src/go/rpk/pkg/out", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/schemaregistry", "//src/go/rpk/pkg/serde", - "//src/go/rpk/pkg/utils", "@com_github_docker_go_units//:go-units", "@com_github_hashicorp_go_multierror//:go-multierror", "@com_github_redpanda_data_common_go_rpadmin//:rpadmin", diff --git a/src/go/rpk/pkg/cli/topic/add_partitions.go b/src/go/rpk/pkg/cli/topic/add_partitions.go index 3039b7ee5d907..c0d00b244ba1a 100644 --- a/src/go/rpk/pkg/cli/topic/add_partitions.go +++ b/src/go/rpk/pkg/cli/topic/add_partitions.go @@ -48,7 +48,7 @@ func newAddPartitionsCommand(fs afero.Fs, p *config.Params) *cobra.Command { defer adm.Close() if num <= 0 { - out.Die("--num (-n) should be a positive value, exiting!") + out.Die("--num (-n) should be a positive value") } resps, err := adm.CreatePartitions(context.Background(), num, topics...) diff --git a/src/go/rpk/pkg/cli/topic/config.go b/src/go/rpk/pkg/cli/topic/config.go index 1a3114509b015..f3997cd941584 100644 --- a/src/go/rpk/pkg/cli/topic/config.go +++ b/src/go/rpk/pkg/cli/topic/config.go @@ -111,7 +111,7 @@ Use the flag '--no-confirm' to avoid the confirmation prompt.`, confirmed, err := out.Confirm("Warning: disabling Tiered Storage may lead to data loss. If you only want to pause Tiered Storage temporarily, use the 'cloud_storage_enable_segment_uploads' option. Abort?") out.MaybeDie(err, "unable to read user input: %v", err) if confirmed { - out.Die("Aborted by user.") + out.Die("aborted by user") } } } diff --git a/src/go/rpk/pkg/cli/topic/consume.go b/src/go/rpk/pkg/cli/topic/consume.go index 1897025a7295f..fa9c9a470453e 100644 --- a/src/go/rpk/pkg/cli/topic/consume.go +++ b/src/go/rpk/pkg/cli/topic/consume.go @@ -359,7 +359,7 @@ func (c *consumer) parseOffset( // (a) list the start offsets to know what to consume from, // (b) list the end offsets to define what to consume to, // (c) filter partitions that have nothing to consume. - if !(hasEnd || currentEnd) { + if !hasEnd && !currentEnd { return nil } diff --git a/src/go/rpk/pkg/cli/topic/describe_storage.go b/src/go/rpk/pkg/cli/topic/describe_storage.go index d64666ecf894a..fd1eac75c6ab2 100644 --- a/src/go/rpk/pkg/cli/topic/describe_storage.go +++ b/src/go/rpk/pkg/cli/topic/describe_storage.go @@ -100,7 +100,7 @@ func newDescribeStorageCommand(fs afero.Fs, p *config.Params) *cobra.Command { out.Die(err.Error()) } if len(report) == 0 { - out.Die("error: could not get any status report from cloud storage.") + out.Die("could not get any status report from cloud storage") } sort.Slice(report, func(i, j int) bool { return report[i].Partition < report[j].Partition diff --git a/src/go/rpk/pkg/cli/topic/trim.go b/src/go/rpk/pkg/cli/topic/trim.go index 99a5889966c05..9c69fada1c17d 100644 --- a/src/go/rpk/pkg/cli/topic/trim.go +++ b/src/go/rpk/pkg/cli/topic/trim.go @@ -86,10 +86,10 @@ Trim records from a JSON file } } else { if len(args) == 0 { - out.Die("Error: required arg 'topic' not set\n%v", cmd.UsageString()) + out.Die("required arg 'topic' not set\n%v", cmd.UsageString()) } if offset == "" { - out.Die("Error: required flag 'offset' not set\n%v", cmd.UsageString()) + out.Die("required flag 'offset' not set\n%v", cmd.UsageString()) } topic := args[0] o, err = parseOffsetArgs(cmd.Context(), adm, topic, offset, partitions) diff --git a/src/go/rpk/pkg/cli/topic/utils.go b/src/go/rpk/pkg/cli/topic/utils.go index efa1bd9d64adf..e746bc19f323d 100644 --- a/src/go/rpk/pkg/cli/topic/utils.go +++ b/src/go/rpk/pkg/cli/topic/utils.go @@ -14,7 +14,7 @@ import ( "fmt" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/twmb/franz-go/pkg/kadm" ) @@ -57,7 +57,7 @@ func regexTopics(adm *kadm.Client, expressions []string) ([]string, error) { return nil, fmt.Errorf("unable to list topics: %w", err) } - return utils.RegexListedItems(topics.Names(), expressions) + return rpkutil.RegexListedItems(topics.Names(), expressions) } func regexTopicDetails(adm *kadm.Client, expressions []string) (kadm.TopicDetails, error) { @@ -66,14 +66,14 @@ func regexTopicDetails(adm *kadm.Client, expressions []string) (kadm.TopicDetail return nil, fmt.Errorf("unable to list topics: %w", err) } - compiled, err := utils.CompileRegexExpressions(expressions) + compiled, err := rpkutil.CompileRegexExpressions(expressions) if err != nil { return nil, fmt.Errorf("unable to compile regex expressions: %w", err) } result := make(kadm.TopicDetails) for name, topic := range topics { - if utils.MatchesAnyRegex(name, compiled) { + if rpkutil.MatchesAnyRegex(name, compiled) { result[name] = topic } } diff --git a/src/go/rpk/pkg/cli/transform/buildpack/BUILD b/src/go/rpk/pkg/cli/transform/buildpack/BUILD index e4b4ea9ce664d..dd29686f768c4 100644 --- a/src/go/rpk/pkg/cli/transform/buildpack/BUILD +++ b/src/go/rpk/pkg/cli/transform/buildpack/BUILD @@ -7,8 +7,8 @@ go_library( visibility = ["//visibility:public"], deps = [ "//src/go/rpk/pkg/httpapi", - "//src/go/rpk/pkg/os", - "//src/go/rpk/pkg/utils", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "@com_github_schollz_progressbar_v3//:progressbar", "@com_github_spf13_afero//:afero", "@org_golang_x_sync//errgroup", diff --git a/src/go/rpk/pkg/cli/transform/buildpack/buildpack.go b/src/go/rpk/pkg/cli/transform/buildpack/buildpack.go index 632e86f7ae308..1d6f32aaf946d 100644 --- a/src/go/rpk/pkg/cli/transform/buildpack/buildpack.go +++ b/src/go/rpk/pkg/cli/transform/buildpack/buildpack.go @@ -30,8 +30,8 @@ import ( "time" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/httpapi" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/schollz/progressbar/v3" "github.com/spf13/afero" "golang.org/x/sync/errgroup" @@ -164,7 +164,7 @@ func (bp *Buildpack) IsUpToDate(fs afero.Fs) (bool, error) { if !ok { return false, nil } - got, err := utils.ReadEnsureSingleLine(fs, path) + got, err := rpkutil.ReadEnsureSingleLine(fs, path) return got == want, err } diff --git a/src/go/rpk/pkg/config/BUILD b/src/go/rpk/pkg/config/BUILD index 4208b3541e749..11029c550cb24 100644 --- a/src/go/rpk/pkg/config/BUILD +++ b/src/go/rpk/pkg/config/BUILD @@ -14,8 +14,8 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config", visibility = ["//visibility:public"], deps = [ - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/controlplane/v1:controlplane", "@com_github_fatih_color//:color", @@ -48,8 +48,8 @@ go_test( "HOME": "$TEST_TMPDIR", }, deps = [ + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/testfs", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", "@in_gopkg_yaml_v3//:yaml_v3", diff --git a/src/go/rpk/pkg/config/config.go b/src/go/rpk/pkg/config/config.go index 0b84d7e3d479b..8ecb8b7f2b725 100644 --- a/src/go/rpk/pkg/config/config.go +++ b/src/go/rpk/pkg/config/config.go @@ -84,7 +84,7 @@ type Config struct { // ALLOW_RPK_CLOUD_ADMIN override. func CheckExitCloudAdmin(p *RpkProfile) { if p.FromCloud && !p.DevOverrides().AllowRpkCloudAdmin { - out.Die("This admin API based command is not supported on Redpanda Cloud clusters.") + out.Die("this admin API based command is not supported on Redpanda Cloud clusters") } } @@ -92,7 +92,7 @@ func CheckExitCloudAdmin(p *RpkProfile) { // cluster is a Serverless cluster. func CheckExitServerlessAdmin(p *RpkProfile) { if p.FromCloud && p.CloudCluster.IsServerless() { - out.Die("This admin API based command is not supported on Redpanda Cloud serverless clusters.") + out.Die("this admin API based command is not supported on Redpanda Cloud serverless clusters") } } @@ -100,7 +100,7 @@ func CheckExitServerlessAdmin(p *RpkProfile) { // cluster is NOT a Serverless cluster. func CheckExitNotServerlessAdmin(p *RpkProfile) { if p.FromCloud && !p.CloudCluster.IsServerless() { - out.Die("This admin API based command is not supported on Redpanda Cloud clusters.") + out.Die("this admin API based command is not supported on Redpanda Cloud clusters") } } diff --git a/src/go/rpk/pkg/config/config_test.go b/src/go/rpk/pkg/config/config_test.go index 1dd0ade553fa7..5177262af3ccd 100644 --- a/src/go/rpk/pkg/config/config_test.go +++ b/src/go/rpk/pkg/config/config_test.go @@ -12,7 +12,7 @@ package config import ( "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -749,7 +749,7 @@ schema_registry: {} path := tt.conf().FileLocation() fs := afero.NewMemMapFs() if tt.existingConf != "" { - _, err := utils.WriteBytes(fs, []byte(tt.existingConf), path) + _, err := rpkutil.WriteBytes(fs, []byte(tt.existingConf), path) require.NoError(t, err) } diff --git a/src/go/rpk/pkg/config/params.go b/src/go/rpk/pkg/config/params.go index 74c1f5782a6da..7a02d7a01822d 100644 --- a/src/go/rpk/pkg/config/params.go +++ b/src/go/rpk/pkg/config/params.go @@ -34,7 +34,7 @@ import ( "github.com/spf13/cobra" "gopkg.in/yaml.v3" - rpknet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" + rpknet "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" ) diff --git a/src/go/rpk/pkg/config/profile_doc.go b/src/go/rpk/pkg/config/profile_doc.go index d1cfda9f45938..ff3ee0faa4d6c 100644 --- a/src/go/rpk/pkg/config/profile_doc.go +++ b/src/go/rpk/pkg/config/profile_doc.go @@ -149,8 +149,8 @@ func writeDocumentedStruct(buf *bytes.Buffer, v reflect.Value, t reflect.Type, p } else { // Hack: Add warning before cloud-managed fields. if fullPath == "from_cloud" { - buf.WriteString(fmt.Sprintf("%s# The following fields are managed by rpk. Altering them manually may\n", indentStr)) - buf.WriteString(fmt.Sprintf("%s# result in unexpected behavior.\n", indentStr)) + fmt.Fprintf(buf, "%s# The following fields are managed by rpk. Altering them manually may\n", indentStr) + fmt.Fprintf(buf, "%s# result in unexpected behavior.\n", indentStr) } if err := writeValueField(buf, fieldName, fieldValue, doc, fullPath, indentStr); err != nil { return err @@ -219,7 +219,7 @@ func isEmptyValue(v reflect.Value) bool { func writeCommentedField(buf *bytes.Buffer, name string, t reflect.Type, doc, fullPath, indent string) { // Write documentation comment if doc != "" { - buf.WriteString(fmt.Sprintf("%s# %s\n", indent, doc)) + fmt.Fprintf(buf, "%s# %s\n", indent, doc) } // Handle pointer types @@ -231,16 +231,16 @@ func writeCommentedField(buf *bytes.Buffer, name string, t reflect.Type, doc, fu switch t.Kind() { case reflect.Struct: // Write struct template as comment - buf.WriteString(fmt.Sprintf("%s# %s:\n", indent, name)) + fmt.Fprintf(buf, "%s# %s:\n", indent, name) writeCommentedStructTemplate(buf, t, fullPath, indent+" ") case reflect.Slice: - buf.WriteString(fmt.Sprintf("%s# %s: []\n", indent, name)) + fmt.Fprintf(buf, "%s# %s: []\n", indent, name) case reflect.Bool: - buf.WriteString(fmt.Sprintf("%s# %s: false\n", indent, name)) + fmt.Fprintf(buf, "%s# %s: false\n", indent, name) case reflect.String: - buf.WriteString(fmt.Sprintf("%s# %s: \"\"\n", indent, name)) + fmt.Fprintf(buf, "%s# %s: \"\"\n", indent, name) default: - buf.WriteString(fmt.Sprintf("%s# %s:\n", indent, name)) + fmt.Fprintf(buf, "%s# %s:\n", indent, name) } } @@ -277,7 +277,7 @@ func writeCommentedStructTemplate(buf *bytes.Buffer, t reflect.Type, pathPrefix, doc := profileFieldDocs[fullPath] if doc != "" { - buf.WriteString(fmt.Sprintf("%s# %s\n", indent, doc)) + fmt.Fprintf(buf, "%s# %s\n", indent, doc) } fieldType := field.Type @@ -287,16 +287,16 @@ func writeCommentedStructTemplate(buf *bytes.Buffer, t reflect.Type, pathPrefix, switch fieldType.Kind() { case reflect.Struct: - buf.WriteString(fmt.Sprintf("%s# %s:\n", indent, fieldName)) + fmt.Fprintf(buf, "%s# %s:\n", indent, fieldName) writeCommentedStructTemplate(buf, fieldType, fullPath, indent+" ") case reflect.Slice: - buf.WriteString(fmt.Sprintf("%s# %s: []\n", indent, fieldName)) + fmt.Fprintf(buf, "%s# %s: []\n", indent, fieldName) case reflect.Bool: - buf.WriteString(fmt.Sprintf("%s# %s: false\n", indent, fieldName)) + fmt.Fprintf(buf, "%s# %s: false\n", indent, fieldName) case reflect.String: - buf.WriteString(fmt.Sprintf("%s# %s: \"\"\n", indent, fieldName)) + fmt.Fprintf(buf, "%s# %s: \"\"\n", indent, fieldName) default: - buf.WriteString(fmt.Sprintf("%s# %s:\n", indent, fieldName)) + fmt.Fprintf(buf, "%s# %s:\n", indent, fieldName) } } } @@ -313,23 +313,23 @@ func writeValueField(buf *bytes.Buffer, name string, v reflect.Value, doc, fullP // Write documentation comment on top (if present) if doc != "" { - buf.WriteString(fmt.Sprintf("%s# %s\n", indent, doc)) + fmt.Fprintf(buf, "%s# %s\n", indent, doc) } switch v.Kind() { case reflect.Struct: // If struct is empty, write as {} to preserve semantics. (e.g., tls: {}) if isStructAllEmpty(v) { - buf.WriteString(fmt.Sprintf("%s%s: {}\n", indent, name)) + fmt.Fprintf(buf, "%s%s: {}\n", indent, name) } else { - buf.WriteString(fmt.Sprintf("%s%s:\n", indent, name)) + fmt.Fprintf(buf, "%s%s:\n", indent, name) if err := writeDocumentedStruct(buf, v, v.Type(), fullPath, len(indent)/2+1); err != nil { return err } } case reflect.Slice: - buf.WriteString(fmt.Sprintf("%s%s:\n", indent, name)) + fmt.Fprintf(buf, "%s%s:\n", indent, name) for i := 0; i < v.Len(); i++ { elem := v.Index(i) if err := writeSliceElement(buf, elem, indent+" "); err != nil { @@ -342,17 +342,17 @@ func writeValueField(buf *bytes.Buffer, name string, v reflect.Value, doc, fullP if needsQuoting(val) { val = fmt.Sprintf("%q", val) } - buf.WriteString(fmt.Sprintf("%s%s: %s\n", indent, name, val)) + fmt.Fprintf(buf, "%s%s: %s\n", indent, name, val) case reflect.Bool: val := "false" if v.Bool() { val = "true" } - buf.WriteString(fmt.Sprintf("%s%s: %s\n", indent, name, val)) + fmt.Fprintf(buf, "%s%s: %s\n", indent, name, val) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - buf.WriteString(fmt.Sprintf("%s%s: %d\n", indent, name, v.Int())) + fmt.Fprintf(buf, "%s%s: %d\n", indent, name, v.Int()) default: // Use yaml.Marshal for other types. @@ -361,7 +361,7 @@ func writeValueField(buf *bytes.Buffer, name string, v reflect.Value, doc, fullP return fmt.Errorf("marshal field %q: %w", name, err) } val := strings.TrimSpace(string(valBytes)) - buf.WriteString(fmt.Sprintf("%s%s: %s\n", indent, name, val)) + fmt.Fprintf(buf, "%s%s: %s\n", indent, name, val) } return nil } @@ -380,7 +380,7 @@ func writeSliceElement(buf *bytes.Buffer, v reflect.Value, indent string) error if needsQuoting(val) { val = fmt.Sprintf("%q", val) } - buf.WriteString(fmt.Sprintf("%s- %s\n", indent, val)) + fmt.Fprintf(buf, "%s- %s\n", indent, val) case reflect.Struct: // First field on same line as dash, rest indented @@ -404,14 +404,14 @@ func writeSliceElement(buf *bytes.Buffer, v reflect.Value, indent string) error } if first { - buf.WriteString(fmt.Sprintf("%s- %s: ", indent, fieldName)) + fmt.Fprintf(buf, "%s- %s: ", indent, fieldName) if err := writeInlineValue(buf, fieldValue); err != nil { return err } buf.WriteString("\n") first = false } else { - buf.WriteString(fmt.Sprintf("%s %s: ", indent, fieldName)) + fmt.Fprintf(buf, "%s %s: ", indent, fieldName) if err := writeInlineValue(buf, fieldValue); err != nil { return err } @@ -420,7 +420,7 @@ func writeSliceElement(buf *bytes.Buffer, v reflect.Value, indent string) error } if first { // Empty struct - buf.WriteString(fmt.Sprintf("%s- {}\n", indent)) + fmt.Fprintf(buf, "%s- {}\n", indent) } default: @@ -428,7 +428,7 @@ func writeSliceElement(buf *bytes.Buffer, v reflect.Value, indent string) error if err != nil { return fmt.Errorf("marshal slice element: %w", err) } - buf.WriteString(fmt.Sprintf("%s- %s", indent, strings.TrimSpace(string(valBytes)))) + fmt.Fprintf(buf, "%s- %s", indent, strings.TrimSpace(string(valBytes))) if !strings.HasSuffix(string(valBytes), "\n") { buf.WriteString("\n") } @@ -449,7 +449,7 @@ func writeInlineValue(buf *bytes.Buffer, v reflect.Value) error { case reflect.String: val := v.String() if needsQuoting(val) { - buf.WriteString(fmt.Sprintf("%q", val)) + fmt.Fprintf(buf, "%q", val) } else { buf.WriteString(val) } @@ -460,7 +460,7 @@ func writeInlineValue(buf *bytes.Buffer, v reflect.Value) error { buf.WriteString("false") } case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - buf.WriteString(fmt.Sprintf("%d", v.Int())) + fmt.Fprintf(buf, "%d", v.Int()) default: valBytes, err := yaml.Marshal(v.Interface()) if err != nil { diff --git a/src/go/rpk/pkg/config/redpanda_yaml.go b/src/go/rpk/pkg/config/redpanda_yaml.go index a3d375733f121..4f07cea52df14 100644 --- a/src/go/rpk/pkg/config/redpanda_yaml.go +++ b/src/go/rpk/pkg/config/redpanda_yaml.go @@ -19,7 +19,7 @@ import ( "github.com/twmb/tlscfg" "gopkg.in/yaml.v3" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" ) // DefaultRedpandaYamlPath is where redpanda's configuration is located by diff --git a/src/go/rpk/pkg/config/rpk_yaml.go b/src/go/rpk/pkg/config/rpk_yaml.go index c5233e0882ca5..698762406f127 100644 --- a/src/go/rpk/pkg/config/rpk_yaml.go +++ b/src/go/rpk/pkg/config/rpk_yaml.go @@ -20,7 +20,7 @@ import ( controlplanev1 "buf.build/gen/go/redpandadata/cloud/protocolbuffers/go/redpanda/api/controlplane/v1" "github.com/fatih/color" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/spf13/afero" "go.uber.org/zap" "gopkg.in/yaml.v3" @@ -482,7 +482,7 @@ func (c *RpkCloudCluster) CheckClusterURL() (string, error) { // MarshalText implements encoding.TextMarshaler. func (d Duration) MarshalText() ([]byte, error) { - return []byte(d.Duration.String()), nil + return []byte(d.String()), nil } // UnmarshalText implements encoding.TextUnmarshaler. diff --git a/src/go/rpk/pkg/net/BUILD b/src/go/rpk/pkg/netutil/BUILD similarity index 52% rename from src/go/rpk/pkg/net/BUILD rename to src/go/rpk/pkg/netutil/BUILD index 1126a930aaaec..2a964603d731b 100644 --- a/src/go/rpk/pkg/net/BUILD +++ b/src/go/rpk/pkg/netutil/BUILD @@ -21,3 +21,24 @@ go_test( embed = [":net"], deps = ["@com_github_stretchr_testify//require"], ) + +go_library( + name = "netutil", + srcs = [ + "hostport.go", + "interfaces.go", + ], + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil", + visibility = ["//visibility:public"], + deps = [ + "//src/go/rpk/pkg/rpkutil", + "@org_uber_go_zap//:zap", + ], +) + +go_test( + name = "netutil_test", + srcs = ["hostport_test.go"], + embed = [":netutil"], + deps = ["@com_github_stretchr_testify//require"], +) diff --git a/src/go/rpk/pkg/net/hostport.go b/src/go/rpk/pkg/netutil/hostport.go similarity index 99% rename from src/go/rpk/pkg/net/hostport.go rename to src/go/rpk/pkg/netutil/hostport.go index dea9d36e6a93e..be145d71a7bc2 100644 --- a/src/go/rpk/pkg/net/hostport.go +++ b/src/go/rpk/pkg/netutil/hostport.go @@ -1,4 +1,4 @@ -package net +package netutil import ( "fmt" diff --git a/src/go/rpk/pkg/net/hostport_test.go b/src/go/rpk/pkg/netutil/hostport_test.go similarity index 99% rename from src/go/rpk/pkg/net/hostport_test.go rename to src/go/rpk/pkg/netutil/hostport_test.go index 5312a1a22e7c8..f65de78513eb2 100644 --- a/src/go/rpk/pkg/net/hostport_test.go +++ b/src/go/rpk/pkg/netutil/hostport_test.go @@ -1,4 +1,4 @@ -package net +package netutil import ( "strings" diff --git a/src/go/rpk/pkg/net/interfaces.go b/src/go/rpk/pkg/netutil/interfaces.go similarity index 89% rename from src/go/rpk/pkg/net/interfaces.go rename to src/go/rpk/pkg/netutil/interfaces.go index 7fdf3ce402e54..e14660e9c593f 100644 --- a/src/go/rpk/pkg/net/interfaces.go +++ b/src/go/rpk/pkg/netutil/interfaces.go @@ -7,12 +7,12 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package net +package netutil import ( "net" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "go.uber.org/zap" ) @@ -25,6 +25,7 @@ func GetInterfacesByIps(addresses ...string) ([]string, error) { } for i, address := range addresses { + //nolint:noctx // Internally it uses context.Background, no need for a major refactor as this is used as a one-shot in Tuners. resolvedIps, err := net.LookupIP(address) if err != nil { zap.L().Sugar().Debugf("Can't resolve address '%s', err: %s", address, err) @@ -62,7 +63,7 @@ func GetInterfacesByIps(addresses ...string) ([]string, error) { } } - return utils.GetKeys(nics), nil + return rpkutil.GetKeys(nics), nil } func getFreePort() (uint, error) { diff --git a/src/go/rpk/pkg/oauth/BUILD b/src/go/rpk/pkg/oauth/BUILD index f6605d1d4ef68..ff6bb242f9648 100644 --- a/src/go/rpk/pkg/oauth/BUILD +++ b/src/go/rpk/pkg/oauth/BUILD @@ -12,7 +12,7 @@ go_library( deps = [ "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/oauth/authtoken", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/publicapi", "@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/iam/v1:iam", "@com_connectrpc_connect//:connect", diff --git a/src/go/rpk/pkg/oauth/load.go b/src/go/rpk/pkg/oauth/load.go index dc4ba7ff1bab8..9b7f7ee6e251b 100644 --- a/src/go/rpk/pkg/oauth/load.go +++ b/src/go/rpk/pkg/oauth/load.go @@ -16,7 +16,7 @@ import ( iamv1 "buf.build/gen/go/redpandadata/cloud/protocolbuffers/go/redpanda/api/iam/v1" "connectrpc.com/connect" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi" "github.com/spf13/afero" "go.uber.org/zap" diff --git a/src/go/rpk/pkg/os/BUILD b/src/go/rpk/pkg/osutil/BUILD similarity index 51% rename from src/go/rpk/pkg/os/BUILD rename to src/go/rpk/pkg/osutil/BUILD index 324207cc13dfa..32b7abf6ce78a 100644 --- a/src/go/rpk/pkg/os/BUILD +++ b/src/go/rpk/pkg/osutil/BUILD @@ -35,3 +35,38 @@ go_test( "@com_github_stretchr_testify//require", ], ) + +go_library( + name = "osutil", + srcs = [ + "commands.go", + "directory.go", + "file.go", + "file_all.go", + "file_windows.go", + "lock.go", + "proc.go", + ], + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil", + visibility = ["//visibility:public"], + deps = [ + "//src/go/rpk/pkg/rpkutil", + "@com_github_spf13_afero//:afero", + "@in_gopkg_yaml_v3//:yaml_v3", + "@org_uber_go_zap//:zap", + ], +) + +go_test( + name = "osutil_test", + srcs = [ + "file_test.go", + "proc_test.go", + ], + embed = [":osutil"], + deps = [ + "//src/go/rpk/pkg/rpkutil", + "@com_github_spf13_afero//:afero", + "@com_github_stretchr_testify//require", + ], +) diff --git a/src/go/rpk/pkg/os/commands.go b/src/go/rpk/pkg/osutil/commands.go similarity index 98% rename from src/go/rpk/pkg/os/commands.go rename to src/go/rpk/pkg/osutil/commands.go index 4cb166cf943f2..2b8543829af38 100644 --- a/src/go/rpk/pkg/os/commands.go +++ b/src/go/rpk/pkg/osutil/commands.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os +package osutil import "time" diff --git a/src/go/rpk/pkg/os/directory.go b/src/go/rpk/pkg/osutil/directory.go similarity index 98% rename from src/go/rpk/pkg/os/directory.go rename to src/go/rpk/pkg/osutil/directory.go index dbb723b304b8d..b36d7d7e3c3f5 100644 --- a/src/go/rpk/pkg/os/directory.go +++ b/src/go/rpk/pkg/osutil/directory.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os +package osutil import ( "fmt" diff --git a/src/go/rpk/pkg/os/file.go b/src/go/rpk/pkg/osutil/file.go similarity index 91% rename from src/go/rpk/pkg/os/file.go rename to src/go/rpk/pkg/osutil/file.go index 23df9a4eab5ab..f5d5ff68fd076 100644 --- a/src/go/rpk/pkg/os/file.go +++ b/src/go/rpk/pkg/osutil/file.go @@ -7,10 +7,11 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os +package osutil import ( "bytes" + "context" "errors" "fmt" "math/rand" @@ -83,7 +84,7 @@ func ReplaceFile(fs afero.Fs, filename string, contents []byte, newPerms os.File // EditTmpFile writes f to a temporary file, launches the user's editor, and // returns the contents of the file (and deletes the file) after the editor is // closed. -func EditTmpFile(fs afero.Fs, f []byte) ([]byte, error) { +func EditTmpFile(ctx context.Context, fs afero.Fs, f []byte) ([]byte, error) { file, err := afero.TempFile(fs, "/tmp", "rpk_*.yaml") filename := file.Name() defer func() { @@ -116,7 +117,7 @@ func EditTmpFile(fs afero.Fs, f []byte) ([]byte, error) { } } - child := exec.Command(editor, filename) + child := exec.CommandContext(ctx, editor, filename) child.Stdout = os.Stdout child.Stderr = os.Stderr child.Stdin = os.Stdin @@ -134,13 +135,13 @@ func EditTmpFile(fs afero.Fs, f []byte) ([]byte, error) { // EditTmpYAMLFile is the same as EditTmpFile, but yaml.Marshal's v // before writing and decodes into and returns a new T. -func EditTmpYAMLFile[T any](fs afero.Fs, v T) (T, error) { +func EditTmpYAMLFile[T any](ctx context.Context, fs afero.Fs, v T) (T, error) { var update T f, err := yaml.Marshal(v) if err != nil { return update, fmt.Errorf("unable to encode: %w", err) } - read, err := EditTmpFile(fs, f) + read, err := EditTmpFile(ctx, fs, f) if err != nil { return update, fmt.Errorf("unable to edit: %w", err) } @@ -164,13 +165,13 @@ func decodeStrictYAML(b []byte, v any) error { // EditTmpYAMLFileWithEncoder is like EditTmpYAMLFile but accepts a custom // encoder function to generate the initial YAML content. This allows for // customization such as adding documentation comments. -func EditTmpYAMLFileWithEncoder[T any](fs afero.Fs, v T, encode func(T) ([]byte, error)) (T, error) { +func EditTmpYAMLFileWithEncoder[T any](ctx context.Context, fs afero.Fs, v T, encode func(T) ([]byte, error)) (T, error) { var update T f, err := encode(v) if err != nil { return update, fmt.Errorf("unable to encode: %w", err) } - read, err := EditTmpFile(fs, f) + read, err := EditTmpFile(ctx, fs, f) if err != nil { return update, fmt.Errorf("unable to edit: %w", err) } diff --git a/src/go/rpk/pkg/os/file_all.go b/src/go/rpk/pkg/osutil/file_all.go similarity index 98% rename from src/go/rpk/pkg/os/file_all.go rename to src/go/rpk/pkg/osutil/file_all.go index b4cdd1273def1..ee78ab5e70407 100644 --- a/src/go/rpk/pkg/os/file_all.go +++ b/src/go/rpk/pkg/osutil/file_all.go @@ -9,7 +9,7 @@ //go:build !windows -package os +package osutil import ( "fmt" diff --git a/src/go/rpk/pkg/os/file_test.go b/src/go/rpk/pkg/osutil/file_test.go similarity index 98% rename from src/go/rpk/pkg/os/file_test.go rename to src/go/rpk/pkg/osutil/file_test.go index 9f02e2e2df5df..6fb5f1ad71f31 100644 --- a/src/go/rpk/pkg/os/file_test.go +++ b/src/go/rpk/pkg/osutil/file_test.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os +package osutil import ( "testing" diff --git a/src/go/rpk/pkg/os/file_windows.go b/src/go/rpk/pkg/osutil/file_windows.go similarity index 97% rename from src/go/rpk/pkg/os/file_windows.go rename to src/go/rpk/pkg/osutil/file_windows.go index 34d5162e29841..d0c5d8b030260 100644 --- a/src/go/rpk/pkg/os/file_windows.go +++ b/src/go/rpk/pkg/osutil/file_windows.go @@ -9,7 +9,7 @@ //go:build windows -package os +package osutil import ( "os" diff --git a/src/go/rpk/pkg/os/lock.go b/src/go/rpk/pkg/osutil/lock.go similarity index 98% rename from src/go/rpk/pkg/os/lock.go rename to src/go/rpk/pkg/osutil/lock.go index 41ca94491c187..ba6e6b8f95951 100644 --- a/src/go/rpk/pkg/os/lock.go +++ b/src/go/rpk/pkg/osutil/lock.go @@ -9,7 +9,7 @@ //go:build !windows -package os +package osutil import ( "os" diff --git a/src/go/rpk/pkg/os/proc.go b/src/go/rpk/pkg/osutil/proc.go similarity index 96% rename from src/go/rpk/pkg/os/proc.go rename to src/go/rpk/pkg/osutil/proc.go index 1582045ff109f..edcb2f22d5c61 100644 --- a/src/go/rpk/pkg/os/proc.go +++ b/src/go/rpk/pkg/osutil/proc.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os +package osutil import ( "bytes" @@ -19,7 +19,7 @@ import ( "strings" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -54,7 +54,7 @@ func IsRunningPID(fs afero.Fs, pid int) (bool, error) { // section "/proc/[pid]/stat" for info on the info layout and possible // process states. deadStates := []string{"Z", "X", "x"} - l, err := utils.ReadEnsureSingleLine( + l, err := rpkutil.ReadEnsureSingleLine( fs, fmt.Sprintf("/proc/%d/stat", pid), ) diff --git a/src/go/rpk/pkg/os/proc_test.go b/src/go/rpk/pkg/osutil/proc_test.go similarity index 87% rename from src/go/rpk/pkg/os/proc_test.go rename to src/go/rpk/pkg/osutil/proc_test.go index 6a1b769c5c1e9..68308d28e2ecc 100644 --- a/src/go/rpk/pkg/os/proc_test.go +++ b/src/go/rpk/pkg/osutil/proc_test.go @@ -7,14 +7,14 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package os_test +package osutil_test import ( "fmt" "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -28,7 +28,7 @@ func TestIsRunningPID(t *testing.T) { defaultSetup := func(state string) beforeFunc { return func(fs afero.Fs) error { contents := fmt.Sprintf(fileFmt, state) - _, err := utils.WriteBytes(fs, []byte(contents), path) + _, err := rpkutil.WriteBytes(fs, []byte(contents), path) return err } } @@ -65,7 +65,7 @@ func TestIsRunningPID(t *testing.T) { { name: "it should fail if the file is corrupt", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes(fs, []byte("lolwut"), path) + _, err := rpkutil.WriteBytes(fs, []byte("lolwut"), path) return err }, expectedErr: "corrupt info for process 4321", @@ -79,7 +79,7 @@ func TestIsRunningPID(t *testing.T) { err := tt.before(fs) require.NoError(t, err) } - running, err := os.IsRunningPID(fs, pid) + running, err := osutil.IsRunningPID(fs, pid) if tt.expectedErr != "" { require.EqualError(t, err, tt.expectedErr) return diff --git a/src/go/rpk/pkg/plugin/BUILD b/src/go/rpk/pkg/plugin/BUILD index 54b8ed5919fbe..55485ebaea5b5 100644 --- a/src/go/rpk/pkg/plugin/BUILD +++ b/src/go/rpk/pkg/plugin/BUILD @@ -12,7 +12,7 @@ go_library( deps = [ "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/httpapi", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", "@in_gopkg_yaml_v3//:yaml_v3", diff --git a/src/go/rpk/pkg/plugin/plugin.go b/src/go/rpk/pkg/plugin/plugin.go index 883e0fcbc46b7..033d995309577 100644 --- a/src/go/rpk/pkg/plugin/plugin.go +++ b/src/go/rpk/pkg/plugin/plugin.go @@ -31,7 +31,7 @@ import ( "go.uber.org/zap" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/httpapi" - rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/spf13/afero" ) diff --git a/src/go/rpk/pkg/utils/BUILD b/src/go/rpk/pkg/rpkutil/BUILD similarity index 52% rename from src/go/rpk/pkg/utils/BUILD rename to src/go/rpk/pkg/rpkutil/BUILD index f728f4656d924..42dd9777ea1f9 100644 --- a/src/go/rpk/pkg/utils/BUILD +++ b/src/go/rpk/pkg/rpkutil/BUILD @@ -30,3 +30,33 @@ go_test( "@com_github_stretchr_testify//require", ], ) + +go_library( + name = "rpkutil", + srcs = [ + "chained_error.go", + "collect.go", + "files.go", + "os.go", + "regex_filter.go", + ], + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil", + visibility = ["//visibility:public"], + deps = [ + "@com_github_spf13_afero//:afero", + "@org_uber_go_zap//:zap", + ], +) + +go_test( + name = "rpkutil_test", + srcs = [ + "files_test.go", + "regex_filter_test.go", + ], + embed = [":rpkutil"], + deps = [ + "@com_github_spf13_afero//:afero", + "@com_github_stretchr_testify//require", + ], +) diff --git a/src/go/rpk/pkg/utils/chained_error.go b/src/go/rpk/pkg/rpkutil/chained_error.go similarity index 97% rename from src/go/rpk/pkg/utils/chained_error.go rename to src/go/rpk/pkg/rpkutil/chained_error.go index 48afc3ea26173..e974b8e475dde 100644 --- a/src/go/rpk/pkg/utils/chained_error.go +++ b/src/go/rpk/pkg/rpkutil/chained_error.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil import "fmt" diff --git a/src/go/rpk/pkg/utils/collect.go b/src/go/rpk/pkg/rpkutil/collect.go similarity index 97% rename from src/go/rpk/pkg/utils/collect.go rename to src/go/rpk/pkg/rpkutil/collect.go index c686ebfa167f6..195c6fb01f1f6 100644 --- a/src/go/rpk/pkg/utils/collect.go +++ b/src/go/rpk/pkg/rpkutil/collect.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil func GetKeys(setMap map[string]bool) []string { var keys []string diff --git a/src/go/rpk/pkg/utils/files.go b/src/go/rpk/pkg/rpkutil/files.go similarity index 99% rename from src/go/rpk/pkg/utils/files.go rename to src/go/rpk/pkg/rpkutil/files.go index 41c987224b37c..3710bd2436eb2 100644 --- a/src/go/rpk/pkg/utils/files.go +++ b/src/go/rpk/pkg/rpkutil/files.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil import ( "bufio" diff --git a/src/go/rpk/pkg/utils/files_test.go b/src/go/rpk/pkg/rpkutil/files_test.go similarity index 87% rename from src/go/rpk/pkg/utils/files_test.go rename to src/go/rpk/pkg/rpkutil/files_test.go index 5d609bbe50160..881dc6297c978 100644 --- a/src/go/rpk/pkg/utils/files_test.go +++ b/src/go/rpk/pkg/rpkutil/files_test.go @@ -7,12 +7,12 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils_test +package rpkutil_test import ( "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -23,7 +23,7 @@ func TestWriteBytes(t *testing.T) { bs := []byte(content) filepath := "/tmp/testwritebytes.yaml" - n, err := utils.WriteBytes(fs, bs, filepath) + n, err := rpkutil.WriteBytes(fs, bs, filepath) require.Equal(t, len(bs), n, "the number of bytes read doesn't match the number of bytes written") require.NoError(t, err) buf := make([]byte, len(bs)) diff --git a/src/go/rpk/pkg/utils/os.go b/src/go/rpk/pkg/rpkutil/os.go similarity index 98% rename from src/go/rpk/pkg/utils/os.go rename to src/go/rpk/pkg/rpkutil/os.go index b958823e777cc..16d169c3303f4 100644 --- a/src/go/rpk/pkg/utils/os.go +++ b/src/go/rpk/pkg/rpkutil/os.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil import ( "context" diff --git a/src/go/rpk/pkg/utils/regex_filter.go b/src/go/rpk/pkg/rpkutil/regex_filter.go similarity index 99% rename from src/go/rpk/pkg/utils/regex_filter.go rename to src/go/rpk/pkg/rpkutil/regex_filter.go index f1e8d9c0c46de..79702ecbf967e 100644 --- a/src/go/rpk/pkg/utils/regex_filter.go +++ b/src/go/rpk/pkg/rpkutil/regex_filter.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil import ( "fmt" diff --git a/src/go/rpk/pkg/utils/regex_filter_test.go b/src/go/rpk/pkg/rpkutil/regex_filter_test.go similarity index 99% rename from src/go/rpk/pkg/utils/regex_filter_test.go rename to src/go/rpk/pkg/rpkutil/regex_filter_test.go index e053f4c4b2d76..59d3fc4a3ca77 100644 --- a/src/go/rpk/pkg/utils/regex_filter_test.go +++ b/src/go/rpk/pkg/rpkutil/regex_filter_test.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 -package utils +package rpkutil import ( "testing" diff --git a/src/go/rpk/pkg/schemaregistry/BUILD b/src/go/rpk/pkg/schemaregistry/BUILD index f7a31dd577143..8ea45518cb939 100644 --- a/src/go/rpk/pkg/schemaregistry/BUILD +++ b/src/go/rpk/pkg/schemaregistry/BUILD @@ -8,7 +8,7 @@ go_library( deps = [ "//src/go/rpk/pkg/adminapi", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", + "//src/go/rpk/pkg/netutil", "//src/go/rpk/pkg/oauth/authtoken", "//src/go/rpk/pkg/oauth/providers/auth0", "@com_github_redpanda_data_common_go_rpsr//:rpsr", diff --git a/src/go/rpk/pkg/schemaregistry/client.go b/src/go/rpk/pkg/schemaregistry/client.go index 3b534a1da70da..6c0af61c4e90f 100644 --- a/src/go/rpk/pkg/schemaregistry/client.go +++ b/src/go/rpk/pkg/schemaregistry/client.go @@ -8,7 +8,7 @@ import ( "github.com/redpanda-data/common-go/rpsr" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/authtoken" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0" "github.com/spf13/afero" @@ -27,7 +27,7 @@ func NewClient(fs afero.Fs, p *config.RpkProfile) (*rpsr.Client, error) { urls := p.SR.Addresses for i, u := range p.SR.Addresses { - scheme, _, err := net.ParseHostMaybeScheme(u) + scheme, _, err := netutil.ParseHostMaybeScheme(u) if err != nil { return nil, fmt.Errorf("unable to parse your schema registry address %q: %v", u, err) } diff --git a/src/go/rpk/pkg/system/BUILD b/src/go/rpk/pkg/system/BUILD index 9aabc4873db12..baaccc62f3106 100644 --- a/src/go/rpk/pkg/system/BUILD +++ b/src/go/rpk/pkg/system/BUILD @@ -22,8 +22,8 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system", visibility = ["//visibility:public"], deps = [ - "//src/go/rpk/pkg/os", - "//src/go/rpk/pkg/utils", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "@com_github_docker_go_units//:go-units", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", @@ -134,12 +134,12 @@ go_test( "@com_github_stretchr_testify//require", ] + select({ "@rules_go//go/platform:android": [ + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", - "//src/go/rpk/pkg/utils", ], "@rules_go//go/platform:linux": [ + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", - "//src/go/rpk/pkg/utils", ], "//conditions:default": [], }), diff --git a/src/go/rpk/pkg/system/cgroup.go b/src/go/rpk/pkg/system/cgroup.go index 820f39b79af43..75851631b1791 100644 --- a/src/go/rpk/pkg/system/cgroup.go +++ b/src/go/rpk/pkg/system/cgroup.go @@ -18,7 +18,7 @@ import ( "strconv" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" ) @@ -119,7 +119,7 @@ func readCgroupFile(fs afero.Fs, v1Subpath, v2Subpath string) (string, error) { if err != nil { return "", err } - ls, err := utils.ReadFileLines(fs, filePath) + ls, err := rpkutil.ReadFileLines(fs, filePath) if err != nil { return "", err } @@ -133,7 +133,7 @@ func readCgroupFile(fs afero.Fs, v1Subpath, v2Subpath string) (string, error) { } func v2CgroupPath(fs afero.Fs) (string, error) { - ls, err := utils.ReadFileLines(fs, "/proc/self/cgroup") + ls, err := rpkutil.ReadFileLines(fs, "/proc/self/cgroup") if err != nil { return "", err } diff --git a/src/go/rpk/pkg/system/grub.go b/src/go/rpk/pkg/system/grub.go index f15afb93438df..30edb17a95e5c 100644 --- a/src/go/rpk/pkg/system/grub.go +++ b/src/go/rpk/pkg/system/grub.go @@ -18,10 +18,10 @@ import ( "strings" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors/commands" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -37,8 +37,8 @@ type Grub interface { } func NewGrub( - commands os.Commands, - proc os.Proc, + commands osutil.Commands, + proc osutil.Proc, fs afero.Fs, executor executors.Executor, timeout time.Duration, @@ -53,8 +53,8 @@ func NewGrub( } type grub struct { - commands os.Commands - proc os.Proc + commands osutil.Commands + proc osutil.Proc fs afero.Fs executor executors.Executor timeout time.Duration @@ -79,11 +79,11 @@ func (g *grub) AddCommandLineOptions(opt []string) error { fmt.Println("GRUB options are up to date, doing nothing") return nil } - lines, err := utils.ReadFileLines(g.fs, grubCfg) + lines, err := rpkutil.ReadFileLines(g.fs, grubCfg) if err != nil { return err } - backupFile, err := utils.BackupFile(g.fs, grubCfg) + backupFile, err := rpkutil.BackupFile(g.fs, grubCfg) if err != nil { return err } @@ -113,7 +113,7 @@ func (g *grub) AddCommandLineOptions(opt []string) error { } func (g *grub) cmdLineCfgNeedChange(requestedOpts []string) (bool, error) { - lines, err := utils.ReadFileLines(g.fs, grubCfg) + lines, err := rpkutil.ReadFileLines(g.fs, grubCfg) if err != nil { return false, err } diff --git a/src/go/rpk/pkg/system/grub_test.go b/src/go/rpk/pkg/system/grub_test.go index 95504680e81f3..28a61b2783213 100644 --- a/src/go/rpk/pkg/system/grub_test.go +++ b/src/go/rpk/pkg/system/grub_test.go @@ -16,8 +16,8 @@ import ( "testing" "time" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -37,7 +37,7 @@ func TestGrubAddCommandLineOptions(t *testing.T) { opt: []string{"noht"}, check: func(fs afero.Fs, grubCfg []string) { backupName := "/etc/default/grub.vectorized.9be9f2dfe19f13b03e09fcc75648d4ec.bk" - backup, err := utils.ReadFileLines(fs, backupName) + backup, err := rpkutil.ReadFileLines(fs, backupName) require.NoError(t, err) require.Equal(t, grubCfg, backup) }, @@ -49,7 +49,7 @@ func TestGrubAddCommandLineOptions(t *testing.T) { opt: []string{"some_opt=2"}, check: func(fs afero.Fs, grubCfg []string) { backupName := "/etc/default/grub.vectorized.9be9f2dfe19f13b03e09fcc75648d4ec.bk" - backup, err := utils.ReadFileLines(fs, backupName) + backup, err := rpkutil.ReadFileLines(fs, backupName) require.NoError(t, err) require.Equal(t, grubCfg, backup) }, @@ -72,7 +72,7 @@ func TestGrubAddCommandLineOptions(t *testing.T) { opt: []string{"some_opt=2"}, check: func(fs afero.Fs, grubCfg []string) { backupName := "/etc/default/grub.vectorized.f88adb8d4d821d657e1d24d1d87a854e.bk" - backup, err := utils.ReadFileLines(fs, backupName) + backup, err := rpkutil.ReadFileLines(fs, backupName) require.NoError(t, err) require.Equal(t, grubCfg, backup) }, @@ -83,15 +83,15 @@ func TestGrubAddCommandLineOptions(t *testing.T) { fs := afero.NewMemMapFs() grub := NewGrub(nil, nil, fs, executors.NewDirectExecutor(), time.Duration(10)*time.Second) osfs := afero.NewOsFs() - grubCfg, err := utils.ReadFileLines(osfs, tt.grubInitFilename) + grubCfg, err := rpkutil.ReadFileLines(osfs, tt.grubInitFilename) require.NoError(t, err) - utils.WriteFileLines(fs, grubCfg, "/etc/default/grub") + rpkutil.WriteFileLines(fs, grubCfg, "/etc/default/grub") err = grub.AddCommandLineOptions(tt.opt) require.NoError(t, err) tt.check(fs, grubCfg) - grubGot, err := utils.ReadFileLines(fs, "/etc/default/grub") + grubGot, err := rpkutil.ReadFileLines(fs, "/etc/default/grub") require.NoError(t, err) - grubWant, err := utils.ReadFileLines(osfs, tt.grubWantFilename) + grubWant, err := rpkutil.ReadFileLines(osfs, tt.grubWantFilename) require.NoError(t, err) require.Equal(t, grubWant, grubGot) }) diff --git a/src/go/rpk/pkg/system/metrics.go b/src/go/rpk/pkg/system/metrics.go index 86429b17ab37a..7497a8a9a8264 100644 --- a/src/go/rpk/pkg/system/metrics.go +++ b/src/go/rpk/pkg/system/metrics.go @@ -22,7 +22,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/tklauser/go-sysconf" ) @@ -61,7 +61,7 @@ func GatherMetrics( errs = multierror.Append(errs, err) } - pidStr, err := utils.ReadEnsureSingleLine(fs, y.PIDFile()) + pidStr, err := rpkutil.ReadEnsureSingleLine(fs, y.PIDFile()) if err != nil { if os.IsNotExist(err) { return metrics, errRedpandaDown @@ -124,7 +124,7 @@ func redpandaCPUPercentage( func readStat(fs afero.Fs, pid int) (*stat, error) { statFilePath := fmt.Sprintf("/proc/%d/stat", pid) - line, err := utils.ReadEnsureSingleLine(fs, statFilePath) + line, err := rpkutil.ReadEnsureSingleLine(fs, statFilePath) if err != nil { return nil, err } diff --git a/src/go/rpk/pkg/system/ntp.go b/src/go/rpk/pkg/system/ntp.go index 828e75bca962e..d50d101091de4 100644 --- a/src/go/rpk/pkg/system/ntp.go +++ b/src/go/rpk/pkg/system/ntp.go @@ -15,7 +15,7 @@ import ( "regexp" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -28,14 +28,14 @@ func NewNtpQuery(timeout time.Duration, fs afero.Fs) NtpQuery { return &ntpQuery{ timeout: timeout, fs: fs, - proc: os.NewProc(), + proc: osutil.NewProc(), } } type ntpQuery struct { timeout time.Duration fs afero.Fs - proc os.Proc + proc osutil.Proc } func (q *ntpQuery) IsNtpSynced() (bool, error) { diff --git a/src/go/rpk/pkg/system/runtime_options.go b/src/go/rpk/pkg/system/runtime_options.go index abbb81ae59655..635c449648872 100644 --- a/src/go/rpk/pkg/system/runtime_options.go +++ b/src/go/rpk/pkg/system/runtime_options.go @@ -14,7 +14,7 @@ import ( "regexp" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" ) @@ -24,7 +24,7 @@ type RuntimeOptions struct { func ReadRuntineOptions(fs afero.Fs, path string) (*RuntimeOptions, error) { optionsMap := make(map[string]bool) - lines, err := utils.ReadFileLines(fs, path) + lines, err := rpkutil.ReadFileLines(fs, path) if err != nil { return nil, err } @@ -60,5 +60,5 @@ func (r *RuntimeOptions) GetActive() string { } func (r *RuntimeOptions) GetAvailable() []string { - return utils.GetKeys(r.optionsMap) + return rpkutil.GetKeys(r.optionsMap) } diff --git a/src/go/rpk/pkg/system/systemd/BUILD b/src/go/rpk/pkg/system/systemd/BUILD index b8330d9667a76..350a3586450a2 100644 --- a/src/go/rpk/pkg/system/systemd/BUILD +++ b/src/go/rpk/pkg/system/systemd/BUILD @@ -10,7 +10,7 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system/systemd", visibility = ["//visibility:public"], deps = [ - "//src/go/rpk/pkg/utils", + "//src/go/rpk/pkg/rpkutil", "@com_github_coreos_go_systemd_v22//dbus", "@com_github_spf13_afero//:afero", ], diff --git a/src/go/rpk/pkg/system/systemd/dbus.go b/src/go/rpk/pkg/system/systemd/dbus.go index 533788ca3a178..c8f795049619b 100644 --- a/src/go/rpk/pkg/system/systemd/dbus.go +++ b/src/go/rpk/pkg/system/systemd/dbus.go @@ -13,7 +13,7 @@ import ( "context" "github.com/coreos/go-systemd/v22/dbus" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" ) @@ -57,7 +57,7 @@ func (c *dbusClient) UnitState(name string) (LoadState, ActiveState, error) { } func (c *dbusClient) LoadUnit(fs afero.Fs, body, name string) error { - _, err := utils.WriteBytes(fs, []byte(body), UnitPath(name)) + _, err := rpkutil.WriteBytes(fs, []byte(body), UnitPath(name)) if err != nil { return err } diff --git a/src/go/rpk/pkg/system/utils.go b/src/go/rpk/pkg/system/utils.go index 1e69411dabf5c..56d507fb2b749 100644 --- a/src/go/rpk/pkg/system/utils.go +++ b/src/go/rpk/pkg/system/utils.go @@ -13,7 +13,7 @@ import ( "fmt" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "go.uber.org/zap" ) @@ -23,7 +23,7 @@ func UnameAndDistro(timeout time.Duration) (string, error) { return "", err } cmd := "lsb_release" - p := os.NewProc() + p := osutil.NewProc() ls, err := p.RunWithSystemLdPath(timeout, cmd, "-d", "-s") if err != nil { zap.L().Sugar().Debugf("%s failed", cmd) diff --git a/src/go/rpk/pkg/tuners/BUILD b/src/go/rpk/pkg/tuners/BUILD index 454da64671964..a4ab9734e3e90 100644 --- a/src/go/rpk/pkg/tuners/BUILD +++ b/src/go/rpk/pkg/tuners/BUILD @@ -39,10 +39,11 @@ go_library( "//src/go/rpk/pkg/cloud/gcp", "//src/go/rpk/pkg/cloud/provider", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/system/filesystem", "//src/go/rpk/pkg/system/systemd", @@ -54,7 +55,6 @@ go_library( "//src/go/rpk/pkg/tuners/iotune", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_hashicorp_go_multierror//:go-multierror", "@com_github_lorenzosaino_go_sysctl//:go-sysctl", "@com_github_pkg_errors//:errors", @@ -67,10 +67,11 @@ go_library( "//src/go/rpk/pkg/cloud/gcp", "//src/go/rpk/pkg/cloud/provider", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/out", "//src/go/rpk/pkg/redpanda", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/system/filesystem", "//src/go/rpk/pkg/system/systemd", @@ -82,7 +83,6 @@ go_library( "//src/go/rpk/pkg/tuners/iotune", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_hashicorp_go_multierror//:go-multierror", "@com_github_lorenzosaino_go_sysctl//:go-sysctl", "@com_github_pkg_errors//:errors", @@ -121,7 +121,8 @@ go_test( "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/cloud/provider", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system/systemd", "//src/go/rpk/pkg/tuners/disk", "//src/go/rpk/pkg/tuners/ethtool", @@ -129,7 +130,6 @@ go_test( "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", @@ -138,7 +138,8 @@ go_test( "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/cloud/provider", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system/systemd", "//src/go/rpk/pkg/tuners/disk", "//src/go/rpk/pkg/tuners/ethtool", @@ -146,7 +147,6 @@ go_test( "//src/go/rpk/pkg/tuners/hwloc", "//src/go/rpk/pkg/tuners/irq", "//src/go/rpk/pkg/tuners/network", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", diff --git a/src/go/rpk/pkg/tuners/aio.go b/src/go/rpk/pkg/tuners/aio.go index a8ce29432086d..39ea907b33bd7 100644 --- a/src/go/rpk/pkg/tuners/aio.go +++ b/src/go/rpk/pkg/tuners/aio.go @@ -14,9 +14,9 @@ package tuners import ( "fmt" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors/commands" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -38,7 +38,7 @@ func NewMaxAIOEventsChecker(fs afero.Fs) Checker { return fmt.Sprintf(">= %d", maxAIOEvents) }, func() (int, error) { - return utils.ReadIntFromFile(fs, maxAIOEventsFile) + return rpkutil.ReadIntFromFile(fs, maxAIOEventsFile) }, ) } diff --git a/src/go/rpk/pkg/tuners/aio_test.go b/src/go/rpk/pkg/tuners/aio_test.go index 6387545764b0b..33262ccd44d46 100644 --- a/src/go/rpk/pkg/tuners/aio_test.go +++ b/src/go/rpk/pkg/tuners/aio_test.go @@ -15,9 +15,9 @@ import ( "fmt" "testing" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -43,7 +43,7 @@ func TestMaxAIOEventsCheck(t *testing.T) { { name: "it shouldn't do anything if current >= reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("20000000"), maxAIOEventsFile, @@ -54,7 +54,7 @@ func TestMaxAIOEventsCheck(t *testing.T) { { name: "it shouldn't do anything if current == reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("10000137"), maxAIOEventsFile, @@ -65,7 +65,7 @@ func TestMaxAIOEventsCheck(t *testing.T) { { name: "it should set the value if current < reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("10000136"), maxAIOEventsFile, diff --git a/src/go/rpk/pkg/tuners/cpu/BUILD b/src/go/rpk/pkg/tuners/cpu/BUILD index 589c5d1e5de61..a04e0a0b32000 100644 --- a/src/go/rpk/pkg/tuners/cpu/BUILD +++ b/src/go/rpk/pkg/tuners/cpu/BUILD @@ -7,22 +7,22 @@ go_library( visibility = ["//visibility:public"], deps = select({ "@rules_go//go/platform:android": [ + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/executors", "//src/go/rpk/pkg/tuners/executors/commands", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/executors", "//src/go/rpk/pkg/tuners/executors/commands", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", ], diff --git a/src/go/rpk/pkg/tuners/cpu/tuner.go b/src/go/rpk/pkg/tuners/cpu/tuner.go index a48d206c166b7..27ce36b224690 100644 --- a/src/go/rpk/pkg/tuners/cpu/tuner.go +++ b/src/go/rpk/pkg/tuners/cpu/tuner.go @@ -15,12 +15,12 @@ import ( "fmt" "strconv" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors/commands" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -121,7 +121,7 @@ func (tuner *tuner) getMaxCState() (uint, error) { zap.L().Sugar().Debugf("Getting max allowed CState") // Possible errors while reading max_cstate: // File doesn't exist or reading error. - lines, err := utils.ReadFileLines(tuner.fs, + lines, err := rpkutil.ReadFileLines(tuner.fs, "/sys/module/intel_idle/parameters/max_cstate") // We return maxCstate = 0 when any of the above errors occurred. if err != nil { @@ -149,7 +149,7 @@ func (tuner *tuner) disableCStates() error { func (tuner *tuner) checkIfPStateIsEnabled() (bool, error) { zap.L().Sugar().Debugf("Checking if Intel P-States are enabled") - lines, err := utils.ReadFileLines(tuner.fs, + lines, err := rpkutil.ReadFileLines(tuner.fs, "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver") if err != nil { return false, err diff --git a/src/go/rpk/pkg/tuners/disk/BUILD b/src/go/rpk/pkg/tuners/disk/BUILD index 65391f18bc16f..844af52054f7d 100644 --- a/src/go/rpk/pkg/tuners/disk/BUILD +++ b/src/go/rpk/pkg/tuners/disk/BUILD @@ -13,19 +13,19 @@ go_library( visibility = ["//visibility:public"], deps = select({ "@rules_go//go/platform:android": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_golang_x_sys//unix", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_golang_x_sys//unix", "@org_uber_go_zap//:zap", @@ -45,16 +45,16 @@ go_test( embed = [":disk"], deps = select({ "@rules_go//go/platform:android": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", ], "@rules_go//go/platform:linux": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", ], diff --git a/src/go/rpk/pkg/tuners/disk/block_device.go b/src/go/rpk/pkg/tuners/disk/block_device.go index 79e021adba43c..946d0993d86d4 100644 --- a/src/go/rpk/pkg/tuners/disk/block_device.go +++ b/src/go/rpk/pkg/tuners/disk/block_device.go @@ -16,7 +16,7 @@ import ( "path/filepath" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -47,7 +47,7 @@ func (d *blockDevice) Parent() BlockDevice { func deviceFromSystemPath(syspath string, fs afero.Fs) (BlockDevice, error) { zap.L().Sugar().Debugf("Reading block device details from '%s'", syspath) - lines, err := utils.ReadFileLines(fs, filepath.Join(syspath, "uevent")) + lines, err := rpkutil.ReadFileLines(fs, filepath.Join(syspath, "uevent")) if err != nil { return nil, err } diff --git a/src/go/rpk/pkg/tuners/disk/block_device_test.go b/src/go/rpk/pkg/tuners/disk/block_device_test.go index e324400f370c1..0d4940d461aea 100644 --- a/src/go/rpk/pkg/tuners/disk/block_device_test.go +++ b/src/go/rpk/pkg/tuners/disk/block_device_test.go @@ -15,7 +15,7 @@ import ( "path/filepath" "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -33,7 +33,7 @@ func Test_deviceFromSystemPath(t *testing.T) { before: func(fs afero.Fs, syspath string) { ueventFileLines := []string{"DEVNAME=node-name"} fs.MkdirAll(syspath, 0o755) - utils.WriteFileLines(fs, ueventFileLines, + rpkutil.WriteFileLines(fs, ueventFileLines, filepath.Join(syspath, "uevent")) }, want: &blockDevice{ @@ -48,11 +48,11 @@ func Test_deviceFromSystemPath(t *testing.T) { before: func(fs afero.Fs, syspath string) { ueventFileLines := []string{"DEVNAME=child"} fs.MkdirAll(syspath, 0o755) - utils.WriteFileLines(fs, ueventFileLines, + rpkutil.WriteFileLines(fs, ueventFileLines, filepath.Join(syspath, "uevent")) parentPath := "/sys/devices/pci0000:00/0000:00:1d.0/nvme/nvme0" parentUeventFileLines := []string{"DEVNAME=parent"} - utils.WriteFileLines(fs, parentUeventFileLines, + rpkutil.WriteFileLines(fs, parentUeventFileLines, filepath.Join(parentPath, "uevent")) }, want: &blockDevice{ diff --git a/src/go/rpk/pkg/tuners/disk/block_devices.go b/src/go/rpk/pkg/tuners/disk/block_devices.go index d40ca61ec71e2..4c80de15dcf96 100644 --- a/src/go/rpk/pkg/tuners/disk/block_devices.go +++ b/src/go/rpk/pkg/tuners/disk/block_devices.go @@ -21,9 +21,9 @@ import ( "syscall" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -48,7 +48,7 @@ type BlockDevices interface { } type blockDevices struct { - proc os.Proc + proc osutil.Proc fs afero.Fs irqDeviceInfo irq.DeviceInfo irqProcFile irq.ProcFile @@ -59,7 +59,7 @@ func NewBlockDevices( fs afero.Fs, irqDeviceInfo irq.DeviceInfo, irqProcFile irq.ProcFile, - proc os.Proc, + proc osutil.Proc, timeout time.Duration, ) BlockDevices { return &blockDevices{ @@ -253,7 +253,7 @@ func (b *blockDevices) GetDiskInfoByType( } } - if utils.IsAWSi3MetalInstance() { + if rpkutil.IsAWSi3MetalInstance() { for IRQ := range nvmeIRQs { isNvmFastPath, err := b.isIRQNvmeFastPathIRQ(IRQ, runtime.NumCPU()) if err != nil { @@ -265,12 +265,12 @@ func (b *blockDevices) GetDiskInfoByType( } } diskInfoByType[Nvme] = DevicesIRQs{ - utils.GetKeys(nvmeDisks), - utils.GetIntKeys(nvmeIRQs), + rpkutil.GetKeys(nvmeDisks), + rpkutil.GetIntKeys(nvmeIRQs), } diskInfoByType[NonNvme] = DevicesIRQs{ - utils.GetKeys(nonNvmeDisks), - utils.GetIntKeys(nonNvmeIRQs), + rpkutil.GetKeys(nonNvmeDisks), + rpkutil.GetIntKeys(nonNvmeIRQs), } return diskInfoByType, nil } diff --git a/src/go/rpk/pkg/tuners/disk/block_devices_test.go b/src/go/rpk/pkg/tuners/disk/block_devices_test.go index 7399b7522dfcb..1fd6718331d7a 100644 --- a/src/go/rpk/pkg/tuners/disk/block_devices_test.go +++ b/src/go/rpk/pkg/tuners/disk/block_devices_test.go @@ -15,7 +15,7 @@ import ( "strings" "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" "github.com/spf13/afero" "github.com/stretchr/testify/require" @@ -35,7 +35,7 @@ func (m *irqProcFileMock) GetIRQProcFileLinesMap() (map[int]string, error) { } type procMock struct { - os.Proc + osutil.Proc } func Test_blockDevices_getDeviceControllerPath(t *testing.T) { diff --git a/src/go/rpk/pkg/tuners/disk_tuner.go b/src/go/rpk/pkg/tuners/disk_tuner.go index 3911703acf94f..976fcd0894607 100644 --- a/src/go/rpk/pkg/tuners/disk_tuner.go +++ b/src/go/rpk/pkg/tuners/disk_tuner.go @@ -12,8 +12,8 @@ package tuners import ( + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/disk" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -77,7 +77,7 @@ func (tuner *diskTuner) createDeviceTuners() ([]Tunable, error) { for _, device := range tuner.devices { disksSetMap[device] = true } - devices := utils.GetKeys(disksSetMap) + devices := rpkutil.GetKeys(disksSetMap) var tuners []Tunable for _, device := range devices { zap.L().Sugar().Debugf("Creating disk tuner for '%s'", device) diff --git a/src/go/rpk/pkg/tuners/executors/commands/BUILD b/src/go/rpk/pkg/tuners/executors/commands/BUILD index c2364e3598ae4..25bacd31d179d 100644 --- a/src/go/rpk/pkg/tuners/executors/commands/BUILD +++ b/src/go/rpk/pkg/tuners/executors/commands/BUILD @@ -19,10 +19,10 @@ go_library( visibility = ["//visibility:public"], deps = select({ "@rules_go//go/platform:android": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system/systemd", "//src/go/rpk/pkg/tuners/ethtool", - "//src/go/rpk/pkg/utils", "@com_github_lorenzosaino_go_sysctl//:go-sysctl", "@com_github_safchain_ethtool//:ethtool", "@com_github_spf13_afero//:afero", @@ -30,10 +30,10 @@ go_library( "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/system/systemd", "//src/go/rpk/pkg/tuners/ethtool", - "//src/go/rpk/pkg/utils", "@com_github_lorenzosaino_go_sysctl//:go-sysctl", "@com_github_safchain_ethtool//:ethtool", "@com_github_spf13_afero//:afero", diff --git a/src/go/rpk/pkg/tuners/executors/commands/backup_file.go b/src/go/rpk/pkg/tuners/executors/commands/backup_file.go index 23915fea10a00..badcd9bfc4824 100644 --- a/src/go/rpk/pkg/tuners/executors/commands/backup_file.go +++ b/src/go/rpk/pkg/tuners/executors/commands/backup_file.go @@ -15,7 +15,7 @@ import ( "bufio" "fmt" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -35,7 +35,7 @@ func NewBackupFileCmd(fs afero.Fs, path string) Command { func (c *backupFileCommand) Execute() error { zap.L().Sugar().Debugf("Creating backup of '%s'", c.path) - bckFile, err := utils.BackupFile(c.fs, c.path) + bckFile, err := rpkutil.BackupFile(c.fs, c.path) if err == nil { zap.L().Sugar().Debugf("Backup created '%s'", bckFile) } diff --git a/src/go/rpk/pkg/tuners/executors/commands/execute.go b/src/go/rpk/pkg/tuners/executors/commands/execute.go index 2936fa9ef80f0..a6cb6a65e3c23 100644 --- a/src/go/rpk/pkg/tuners/executors/commands/execute.go +++ b/src/go/rpk/pkg/tuners/executors/commands/execute.go @@ -16,19 +16,19 @@ import ( "fmt" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" ) type executeCommand struct { Command cmd string args []string - proc os.Proc + proc osutil.Proc timeout time.Duration } func NewLaunchCmd( - proc os.Proc, timeout time.Duration, cmd string, args ...string, + proc osutil.Proc, timeout time.Duration, cmd string, args ...string, ) Command { return &executeCommand{ cmd: cmd, diff --git a/src/go/rpk/pkg/tuners/executors/commands/write_file_lines.go b/src/go/rpk/pkg/tuners/executors/commands/write_file_lines.go index d93f92361eb48..a99be3af5b7d8 100644 --- a/src/go/rpk/pkg/tuners/executors/commands/write_file_lines.go +++ b/src/go/rpk/pkg/tuners/executors/commands/write_file_lines.go @@ -15,7 +15,7 @@ import ( "bufio" "fmt" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -37,7 +37,7 @@ func NewWriteFileLinesCmd(fs afero.Fs, path string, lines []string) Command { func (c *writeFileLinesCommand) Execute() error { zap.L().Sugar().Debugf("Writing '%v' to file '%s'", c.lines, c.path) - return utils.WriteFileLines(c.fs, c.lines, c.path) + return rpkutil.WriteFileLines(c.fs, c.lines, c.path) } func (c *writeFileLinesCommand) RenderScript(w *bufio.Writer) error { diff --git a/src/go/rpk/pkg/tuners/factory/BUILD b/src/go/rpk/pkg/tuners/factory/BUILD index 8beccc1505138..8fd268642995e 100644 --- a/src/go/rpk/pkg/tuners/factory/BUILD +++ b/src/go/rpk/pkg/tuners/factory/BUILD @@ -9,8 +9,8 @@ go_library( "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/cloud/gcp", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/ballast", @@ -27,8 +27,8 @@ go_library( "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/cloud/gcp", "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/net", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/netutil", + "//src/go/rpk/pkg/osutil", "//src/go/rpk/pkg/system", "//src/go/rpk/pkg/tuners", "//src/go/rpk/pkg/tuners/ballast", diff --git a/src/go/rpk/pkg/tuners/factory/factory.go b/src/go/rpk/pkg/tuners/factory/factory.go index 5e830ded9ec7f..1fb25d8c46e81 100644 --- a/src/go/rpk/pkg/tuners/factory/factory.go +++ b/src/go/rpk/pkg/tuners/factory/factory.go @@ -19,8 +19,8 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cloud/gcp" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/ballast" @@ -74,14 +74,14 @@ type tunersFactory struct { irqBalanceService irq.BalanceService irqProcFile irq.ProcFile blockDevices disk.BlockDevices - proc os.Proc + proc osutil.Proc grub system.Grub executor executors.Executor } func NewDirectExecutorTunersFactory(fs afero.Fs, rnc config.RpkNodeConfig, timeout time.Duration) TunersFactory { irqProcFile := irq.NewProcFile(fs) - proc := os.NewProc() + proc := osutil.NewProc() irqDeviceInfo := irq.NewDeviceInfo(fs, irqProcFile) executor := executors.NewDirectExecutor() return newTunersFactory(fs, rnc, irqProcFile, proc, irqDeviceInfo, executor, timeout) @@ -89,7 +89,7 @@ func NewDirectExecutorTunersFactory(fs afero.Fs, rnc config.RpkNodeConfig, timeo func NewScriptRenderingTunersFactory(fs afero.Fs, rnc config.RpkNodeConfig, out string, timeout time.Duration) TunersFactory { irqProcFile := irq.NewProcFile(fs) - proc := os.NewProc() + proc := osutil.NewProc() irqDeviceInfo := irq.NewDeviceInfo(fs, irqProcFile) executor := executors.NewScriptRenderingExecutor(fs, out) return newTunersFactory(fs, rnc, irqProcFile, proc, irqDeviceInfo, executor, timeout) @@ -99,7 +99,7 @@ func newTunersFactory( fs afero.Fs, rnc config.RpkNodeConfig, irqProcFile irq.ProcFile, - proc os.Proc, + proc osutil.Proc, irqDeviceInfo irq.DeviceInfo, executor executors.Executor, timeout time.Duration, @@ -112,7 +112,7 @@ func newTunersFactory( cpuMasks: irq.NewCPUMasks(fs, hwloc.NewHwLocCmd(proc, timeout), executor), irqBalanceService: irq.NewBalanceService(fs, proc, executor, timeout), blockDevices: disk.NewBlockDevices(fs, irqDeviceInfo, irqProcFile, proc, timeout), - grub: system.NewGrub(os.NewCommands(proc), proc, fs, executor, timeout), + grub: system.NewGrub(osutil.NewCommands(proc), proc, fs, executor, timeout), proc: proc, executor: executor, } @@ -301,7 +301,7 @@ func MergeTunerParamsConfig(params *TunerParams, y *config.RedpandaYaml) (*Tuner for _, address := range y.Redpanda.KafkaAPI { addrs = append(addrs, address.Address) } - nics, err := net.GetInterfacesByIps( + nics, err := netutil.GetInterfacesByIps( addrs..., ) if err != nil { @@ -320,7 +320,7 @@ func FillTunerParamsWithValuesFromConfig(params *TunerParams, y *config.Redpanda for _, address := range y.Redpanda.KafkaAPI { addrs = append(addrs, address.Address) } - nics, err := net.GetInterfacesByIps( + nics, err := netutil.GetInterfacesByIps( addrs..., ) if err != nil { diff --git a/src/go/rpk/pkg/tuners/fstrim.go b/src/go/rpk/pkg/tuners/fstrim.go index 95271aafc8ca2..3541394c05f1b 100644 --- a/src/go/rpk/pkg/tuners/fstrim.go +++ b/src/go/rpk/pkg/tuners/fstrim.go @@ -15,7 +15,7 @@ import ( "time" "github.com/pkg/errors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system/systemd" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors/commands" @@ -63,7 +63,7 @@ func (*fstrimTuner) CheckIfSupported() (bool, string) { } defer c.Shutdown() - _, err = whichFstrim(os.NewProc(), timeout) + _, err = whichFstrim(osutil.NewProc(), timeout) if err != nil { return false, err.Error() } @@ -76,11 +76,11 @@ func (t *fstrimTuner) Tune() TuneResult { return NewTuneError(err) } defer c.Shutdown() - return tuneFstrim(t.fs, t.executor, c, os.NewProc()) + return tuneFstrim(t.fs, t.executor, c, osutil.NewProc()) } func tuneFstrim( - fs afero.Fs, exe executors.Executor, c systemd.Client, proc os.Proc, + fs afero.Fs, exe executors.Executor, c systemd.Client, proc osutil.Proc, ) TuneResult { // Check if the default timer (fstrim.timer) is available. defaultAvailable, err := startIfAvailable(exe, c, timerName) @@ -200,8 +200,8 @@ func startSystemdUnit( return executor.Execute(cmd) } -func whichFstrim(proc os.Proc, timeout time.Duration) (string, error) { - cmd := os.NewCommands(proc) +func whichFstrim(proc osutil.Proc, timeout time.Duration) (string, error) { + cmd := osutil.NewCommands(proc) return cmd.Which(fstrim, timeout) } diff --git a/src/go/rpk/pkg/tuners/fstrim_test.go b/src/go/rpk/pkg/tuners/fstrim_test.go index 1c4ef39d723c1..653a94406581a 100644 --- a/src/go/rpk/pkg/tuners/fstrim_test.go +++ b/src/go/rpk/pkg/tuners/fstrim_test.go @@ -17,10 +17,10 @@ import ( "testing" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system/systemd" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -72,7 +72,7 @@ func TestTuneFstrimDirectExecutorRollback(t *testing.T) { if name == "redpanda-fstrim.timer" { return errors.New(errMsg) } - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte(body), systemd.UnitPath(name), @@ -95,7 +95,7 @@ func TestTuneFstrimScriptExecutor(t *testing.T) { startUnit func(string) error unitState func(string) (systemd.LoadState, systemd.ActiveState, error) loadUnit func(afero.Fs, string, string) error - proc os.Proc + proc osutil.Proc expected string expectedErrMsg string }{ @@ -260,7 +260,7 @@ sudo systemctl start redpanda-fstrim.timer unitState, loadUnit, ) - var proc os.Proc = &mockProc{} + var proc osutil.Proc = &mockProc{} if tt.proc != nil { proc = tt.proc } diff --git a/src/go/rpk/pkg/tuners/hwloc/BUILD b/src/go/rpk/pkg/tuners/hwloc/BUILD index 758f3e74565af..03d4f93bd7f30 100644 --- a/src/go/rpk/pkg/tuners/hwloc/BUILD +++ b/src/go/rpk/pkg/tuners/hwloc/BUILD @@ -11,11 +11,11 @@ go_library( visibility = ["//visibility:public"], deps = select({ "@rules_go//go/platform:android": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "@org_uber_go_zap//:zap", ], "//conditions:default": [], diff --git a/src/go/rpk/pkg/tuners/hwloc/hwloc_cmd.go b/src/go/rpk/pkg/tuners/hwloc/hwloc_cmd.go index 8161d9b14862c..db60df2cf8c3f 100644 --- a/src/go/rpk/pkg/tuners/hwloc/hwloc_cmd.go +++ b/src/go/rpk/pkg/tuners/hwloc/hwloc_cmd.go @@ -17,7 +17,7 @@ import ( "strings" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "go.uber.org/zap" ) @@ -28,11 +28,11 @@ const ( type hwLocCmd struct { HwLoc - proc os.Proc + proc osutil.Proc timeout time.Duration } -func NewHwLocCmd(proc os.Proc, timeout time.Duration) HwLoc { +func NewHwLocCmd(proc osutil.Proc, timeout time.Duration) HwLoc { return &hwLocCmd{ proc: proc, timeout: timeout, diff --git a/src/go/rpk/pkg/tuners/iotune.go b/src/go/rpk/pkg/tuners/iotune.go index 1a11527472130..b0a800f6373ef 100644 --- a/src/go/rpk/pkg/tuners/iotune.go +++ b/src/go/rpk/pkg/tuners/iotune.go @@ -15,7 +15,7 @@ import ( "fmt" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/iotune" "github.com/spf13/afero" "go.uber.org/zap" @@ -63,7 +63,7 @@ func (tuner *ioTuner) CheckIfSupported() (bool, string) { } func (tuner *ioTuner) Tune() TuneResult { - ioTune := iotune.NewIoTune(os.NewProc(), tuner.getIotunePath(), tuner.timeout) + ioTune := iotune.NewIoTune(osutil.NewProc(), tuner.getIotunePath(), tuner.timeout) args := iotune.IoTuneArgs{ Dirs: tuner.evalDirectories, Format: iotune.Seastar, diff --git a/src/go/rpk/pkg/tuners/iotune/BUILD b/src/go/rpk/pkg/tuners/iotune/BUILD index c6a2e29d209fd..6f908ca052c93 100644 --- a/src/go/rpk/pkg/tuners/iotune/BUILD +++ b/src/go/rpk/pkg/tuners/iotune/BUILD @@ -11,12 +11,12 @@ go_library( deps = select({ "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/cloud/provider", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/cloud/provider", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", "@org_uber_go_zap//:zap", ], "//conditions:default": [], diff --git a/src/go/rpk/pkg/tuners/iotune/io_tune.go b/src/go/rpk/pkg/tuners/iotune/io_tune.go index 64e4f2f547bbd..2b2e7538747a5 100644 --- a/src/go/rpk/pkg/tuners/iotune/io_tune.go +++ b/src/go/rpk/pkg/tuners/iotune/io_tune.go @@ -16,7 +16,7 @@ import ( "strconv" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "go.uber.org/zap" ) @@ -41,7 +41,7 @@ type IoTune interface { Run(IoTuneArgs) ([]string, error) } -func NewIoTune(proc os.Proc, iotunePath string, timeout time.Duration) IoTune { +func NewIoTune(proc osutil.Proc, iotunePath string, timeout time.Duration) IoTune { return &ioTune{ proc: proc, path: iotunePath, @@ -51,7 +51,7 @@ func NewIoTune(proc os.Proc, iotunePath string, timeout time.Duration) IoTune { type ioTune struct { IoTune - proc os.Proc + proc osutil.Proc path string timeout time.Duration } diff --git a/src/go/rpk/pkg/tuners/irq/BUILD b/src/go/rpk/pkg/tuners/irq/BUILD index 7992c9b8321cf..f1c3332869a2e 100644 --- a/src/go/rpk/pkg/tuners/irq/BUILD +++ b/src/go/rpk/pkg/tuners/irq/BUILD @@ -15,21 +15,21 @@ go_library( deps = select({ "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", "//src/go/rpk/pkg/tuners/executors/commands", "//src/go/rpk/pkg/tuners/hwloc", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/config", - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", "//src/go/rpk/pkg/tuners/executors/commands", "//src/go/rpk/pkg/tuners/hwloc", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", ], @@ -50,16 +50,16 @@ go_test( embed = [":irq"], deps = select({ "@rules_go//go/platform:android": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", ], "@rules_go//go/platform:linux": [ - "//src/go/rpk/pkg/os", + "//src/go/rpk/pkg/osutil", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/executors", - "//src/go/rpk/pkg/utils", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", ], diff --git a/src/go/rpk/pkg/tuners/irq/balance_service.go b/src/go/rpk/pkg/tuners/irq/balance_service.go index 04c75d9ae8ef5..9b487c0eca3c4 100644 --- a/src/go/rpk/pkg/tuners/irq/balance_service.go +++ b/src/go/rpk/pkg/tuners/irq/balance_service.go @@ -19,10 +19,10 @@ import ( "strings" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors/commands" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -40,7 +40,7 @@ type BalanceService interface { } func NewBalanceService( - fs afero.Fs, proc os.Proc, executor executors.Executor, timeout time.Duration, + fs afero.Fs, proc osutil.Proc, executor executors.Executor, timeout time.Duration, ) BalanceService { return &balanceService{ fs: fs, @@ -52,7 +52,7 @@ func NewBalanceService( type balanceService struct { fs afero.Fs - proc os.Proc + proc osutil.Proc executor executors.Executor timeout time.Duration } @@ -80,7 +80,7 @@ func (balanceService *balanceService) BanIRQsAndRestart( return err } - configLines, err := utils.ReadFileLines(balanceService.fs, serviceInfo.configFile) + configLines, err := rpkutil.ReadFileLines(balanceService.fs, serviceInfo.configFile) if err != nil { return err } @@ -153,7 +153,7 @@ func (balanceService *balanceService) GetBannedIRQs() ([]int, error) { if err != nil { return nil, err } - configLines, err := utils.ReadFileLines(balanceService.fs, serviceInfo.configFile) + configLines, err := rpkutil.ReadFileLines(balanceService.fs, serviceInfo.configFile) if err != nil { return nil, err } @@ -222,7 +222,7 @@ func (balanceService *balanceService) getBalanceServiceInfo() ( } else { configFile = "/etc/conf.d/irqbalance" optionsKey = "IRQBALANCE_OPTS" - lines, err := utils.ReadFileLines(fs, "/proc/1/comm") + lines, err := rpkutil.ReadFileLines(fs, "/proc/1/comm") if err != nil { return nil, err } diff --git a/src/go/rpk/pkg/tuners/irq/balance_service_test.go b/src/go/rpk/pkg/tuners/irq/balance_service_test.go index 5a7526d6a7eb1..767dbe145f582 100644 --- a/src/go/rpk/pkg/tuners/irq/balance_service_test.go +++ b/src/go/rpk/pkg/tuners/irq/balance_service_test.go @@ -16,15 +16,15 @@ import ( "testing" "time" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) type procMock struct { - os.Proc + osutil.Proc run func(command string, args ...string) ([]string, error) isRunning func(processName string) bool } @@ -63,7 +63,7 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { } tests := []struct { name string - proc os.Proc + proc osutil.Proc bannedIRQs []int testadataInitFilename string configFilename string @@ -91,7 +91,7 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 2, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_ARGS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -116,7 +116,7 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 3, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_ARGS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -141,7 +141,7 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 3, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_ARGS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -163,12 +163,12 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { configFilename: "/etc/conf.d/irqbalance", backupFilename: "/etc/conf.d/irqbalance.vectorized.911727b5a516f8e315b36f97e54facda.bk", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, []string{"systemd"}, "/proc/1/comm") + _ = rpkutil.WriteFileLines(fs, []string{"systemd"}, "/proc/1/comm") }, assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 2, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_OPTS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -190,12 +190,12 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { configFilename: "/etc/default/irqbalance", backupFilename: "/etc/default/irqbalance.vectorized.911727b5a516f8e315b36f97e54facda.bk", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, []string{""}, "/lib/systemd/system/irqbalance.service") + _ = rpkutil.WriteFileLines(fs, []string{""}, "/lib/systemd/system/irqbalance.service") }, assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 2, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_ARGS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -217,12 +217,12 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { configFilename: "/etc/conf.d/irqbalance", backupFilename: "/etc/conf.d/irqbalance.vectorized.911727b5a516f8e315b36f97e54facda.bk", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, []string{"init"}, "/proc/1/comm") + _ = rpkutil.WriteFileLines(fs, []string{"init"}, "/proc/1/comm") }, assert: func(fs afero.Fs, configFilename string, backupContent []string) { require.Equal(t, 2, len(backupContent)) // Check if IRQs were banned in the file - fileContent, err := utils.ReadFileLines(fs, configFilename) + fileContent, err := rpkutil.ReadFileLines(fs, configFilename) require.NoError(t, err) require.Equal(t, 3, len(fileContent)) require.Equal(t, "IRQBALANCE_OPTS=\" --banirq=5 --banirq=12 --banirq=15\"", fileContent[2]) @@ -234,9 +234,9 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { t.Run(fmt.Sprintf("test %02d %s", i, tt.name), func(t *testing.T) { fs := afero.NewMemMapFs() osfs := afero.NewOsFs() - testdataLines, err := utils.ReadFileLines(osfs, tt.testadataInitFilename) + testdataLines, err := rpkutil.ReadFileLines(osfs, tt.testadataInitFilename) require.NoError(t, err) - err = utils.WriteFileLines(fs, testdataLines, tt.configFilename) + err = rpkutil.WriteFileLines(fs, testdataLines, tt.configFilename) require.NoError(t, err) tt.before(fs) balanceService := NewBalanceService( @@ -248,7 +248,7 @@ func Test_BalanceService_BanIRQsAndRestart(t *testing.T) { err = balanceService.BanIRQsAndRestart(tt.bannedIRQs) require.NoError(t, err) // Check if backup is created - backupFileContent, err := utils.ReadFileLines(fs, tt.backupFilename) + backupFileContent, err := rpkutil.ReadFileLines(fs, tt.backupFilename) require.NoError(t, err) tt.assert(fs, tt.configFilename, backupFileContent) }) @@ -264,7 +264,7 @@ func Test_balanceService_GetBannedIRQs(t *testing.T) { { name: "Shall return all banned irq", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{ "ONE_SHOT=true", "#IRQBALANCE_BANNED_CPUS=", @@ -278,7 +278,7 @@ func Test_balanceService_GetBannedIRQs(t *testing.T) { { name: "Shall return empty list as there are none banned IRQs", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{ "ONE_SHOT=true", "#IRQBALANCE_BANNED_CPUS=", @@ -290,7 +290,7 @@ func Test_balanceService_GetBannedIRQs(t *testing.T) { { name: "Shall return empty list as there are no custom options line", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{ "ONE_SHOT=true", "#IRQBALANCE_BANNED_CPUS=", diff --git a/src/go/rpk/pkg/tuners/irq/cpu_masks.go b/src/go/rpk/pkg/tuners/irq/cpu_masks.go index 78a207fdb513f..387f5ac66c228 100644 --- a/src/go/rpk/pkg/tuners/irq/cpu_masks.go +++ b/src/go/rpk/pkg/tuners/irq/cpu_masks.go @@ -77,16 +77,17 @@ func (masks *cpuMasks) CPUMaskForComputations( zap.L().Sugar().Debugf("Computing CPU mask for '%s' mode and input CPU mask '%s'", mode, cpuMask) computationsMask := "" var err error - if mode == Sq { + switch mode { + case Sq: // all but CPU0 computationsMask, err = masks.hwloc.Calc(cpuMask, "~PU:0") - } else if mode == SqSplit { + case SqSplit: // all but CPU0 and its HT siblings computationsMask, err = masks.hwloc.Calc(cpuMask, "~core:0") - } else if mode == Mq { + case Mq: // all available cores computationsMask = cpuMask - } else if mode == Dedicated { + case Dedicated: numOfPUs, err := masks.GetNumberOfPUs(cpuMask) if err != nil { return "", err @@ -101,7 +102,7 @@ func (masks *cpuMasks) CPUMaskForComputations( if err != nil { return "", err } - } else { + default: err = fmt.Errorf("unsupported mode: '%s'", mode) } @@ -144,9 +145,9 @@ func (masks *cpuMasks) SetMask(path string, mask string) error { if _, err := masks.fs.Stat(path); err != nil { return fmt.Errorf("SMP affinity file '%s' not exist", path) } - formattedMask := strings.Replace(mask, "0x", "", -1) + formattedMask := strings.ReplaceAll(mask, "0x", "") for strings.Contains(formattedMask, ",,") { - formattedMask = strings.Replace(formattedMask, ",,", ",0,", -1) + formattedMask = strings.ReplaceAll(formattedMask, ",,", ",0,") } zap.L().Sugar().Debugf("Setting mask '%s' in '%s'", formattedMask, path) @@ -207,7 +208,7 @@ func (masks *cpuMasks) ReadMask(path string) (string, error) { } rawMask := strings.TrimSpace(string(content)) - rawMask = strings.Replace(rawMask, ",0,", ",,", -1) + rawMask = strings.ReplaceAll(rawMask, ",0,", ",,") parts := strings.Split(rawMask, ",") var newMaskParts []string for _, part := range parts { diff --git a/src/go/rpk/pkg/tuners/irq/device_info.go b/src/go/rpk/pkg/tuners/irq/device_info.go index 000171e6d1853..734986bc422e8 100644 --- a/src/go/rpk/pkg/tuners/irq/device_info.go +++ b/src/go/rpk/pkg/tuners/irq/device_info.go @@ -19,7 +19,7 @@ import ( "strconv" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -56,7 +56,7 @@ func (deviceInfo *deviceInfo) GetIRQs( var irqs []int if exists, _ := afero.Exists(deviceInfo.fs, msiIRQsDirName); exists { zap.L().Sugar().Debugf("Device '%s' uses MSI IRQs", irqConfigDir) - files := utils.ListFilesInPath(deviceInfo.fs, msiIRQsDirName) + files := rpkutil.ListFilesInPath(deviceInfo.fs, msiIRQsDirName) for _, file := range files { irq, err := strconv.Atoi(file) if err != nil { @@ -71,7 +71,7 @@ func (deviceInfo *deviceInfo) GetIRQs( irqFileName := path.Join(irqConfigDir, "irq") if exists, _ := afero.Exists(deviceInfo.fs, irqFileName); exists { zap.L().Sugar().Debugf("Device '%s' uses INT#x IRQs", irqConfigDir) - lines, err := utils.ReadFileLines(deviceInfo.fs, irqFileName) + lines, err := rpkutil.ReadFileLines(deviceInfo.fs, irqFileName) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (deviceInfo *deviceInfo) GetIRQs( if err != nil { return nil, fmt.Errorf("unable to find device info in %q: %v", irqConfigDir, err) } - lines, err := utils.ReadFileLines(deviceInfo.fs, modAliasFileName) + lines, err := rpkutil.ReadFileLines(deviceInfo.fs, modAliasFileName) if err != nil { return nil, err } @@ -99,7 +99,7 @@ func (deviceInfo *deviceInfo) GetIRQs( } if strings.Contains(modAlias, "virtio") { zap.L().Sugar().Debugf("Device '%s' is a virtio device type", irqConfigDir) - fileNames := utils.ListFilesInPath(deviceInfo.fs, path.Join(irqConfigDir, "driver")) + fileNames := rpkutil.ListFilesInPath(deviceInfo.fs, path.Join(irqConfigDir, "driver")) for _, name := range fileNames { if strings.Contains(name, "virtio") { irqs = append(irqs, diff --git a/src/go/rpk/pkg/tuners/irq/device_info_test.go b/src/go/rpk/pkg/tuners/irq/device_info_test.go index e1716a90cbb1c..42913a8330943 100644 --- a/src/go/rpk/pkg/tuners/irq/device_info_test.go +++ b/src/go/rpk/pkg/tuners/irq/device_info_test.go @@ -15,7 +15,7 @@ import ( "os" "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -64,7 +64,7 @@ func Test_DeviceInfo_GetIRQs(t *testing.T) { { name: "Shall return the IRQs when device is using INT#x IRQs", before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, []string{"1", "2", "5", "8"}, + _ = rpkutil.WriteFileLines(fs, []string{"1", "2", "5", "8"}, "/irq_config/dev1/irq") }, irqConfigDir: "/irq_config/dev1", @@ -82,10 +82,10 @@ func Test_DeviceInfo_GetIRQs(t *testing.T) { }, }, before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{"virtio:v00008086d000024DBsv0000103Csd0000006Abc01sc01i8A"}, "/irq_config/dev1/modalias") - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{}, "/irq_config/dev1/driver/drv-virtio-1") }, @@ -105,10 +105,10 @@ func Test_DeviceInfo_GetIRQs(t *testing.T) { }, }, before: func(fs afero.Fs) { - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{"xen:v00008086d000024DBsv0000103Csd0000006Abc01sc01i8A"}, "/irq_config/dev1/modalias") - _ = utils.WriteFileLines(fs, + _ = rpkutil.WriteFileLines(fs, []string{}, "/irq_config/dev1/driver/drv-virtio-1") }, diff --git a/src/go/rpk/pkg/tuners/irq/irq_tuner_mode.go b/src/go/rpk/pkg/tuners/irq/irq_tuner_mode.go index 7bc7ab43ff144..7dd338e4805d6 100644 --- a/src/go/rpk/pkg/tuners/irq/irq_tuner_mode.go +++ b/src/go/rpk/pkg/tuners/irq/irq_tuner_mode.go @@ -53,15 +53,16 @@ const ( ) func ModeFromString(modeString string) Mode { - if modeString == "mq" { + switch modeString { + case "mq": return Mq - } else if modeString == "sq" { + case "sq": return Sq - } else if modeString == "sq-split" { + case "sq-split": return SqSplit - } else if modeString == "dedicated" { + case "dedicated": return Dedicated + default: + return Default } - - return Default } diff --git a/src/go/rpk/pkg/tuners/irq/proc_file.go b/src/go/rpk/pkg/tuners/irq/proc_file.go index 7e8f813169133..748da4987fe52 100644 --- a/src/go/rpk/pkg/tuners/irq/proc_file.go +++ b/src/go/rpk/pkg/tuners/irq/proc_file.go @@ -16,7 +16,7 @@ import ( "strconv" "strings" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -37,7 +37,7 @@ type procFile struct { func (procFile *procFile) GetIRQProcFileLinesMap() (map[int]string, error) { zap.L().Sugar().Debugf("Reading '/proc/interrupts' file...") - lines, err := utils.ReadFileLines(procFile.fs, "/proc/interrupts") + lines, err := rpkutil.ReadFileLines(procFile.fs, "/proc/interrupts") if err != nil { return nil, err } diff --git a/src/go/rpk/pkg/tuners/irq/proc_file_test.go b/src/go/rpk/pkg/tuners/irq/proc_file_test.go index 91ab544dee873..42956c171e4dc 100644 --- a/src/go/rpk/pkg/tuners/irq/proc_file_test.go +++ b/src/go/rpk/pkg/tuners/irq/proc_file_test.go @@ -14,7 +14,7 @@ package irq import ( "testing" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -70,7 +70,7 @@ PIW: 0 Posted-interrupt wakeup event func TestProcFile_GetIRQProcFileLinesMap(t *testing.T) { // given fs := afero.NewMemMapFs() - _ = utils.WriteFileLines(fs, procFileLines, "/proc/interrupts") + _ = rpkutil.WriteFileLines(fs, procFileLines, "/proc/interrupts") procFile := NewProcFile(fs) // when procFileLinesMap, err := procFile.GetIRQProcFileLinesMap() diff --git a/src/go/rpk/pkg/tuners/irq/utils.go b/src/go/rpk/pkg/tuners/irq/utils.go index 876f5694f6b0a..0ed0468b5d75a 100644 --- a/src/go/rpk/pkg/tuners/irq/utils.go +++ b/src/go/rpk/pkg/tuners/irq/utils.go @@ -11,7 +11,7 @@ package irq -import "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" +import "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" func GetAllIRQs(deviceIRQs map[string][]int) []int { irqsSet := map[int]bool{} @@ -20,5 +20,5 @@ func GetAllIRQs(deviceIRQs map[string][]int) []int { irqsSet[irq] = true } } - return utils.GetIntKeys(irqsSet) + return rpkutil.GetIntKeys(irqsSet) } diff --git a/src/go/rpk/pkg/tuners/net_checkers.go b/src/go/rpk/pkg/tuners/net_checkers.go index 9dc82128633e2..f4a582659a498 100644 --- a/src/go/rpk/pkg/tuners/net_checkers.go +++ b/src/go/rpk/pkg/tuners/net_checkers.go @@ -17,10 +17,10 @@ import ( "github.com/lorenzosaino/go-sysctl" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/ethtool" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/network" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -257,7 +257,7 @@ func (f *netCheckersFactory) NewNicRfsChecker(nic network.Nic, effectiveConfig n return false, err } for _, limitFile := range limits { - setLimit, err := utils.ReadIntFromFile(f.fs, limitFile) + setLimit, err := rpkutil.ReadIntFromFile(f.fs, limitFile) if err != nil { return false, err } @@ -373,7 +373,7 @@ func (f *netCheckersFactory) NewListenBacklogChecker() Checker { return fmt.Sprintf(">= %d", network.ListenBacklogSize) }, func() (int, error) { - return utils.ReadIntFromFile(f.fs, network.ListenBacklogFile) + return rpkutil.ReadIntFromFile(f.fs, network.ListenBacklogFile) }, ) } @@ -390,7 +390,7 @@ func (f *netCheckersFactory) NewSynBacklogChecker() Checker { return fmt.Sprintf(">= %d", network.SynBacklogSize) }, func() (int, error) { - return utils.ReadIntFromFile(f.fs, network.SynBacklogFile) + return rpkutil.ReadIntFromFile(f.fs, network.SynBacklogFile) }, ) } diff --git a/src/go/rpk/pkg/tuners/net_tuners.go b/src/go/rpk/pkg/tuners/net_tuners.go index 9a0c2c44d7d35..f20f0a2fcf9f8 100644 --- a/src/go/rpk/pkg/tuners/net_tuners.go +++ b/src/go/rpk/pkg/tuners/net_tuners.go @@ -15,7 +15,7 @@ import ( "fmt" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/ethtool" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" @@ -123,7 +123,7 @@ func NewNetTuner( irqProcFile irq.ProcFile, ethtool ethtool.EthtoolWrapper, executor executors.Executor, - proc os.Proc, + proc osutil.Proc, statePath string, ) Tunable { factory := NewNetTunersFactory( @@ -156,7 +156,7 @@ type netTunersFactory struct { cpuMasks irq.CPUMasks checkersFactory NetCheckersFactory executor executors.Executor - proc os.Proc + proc osutil.Proc statePath string } @@ -169,7 +169,7 @@ func NewNetTunersFactory( balanceService irq.BalanceService, cpuMasks irq.CPUMasks, executor executors.Executor, - proc os.Proc, + proc osutil.Proc, statePath string, ) NetTunersFactory { return &netTunersFactory{ diff --git a/src/go/rpk/pkg/tuners/net_tuners_test.go b/src/go/rpk/pkg/tuners/net_tuners_test.go index b4ab45751f260..53ce1e916a99f 100644 --- a/src/go/rpk/pkg/tuners/net_tuners_test.go +++ b/src/go/rpk/pkg/tuners/net_tuners_test.go @@ -17,14 +17,14 @@ import ( "time" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/ethtool" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/hwloc" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/network" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" @@ -34,7 +34,7 @@ func mockNetTunersFactory( fs afero.Fs, exec executors.Executor, ) (tuners.NetTunersFactory, error) { procFile := irq.NewProcFile(fs) - proc := os.NewProc() + proc := osutil.NewProc() timeout := 1 * time.Second hwlocCmd := hwloc.NewHwLocCmd(proc, timeout) eth, err := ethtool.NewEthtoolWrapper() @@ -66,7 +66,7 @@ func TestSynBacklogTuner(t *testing.T) { { name: "it shouldn't do anything if current >= reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("20000000"), network.SynBacklogFile, @@ -77,7 +77,7 @@ func TestSynBacklogTuner(t *testing.T) { { name: "it shouldn't do anything if current == reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("4096"), network.SynBacklogFile, @@ -88,7 +88,7 @@ func TestSynBacklogTuner(t *testing.T) { { name: "it should set the value if current < reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("12"), network.SynBacklogFile, @@ -148,7 +148,7 @@ func TestListenBacklogTuner(t *testing.T) { { name: "it shouldn't do anything if current >= reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("20000000"), network.ListenBacklogFile, @@ -159,7 +159,7 @@ func TestListenBacklogTuner(t *testing.T) { { name: "it shouldn't do anything if current == reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("4096"), network.ListenBacklogFile, @@ -170,7 +170,7 @@ func TestListenBacklogTuner(t *testing.T) { { name: "it should set the value if current < reference", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("12"), network.ListenBacklogFile, diff --git a/src/go/rpk/pkg/tuners/network/BUILD b/src/go/rpk/pkg/tuners/network/BUILD index 88b2384a01728..05abd2756caf8 100644 --- a/src/go/rpk/pkg/tuners/network/BUILD +++ b/src/go/rpk/pkg/tuners/network/BUILD @@ -12,18 +12,18 @@ go_library( deps = select({ "@rules_go//go/platform:android": [ "//src/go/rpk/pkg/config", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/ethtool", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_safchain_ethtool//:ethtool", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", ], "@rules_go//go/platform:linux": [ "//src/go/rpk/pkg/config", + "//src/go/rpk/pkg/rpkutil", "//src/go/rpk/pkg/tuners/ethtool", "//src/go/rpk/pkg/tuners/irq", - "//src/go/rpk/pkg/utils", "@com_github_safchain_ethtool//:ethtool", "@com_github_spf13_afero//:afero", "@org_uber_go_zap//:zap", diff --git a/src/go/rpk/pkg/tuners/network/nic.go b/src/go/rpk/pkg/tuners/network/nic.go index cb40599735c8d..3a90bac6dda55 100644 --- a/src/go/rpk/pkg/tuners/network/nic.go +++ b/src/go/rpk/pkg/tuners/network/nic.go @@ -18,9 +18,9 @@ import ( "strconv" "strings" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/ethtool" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/irq" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "go.uber.org/zap" ) @@ -112,7 +112,7 @@ func (n *nic) Name() string { // NICs. func getLowerNames(fs afero.Fs, nicName string) []string { nicDir := fmt.Sprintf("/sys/class/net/%s", nicName) - files := utils.ListFilesInPath(fs, nicDir) + files := rpkutil.ListFilesInPath(fs, nicDir) lowers := []string{} for _, file := range files { @@ -337,7 +337,7 @@ func (n *nic) GetMaxRxQueueCount() (int, error) { func (n *nic) GetRxQueueCount() (int, error) { rpsCpus, err := n.GetRpsCPUFiles() if err != nil { - return 0, utils.ChainedError(err, "Unable to get the RPS number") + return 0, rpkutil.ChainedError(err, "Unable to get the RPS number") } rxQueuesCount := len(rpsCpus) zap.L().Sugar().Debugf("Getting number of Rx queues for '%s'", n.name) diff --git a/src/go/rpk/pkg/tuners/network/nics.go b/src/go/rpk/pkg/tuners/network/nics.go index e8385dda484c5..e5ac6b6cad8b0 100644 --- a/src/go/rpk/pkg/tuners/network/nics.go +++ b/src/go/rpk/pkg/tuners/network/nics.go @@ -221,12 +221,13 @@ func checkDedicatedCompatibleConfig(cpuMask string, cpuMasks irq.CPUMasks, rnc c func getEffectiveMode(mode irq.Mode, nic Nic, effectiveCPUMask string, cpuMasks irq.CPUMasks, rnc config.RpkNodeConfig) (irq.Mode, error) { var err error effectiveMode := mode - if mode == irq.Default { + switch mode { + case irq.Default: effectiveMode, err = GetDefaultMode(nic, effectiveCPUMask, cpuMasks, rnc) if err != nil { return "", err } - } else if mode == irq.Dedicated { + case irq.Dedicated: // dedicated specified via cli arg --mode dedicated err := checkDedicatedCompatibleConfig(effectiveCPUMask, cpuMasks, rnc) if err != nil { diff --git a/src/go/rpk/pkg/tuners/redpanda_checkers.go b/src/go/rpk/pkg/tuners/redpanda_checkers.go index f825ba491799a..17ab6870030a5 100644 --- a/src/go/rpk/pkg/tuners/redpanda_checkers.go +++ b/src/go/rpk/pkg/tuners/redpanda_checkers.go @@ -20,8 +20,8 @@ import ( "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cloud" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cloud/gcp" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/net" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/netutil" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/system/filesystem" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/disk" @@ -204,7 +204,7 @@ func RedpandaCheckers( y *config.RedpandaYaml, timeout time.Duration, ) (map[CheckerID][]Checker, error) { - proc := os.NewProc() + proc := osutil.NewProc() ethtool, err := ethtool.NewEthtoolWrapper() if err != nil { return nil, err @@ -227,7 +227,7 @@ func RedpandaCheckers( for _, address := range y.Redpanda.KafkaAPI { addrs = append(addrs, address.Address) } - interfaces, err := net.GetInterfacesByIps( + interfaces, err := netutil.GetInterfacesByIps( addrs..., ) if err != nil { diff --git a/src/go/rpk/pkg/tuners/swappiness_test.go b/src/go/rpk/pkg/tuners/swappiness_test.go index e9bb236c43efa..f57501b769a7a 100644 --- a/src/go/rpk/pkg/tuners/swappiness_test.go +++ b/src/go/rpk/pkg/tuners/swappiness_test.go @@ -15,9 +15,9 @@ import ( "fmt" "testing" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/rpkutil" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/tuners/executors" - "github.com/redpanda-data/redpanda/src/go/rpk/pkg/utils" "github.com/spf13/afero" "github.com/stretchr/testify/require" ) @@ -32,7 +32,7 @@ func TestChecker(t *testing.T) { { name: "It should return true if the value is correct", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte(fmt.Sprint(tuners.ExpectedSwappiness)), tuners.File, @@ -44,7 +44,7 @@ func TestChecker(t *testing.T) { { name: "It should return false if the file exists but the value iswrong", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("120"), tuners.File, @@ -87,7 +87,7 @@ func TestTuner(t *testing.T) { { name: "It should leave the same value if it was correct", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte(fmt.Sprint(tuners.ExpectedSwappiness)), tuners.File, @@ -98,7 +98,7 @@ func TestTuner(t *testing.T) { { name: "It should change the value if it was different", before: func(fs afero.Fs) error { - _, err := utils.WriteBytes( + _, err := rpkutil.WriteBytes( fs, []byte("120"), tuners.File, @@ -125,7 +125,7 @@ func TestTuner(t *testing.T) { return } require.NoError(t, res.Error()) - lines, err := utils.ReadFileLines(fs, tuners.File) + lines, err := rpkutil.ReadFileLines(fs, tuners.File) require.NoError(t, err) require.Len(t, lines, 1) require.Equal(t, fmt.Sprint(tuners.ExpectedSwappiness), lines[0])