Skip to content

Commit 9242028

Browse files
committed
Expose status sub-command on all platforms
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent f190eda commit 9242028

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/k0sproject/k0s/cmd/kubeconfig"
1616
"github.com/k0sproject/k0s/cmd/kubectl"
1717
"github.com/k0sproject/k0s/cmd/start"
18+
"github.com/k0sproject/k0s/cmd/status"
1819
"github.com/k0sproject/k0s/cmd/stop"
1920
"github.com/k0sproject/k0s/cmd/sysinfo"
2021
"github.com/k0sproject/k0s/cmd/token"
@@ -46,6 +47,7 @@ func NewRootCmd() *cobra.Command {
4647
cmd.AddCommand(kubectl.NewK0sKubectlCmd())
4748
cmd.AddCommand(start.NewStartCmd())
4849
cmd.AddCommand(stop.NewStopCmd())
50+
cmd.AddCommand(status.NewStatusCmd())
4951
cmd.AddCommand(sysinfo.NewSysinfoCmd())
5052
cmd.AddCommand(token.NewTokenCmd())
5153
cmd.AddCommand(validate.NewValidateCmd()) // hidden+deprecated

cmd/root_linux.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/k0sproject/k0s/cmd/keepalived"
1010
"github.com/k0sproject/k0s/cmd/reset"
1111
"github.com/k0sproject/k0s/cmd/restore"
12-
"github.com/k0sproject/k0s/cmd/status"
1312

1413
"github.com/spf13/cobra"
1514
)
@@ -20,5 +19,4 @@ func addPlatformSpecificCommands(root *cobra.Command) {
2019
root.AddCommand(keepalived.NewKeepalivedSetStateCmd()) // hidden
2120
root.AddCommand(reset.NewResetCmd())
2221
root.AddCommand(restore.NewRestoreCmd())
23-
root.AddCommand(status.NewStatusCmd())
2422
}

cmd/status/status.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build unix
2-
31
// SPDX-FileCopyrightText: 2021 k0s authors
42
// SPDX-License-Identifier: Apache-2.0
53

@@ -9,6 +7,7 @@ import (
97
"encoding/json"
108
"fmt"
119
"io"
10+
"runtime"
1211

1312
"github.com/k0sproject/k0s/cmd/internal"
1413
"github.com/k0sproject/k0s/pkg/component/status"
@@ -51,7 +50,14 @@ func NewStatusCmd() *cobra.Command {
5150

5251
pflags := cmd.PersistentFlags()
5352
debugFlags.AddToFlagSet(pflags)
54-
pflags.String("status-socket", "", "Full file path to the socket file. (default: <rundir>/status.sock)")
53+
var socketDefault string
54+
if runtime.GOOS == "windows" {
55+
socketDefault = status.DefaultSocketPath
56+
} else {
57+
socketDefault = "<rundir>/status.sock"
58+
}
59+
60+
pflags.String("status-socket", "", "Full path to the k0s status socket (default: "+socketDefault+")")
5561

5662
cmd.AddCommand(NewStatusSubCmdComponents())
5763

pkg/config/cfgvars.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,18 @@ func NewCfgVars(cobraCmd command, dirs ...string) (*CfgVars, error) {
141141
runDir = filepath.Join(dataDir, "run")
142142
}
143143

144-
statusSocketPath := filepath.Join(runDir, "status.sock")
145-
if runtime.GOOS != "windows" && euid == 0 {
146-
statusSocketPath = constant.StatusSocketPathDefault
144+
var statusSocketPath string
145+
if cobraCmd != nil {
146+
if val, err := cobraCmd.Flags().GetString("status-socket"); err == nil {
147+
statusSocketPath = val
148+
}
149+
}
150+
if statusSocketPath == "" {
151+
if runtime.GOOS == "windows" || euid == 0 {
152+
statusSocketPath = constant.StatusSocketPathDefault
153+
} else {
154+
statusSocketPath = filepath.Join(runDir, "status.sock")
155+
}
147156
}
148157

149158
certDir := filepath.Join(dataDir, "pki")

0 commit comments

Comments
 (0)