diff --git a/.github/workflows/rpk-build.yml b/.github/workflows/rpk-build.yml index 14e6de8bfb1e..955fb7bae28f 100644 --- a/.github/workflows/rpk-build.yml +++ b/.github/workflows/rpk-build.yml @@ -24,7 +24,7 @@ jobs: name: Test and Build strategy: matrix: - os: [linux, darwin] + os: [linux, darwin, windows] arch: [amd64, arm64] runs-on: ubuntu-latest steps: @@ -56,6 +56,7 @@ jobs: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} ./build.sh $tag ${{ github.sha }} - name: Package + if: ${{ ! matrix.os == 'windows'}} working-directory: src/go/rpk/ run: | zip -j rpk-${{ matrix.os }}-${{ matrix.arch }}.zip ./${{ matrix.os }}-${{ matrix.arch }}/rpk diff --git a/src/go/rpk/pkg/cli/cmd/iotune.go b/src/go/rpk/pkg/cli/cmd/iotune.go index 5572949bc8e9..edc33f771202 100644 --- a/src/go/rpk/pkg/cli/cmd/iotune.go +++ b/src/go/rpk/pkg/cli/cmd/iotune.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package cmd import ( diff --git a/src/go/rpk/pkg/cli/cmd/root_windows.go b/src/go/rpk/pkg/cli/cmd/root_windows.go new file mode 100644 index 000000000000..ff4eb7fb2b5e --- /dev/null +++ b/src/go/rpk/pkg/cli/cmd/root_windows.go @@ -0,0 +1,19 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +package cmd + +import ( + "github.com/spf13/afero" + "github.com/spf13/cobra" +) + +// On Windows this is a no-op. +func addPlatformDependentCmds(fs afero.Fs, cmd *cobra.Command) { +} diff --git a/src/go/rpk/pkg/config/params.go b/src/go/rpk/pkg/config/params.go index d257b0cf1cce..3ed84d00ea7d 100644 --- a/src/go/rpk/pkg/config/params.go +++ b/src/go/rpk/pkg/config/params.go @@ -19,7 +19,6 @@ import ( "reflect" "strconv" "strings" - "syscall" "time" "github.com/spf13/afero" @@ -336,14 +335,9 @@ func (c *Config) Write(fs afero.Fs) (rerr error) { return fmt.Errorf("unable to chmod temp config file: %v", err) } - // Stat_t is only valid in unix not on Windows. - if stat, ok := stat.Sys().(*syscall.Stat_t); ok { - gid := int(stat.Gid) - uid := int(stat.Uid) - err = fs.Chown(temp, uid, gid) - if err != nil { - return fmt.Errorf("unable to chown temp config file: %v", err) - } + err = preserveUnixOwnership(fs, stat, temp) + if err != nil { + return err } } diff --git a/src/go/rpk/pkg/config/utils.go b/src/go/rpk/pkg/config/utils.go new file mode 100644 index 000000000000..058099fd0bb2 --- /dev/null +++ b/src/go/rpk/pkg/config/utils.go @@ -0,0 +1,33 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +//go:build !windows + +package config + +import ( + "fmt" + "os" + "syscall" + + "github.com/spf13/afero" +) + +func preserveUnixOwnership(fs afero.Fs, stat os.FileInfo, file string) error { + // Stat_t is only valid in unix not on Windows. + if stat, ok := stat.Sys().(*syscall.Stat_t); ok { + gid := int(stat.Gid) + uid := int(stat.Uid) + err := fs.Chown(file, uid, gid) + if err != nil { + return fmt.Errorf("unable to chown temp config file: %v", err) + } + } + return nil +} diff --git a/src/go/rpk/pkg/config/utils_windows.go b/src/go/rpk/pkg/config/utils_windows.go new file mode 100644 index 000000000000..e4d3af311032 --- /dev/null +++ b/src/go/rpk/pkg/config/utils_windows.go @@ -0,0 +1,24 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +//go:build windows + +package config + +import ( + "os" + + "github.com/spf13/afero" +) + +// In windows this is a no-op. + +func preserveUnixOwnership(fs afero.Fs, stat os.FileInfo, file string) error { + return nil +} diff --git a/src/go/rpk/pkg/os/lock.go b/src/go/rpk/pkg/os/lock.go index aacd46455b23..41ca94491c18 100644 --- a/src/go/rpk/pkg/os/lock.go +++ b/src/go/rpk/pkg/os/lock.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package os import ( diff --git a/src/go/rpk/pkg/redpanda/launcher.go b/src/go/rpk/pkg/redpanda/launcher.go index 4eff2085134a..bbe65c57e382 100644 --- a/src/go/rpk/pkg/redpanda/launcher.go +++ b/src/go/rpk/pkg/redpanda/launcher.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package redpanda import ( diff --git a/src/go/rpk/pkg/system/filesystem/fs.go b/src/go/rpk/pkg/system/filesystem/fs.go index 6c051b9373e5..d460bdc3adc2 100644 --- a/src/go/rpk/pkg/system/filesystem/fs.go +++ b/src/go/rpk/pkg/system/filesystem/fs.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package filesystem import ( diff --git a/src/go/rpk/pkg/system/memory_windows.go b/src/go/rpk/pkg/system/memory_windows.go new file mode 100644 index 000000000000..59ba4fb3040f --- /dev/null +++ b/src/go/rpk/pkg/system/memory_windows.go @@ -0,0 +1,20 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +package system + +import ( + "errors" + + "github.com/spf13/afero" +) + +func getMemInfo(_ afero.Fs) (*MemInfo, error) { + return nil, errors.New("Memory info collection not available in Windows") +} diff --git a/src/go/rpk/pkg/system/metrics.go b/src/go/rpk/pkg/system/metrics.go index 1ddaa8ed1481..20cce335396f 100644 --- a/src/go/rpk/pkg/system/metrics.go +++ b/src/go/rpk/pkg/system/metrics.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package system import ( diff --git a/src/go/rpk/pkg/system/metrics_windows.go b/src/go/rpk/pkg/system/metrics_windows.go new file mode 100644 index 000000000000..362cee78c4e3 --- /dev/null +++ b/src/go/rpk/pkg/system/metrics_windows.go @@ -0,0 +1,30 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +package system + +import ( + "errors" + "time" + + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" + "github.com/spf13/afero" +) + +type Metrics struct { + CPUPercentage float64 `json:"cpuPercentage"` + FreeMemoryMB float64 `json:"freeMemoryMB"` + FreeSpaceMB float64 `json:"freeSpaceMB"` +} + +func GatherMetrics( + fs afero.Fs, timeout time.Duration, conf config.Config, +) (*Metrics, error) { + return nil, errors.New("gathering metrics is not available in Windows") +} diff --git a/src/go/rpk/pkg/system/utils_windows.go b/src/go/rpk/pkg/system/utils_windows.go new file mode 100644 index 000000000000..8e5e83b12396 --- /dev/null +++ b/src/go/rpk/pkg/system/utils_windows.go @@ -0,0 +1,16 @@ +// Copyright 2022 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +package system + +import "errors" + +func uname() (string, error) { + return "", errors.New("uname not available in Windows") +} diff --git a/src/go/rpk/pkg/tuners/ethtool/ethtool.go b/src/go/rpk/pkg/tuners/ethtool/ethtool.go index a96aaed1c573..1fdae2f1bbe8 100644 --- a/src/go/rpk/pkg/tuners/ethtool/ethtool.go +++ b/src/go/rpk/pkg/tuners/ethtool/ethtool.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package ethtool import "github.com/safchain/ethtool" diff --git a/src/go/rpk/pkg/tuners/executors/commands/ethtool_change.go b/src/go/rpk/pkg/tuners/executors/commands/ethtool_change.go index 9f9ad469a6cb..2b31da0a976e 100644 --- a/src/go/rpk/pkg/tuners/executors/commands/ethtool_change.go +++ b/src/go/rpk/pkg/tuners/executors/commands/ethtool_change.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package commands import ( diff --git a/src/go/rpk/pkg/tuners/net_checkers.go b/src/go/rpk/pkg/tuners/net_checkers.go index 943fee25a934..5760cc567007 100644 --- a/src/go/rpk/pkg/tuners/net_checkers.go +++ b/src/go/rpk/pkg/tuners/net_checkers.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package tuners import ( diff --git a/src/go/rpk/pkg/tuners/net_tuners.go b/src/go/rpk/pkg/tuners/net_tuners.go index 3208d9e64efa..3c3094fbdb66 100644 --- a/src/go/rpk/pkg/tuners/net_tuners.go +++ b/src/go/rpk/pkg/tuners/net_tuners.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package tuners import ( diff --git a/src/go/rpk/pkg/tuners/network/nic.go b/src/go/rpk/pkg/tuners/network/nic.go index 5ee178c62c60..32881192e7ff 100644 --- a/src/go/rpk/pkg/tuners/network/nic.go +++ b/src/go/rpk/pkg/tuners/network/nic.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package network import ( diff --git a/src/go/rpk/pkg/tuners/redpanda_checkers.go b/src/go/rpk/pkg/tuners/redpanda_checkers.go index 340b5993b942..f176a637dfdf 100644 --- a/src/go/rpk/pkg/tuners/redpanda_checkers.go +++ b/src/go/rpk/pkg/tuners/redpanda_checkers.go @@ -7,6 +7,8 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +//go:build !windows + package tuners import (