Skip to content

Commit c9ed299

Browse files
authored
Merge pull request #6719 from k0sproject/k0s-status-on-win
Enable "k0s status" sub-command and the status component on Windows workers
2 parents b6971ad + dd411dc commit c9ed299

File tree

20 files changed

+147
-80
lines changed

20 files changed

+147
-80
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

cmd/worker/worker.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import (
1818
"github.com/k0sproject/k0s/internal/pkg/stringmap"
1919
"github.com/k0sproject/k0s/internal/pkg/sysinfo"
2020
"github.com/k0sproject/k0s/internal/supervised"
21+
"github.com/k0sproject/k0s/pkg/build"
2122
"github.com/k0sproject/k0s/pkg/component/iptables"
2223
"github.com/k0sproject/k0s/pkg/component/manager"
2324
"github.com/k0sproject/k0s/pkg/component/prober"
25+
"github.com/k0sproject/k0s/pkg/component/status"
2426
"github.com/k0sproject/k0s/pkg/component/worker"
2527
workerconfig "github.com/k0sproject/k0s/pkg/component/worker/config"
2628
"github.com/k0sproject/k0s/pkg/component/worker/containerd"
@@ -298,6 +300,27 @@ func (c *Command) Start(ctx context.Context, nodeName apitypes.NodeName, kubelet
298300

299301
addPlatformSpecificComponents(ctx, componentManager, c.K0sVars, controller, certManager)
300302

303+
if controller == nil {
304+
// if running inside a controller, status component is already running
305+
componentManager.Add(ctx, &status.Status{
306+
Prober: prober.DefaultProber,
307+
StatusInformation: status.K0sStatus{
308+
Pid: os.Getpid(),
309+
Role: "worker",
310+
Args: os.Args,
311+
Version: build.Version,
312+
Workloads: true,
313+
SingleNode: false,
314+
K0sVars: c.K0sVars,
315+
// worker does not have cluster config. this is only shown in "k0s status -o json".
316+
// todo: if it's needed, a worker side config client can be set up and used to load the config
317+
ClusterConfig: nil,
318+
},
319+
CertManager: certManager,
320+
Socket: c.K0sVars.StatusSocketPath,
321+
})
322+
}
323+
301324
// extract needed components
302325
if err := componentManager.Init(ctx); err != nil {
303326
return err

cmd/worker/worker_unix.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,15 @@ package worker
77

88
import (
99
"context"
10-
"os"
1110

12-
"github.com/k0sproject/k0s/pkg/build"
1311
"github.com/k0sproject/k0s/pkg/component/manager"
14-
"github.com/k0sproject/k0s/pkg/component/prober"
15-
"github.com/k0sproject/k0s/pkg/component/status"
1612
"github.com/k0sproject/k0s/pkg/component/worker"
1713
"github.com/k0sproject/k0s/pkg/config"
1814
)
1915

2016
func initLogging(context.Context, string) error { return nil }
2117

2218
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, controller EmbeddingController, certManager *worker.CertificateManager) {
23-
// if running inside a controller, status component is already running
24-
if controller == nil {
25-
m.Add(ctx, &status.Status{
26-
Prober: prober.DefaultProber,
27-
StatusInformation: status.K0sStatus{
28-
Pid: os.Getpid(),
29-
Role: "worker",
30-
Args: os.Args,
31-
Version: build.Version,
32-
Workloads: true,
33-
SingleNode: false,
34-
K0sVars: k0sVars,
35-
// worker does not have cluster config. this is only shown in "k0s status -o json".
36-
// todo: if it's needed, a worker side config client can be set up and used to load the config
37-
ClusterConfig: nil,
38-
},
39-
CertManager: certManager,
40-
Socket: k0sVars.StatusSocketPath,
41-
})
42-
}
43-
4419
m.Add(ctx, &worker.Autopilot{
4520
K0sVars: k0sVars,
4621
CertManager: certManager,

cmd/worker/worker_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ func initLogging(ctx context.Context, logDir string) error {
4545
return nil
4646
}
4747

48-
func addPlatformSpecificComponents(context.Context, *manager.Manager, *config.CfgVars, EmbeddingController, *worker.CertificateManager) {
48+
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, controller EmbeddingController, certManager *worker.CertificateManager) {
4949
// no-op
5050
}

pkg/autopilot/controller/setup.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ func (sc *setupController) createControlNode(ctx context.Context, cf apcli.Facto
178178
return nil
179179
}
180180

181-
// TODO re-use from somewhere else
182-
const DefaultK0sStatusSocketPath = "/run/k0s/status.sock"
183-
184181
func getControlNodeAddresses(hostname string) ([]corev1.NodeAddress, error) {
185182
addresses := []corev1.NodeAddress{}
186183
apiAddress, err := getControllerAPIAddress()
@@ -201,7 +198,7 @@ func getControlNodeAddresses(hostname string) ([]corev1.NodeAddress, error) {
201198
}
202199

203200
func getControllerAPIAddress() (string, error) {
204-
status, err := status.GetStatusInfo(DefaultK0sStatusSocketPath)
201+
status, err := status.GetStatusInfo(status.DefaultSocketPath)
205202
if err != nil {
206203
return "", err
207204
}

pkg/autopilot/controller/signal/k0s/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func RegisterControllers(ctx context.Context, logger *logrus.Entry, mgr crman.Ma
3939
logger.Infof("Using effective hostname = '%v'", hostname)
4040

4141
k0sVersionHandler := func() (string, error) {
42-
return getK0sVersion(DefaultK0sStatusSocketPath)
42+
return getK0sVersion(status.DefaultSocketPath)
4343
}
4444

4545
if err := registerSignalController(logger, mgr, signalControllerEventFilter(hostname, apsigpred.DefaultErrorHandler(logger, "k0s signal")), delegate, clusterID, k0sVersionHandler); err != nil {

pkg/autopilot/controller/signal/k0s/restart_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *restart) Reconcile(ctx context.Context, req cr.Request) (cr.Result, err
9393

9494
// Get the current version of k0s
9595
logger.Info("Determining the current version of k0s")
96-
k0sVersion, err := getK0sVersion(DefaultK0sStatusSocketPath)
96+
k0sVersion, err := getK0sVersion(status.DefaultSocketPath)
9797
if err != nil {
9898
logger.Info("Unable to determine current verion of k0s; requeuing")
9999
return cr.Result{}, fmt.Errorf("unable to get k0s version: %w", err)
@@ -128,7 +128,7 @@ func (r *restart) Reconcile(ctx context.Context, req cr.Request) (cr.Result, err
128128

129129
logger.Info("Preparing to restart k0s")
130130

131-
k0sPid, err := getK0sPid(DefaultK0sStatusSocketPath)
131+
k0sPid, err := getK0sPid(status.DefaultSocketPath)
132132
if err != nil {
133133
logger.Info("Unable to determine current k0s pid; requeuing")
134134
return cr.Result{RequeueAfter: restartRequeueDuration}, fmt.Errorf("unable to get k0s pid: %w", err)

pkg/autopilot/controller/signal/k0s/restarted_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
apdel "github.com/k0sproject/k0s/pkg/autopilot/controller/delegate"
1515
apsigpred "github.com/k0sproject/k0s/pkg/autopilot/controller/signal/common/predicate"
1616
apsigv2 "github.com/k0sproject/k0s/pkg/autopilot/signaling/v2"
17+
"github.com/k0sproject/k0s/pkg/component/status"
1718

1819
"github.com/sirupsen/logrus"
1920
cr "sigs.k8s.io/controller-runtime"
@@ -86,7 +87,7 @@ func (r *restarted) Reconcile(ctx context.Context, req cr.Request) (cr.Result, e
8687

8788
// Get the current version of k0s
8889
logger.Info("Determining the current version of k0s")
89-
k0sVersion, err := getK0sVersion(DefaultK0sStatusSocketPath)
90+
k0sVersion, err := getK0sVersion(status.DefaultSocketPath)
9091
if err != nil {
9192
logger.Info("Unable to determine current verion of k0s; requeuing")
9293
return cr.Result{}, fmt.Errorf("unable to get k0s version: %w", err)

0 commit comments

Comments
 (0)