Skip to content

Commit

Permalink
Merge pull request #5260 from r-vasquez/fix-windows-build
Browse files Browse the repository at this point in the history
rpk: fix build for windows OS
  • Loading branch information
twmb committed Jul 7, 2022
2 parents 26b7d23 + f5bba5e commit dea5cac
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/rpk-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/cli/cmd/iotune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
19 changes: 19 additions & 0 deletions src/go/rpk/pkg/cli/cmd/root_windows.go
Original file line number Diff line number Diff line change
@@ -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) {
}
12 changes: 3 additions & 9 deletions src/go/rpk/pkg/config/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"
"strconv"
"strings"
"syscall"
"time"

"github.com/spf13/afero"
Expand Down Expand Up @@ -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
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/go/rpk/pkg/config/utils.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions src/go/rpk/pkg/config/utils_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/os/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/redpanda/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/system/filesystem/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
20 changes: 20 additions & 0 deletions src/go/rpk/pkg/system/memory_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/system/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
30 changes: 30 additions & 0 deletions src/go/rpk/pkg/system/metrics_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}
16 changes: 16 additions & 0 deletions src/go/rpk/pkg/system/utils_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/ethtool/ethtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/executors/commands/ethtool_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/net_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/net_tuners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/network/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/go/rpk/pkg/tuners/redpanda_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit dea5cac

Please sign in to comment.