diff --git a/cmd/backup/backup_windows.go b/cmd/backup/backup_windows.go deleted file mode 100644 index 5c0293d8a62a..000000000000 --- a/cmd/backup/backup_windows.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2021 k0s authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package backup - -import ( - "errors" - - "github.com/spf13/cobra" -) - -var savePath string - -func NewBackupCmd() *cobra.Command { - return &cobra.Command{ - Use: "backup", - Short: "Back-Up k0s configuration. Not supported on Windows OS", - RunE: func(cmd *cobra.Command, args []string) error { - return errors.New("unsupported Operating System for this command") - }, - } -} diff --git a/cmd/install/controller.go b/cmd/install/controller.go index f3245ab02aaa..4be31aa1835e 100644 --- a/cmd/install/controller.go +++ b/cmd/install/controller.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/cmd/install/controller_test.go b/cmd/install/controller_test.go index 0571ff991fb7..e313552d6b37 100644 --- a/cmd/install/controller_test.go +++ b/cmd/install/controller_test.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2024 k0s authors diff --git a/cmd/install/install.go b/cmd/install/install.go index b9310f2a82e6..3f72e09adf18 100644 --- a/cmd/install/install.go +++ b/cmd/install/install.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/cmd/install/worker.go b/cmd/install/worker.go index f965ef6cad21..02139f5e6b92 100644 --- a/cmd/install/worker.go +++ b/cmd/install/worker.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/cmd/reset/reset.go b/cmd/reset/reset.go index 13253e803ec7..899913c78464 100644 --- a/cmd/reset/reset.go +++ b/cmd/reset/reset.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/cmd/restore/restore_windows.go b/cmd/restore/restore_windows.go deleted file mode 100644 index a23e2e4cb6f2..000000000000 --- a/cmd/restore/restore_windows.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2021 k0s authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package restore - -import ( - "errors" - - "github.com/spf13/cobra" -) - -var restoredConfigPath string - -func NewRestoreCmd() *cobra.Command { - return &cobra.Command{ - Use: "restore", - Short: "restore k0s state from given backup archive. Not supported in Windows OS", - RunE: func(cmd *cobra.Command, args []string) error { - return errors.New("unsupported Operating System for this command") - }, - } -} diff --git a/cmd/root.go b/cmd/root.go index 25e207d9abb0..0131f97c681f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,23 +20,15 @@ import ( "errors" "net/http" "os" - "runtime" "github.com/k0sproject/k0s/cmd/airgap" "github.com/k0sproject/k0s/cmd/api" - "github.com/k0sproject/k0s/cmd/backup" configcmd "github.com/k0sproject/k0s/cmd/config" "github.com/k0sproject/k0s/cmd/controller" "github.com/k0sproject/k0s/cmd/ctr" "github.com/k0sproject/k0s/cmd/etcd" - "github.com/k0sproject/k0s/cmd/install" "github.com/k0sproject/k0s/cmd/kubeconfig" "github.com/k0sproject/k0s/cmd/kubectl" - "github.com/k0sproject/k0s/cmd/reset" - "github.com/k0sproject/k0s/cmd/restore" - "github.com/k0sproject/k0s/cmd/start" - "github.com/k0sproject/k0s/cmd/status" - "github.com/k0sproject/k0s/cmd/stop" "github.com/k0sproject/k0s/cmd/sysinfo" "github.com/k0sproject/k0s/cmd/token" "github.com/k0sproject/k0s/cmd/validate" @@ -83,25 +75,12 @@ func NewRootCmd() *cobra.Command { cmd.AddCommand(airgap.NewAirgapCmd()) cmd.AddCommand(api.NewAPICmd()) - cmd.AddCommand(backup.NewBackupCmd()) cmd.AddCommand(controller.NewControllerCmd()) cmd.AddCommand(ctr.NewCtrCommand()) cmd.AddCommand(configcmd.NewConfigCmd()) cmd.AddCommand(etcd.NewEtcdCmd()) - cmd.AddCommand(install.NewInstallCmd()) cmd.AddCommand(kubeconfig.NewKubeConfigCmd()) cmd.AddCommand(kubectl.NewK0sKubectlCmd()) - if runtime.GOOS == "linux" { - // Currently only supported on Linux - cmd.AddCommand(reset.NewResetCmd()) - } - cmd.AddCommand(restore.NewRestoreCmd()) - cmd.AddCommand(start.NewStartCmd()) - if runtime.GOOS == "linux" { - // Currently only supported on Linux - cmd.AddCommand(status.NewStatusCmd()) - } - cmd.AddCommand(stop.NewStopCmd()) cmd.AddCommand(sysinfo.NewSysinfoCmd()) cmd.AddCommand(token.NewTokenCmd()) cmd.AddCommand(validate.NewValidateCmd()) // hidden+deprecated @@ -112,6 +91,8 @@ func NewRootCmd() *cobra.Command { cmd.AddCommand(newDefaultConfigCmd()) // hidden+deprecated cmd.AddCommand(newDocsCmd()) + addPlatformSpecificCommands(cmd) + cmd.DisableAutoGenTag = true longDesc = "k0s - The zero friction Kubernetes - https://k0sproject.io" if build.EulaNotice != "" { diff --git a/cmd/root_linux.go b/cmd/root_linux.go new file mode 100644 index 000000000000..dd018e859c42 --- /dev/null +++ b/cmd/root_linux.go @@ -0,0 +1,39 @@ +/* +Copyright 2024 k0s authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "github.com/k0sproject/k0s/cmd/backup" + "github.com/k0sproject/k0s/cmd/install" + "github.com/k0sproject/k0s/cmd/reset" + "github.com/k0sproject/k0s/cmd/restore" + "github.com/k0sproject/k0s/cmd/start" + "github.com/k0sproject/k0s/cmd/status" + "github.com/k0sproject/k0s/cmd/stop" + + "github.com/spf13/cobra" +) + +func addPlatformSpecificCommands(root *cobra.Command) { + root.AddCommand(backup.NewBackupCmd()) + root.AddCommand(install.NewInstallCmd()) + root.AddCommand(reset.NewResetCmd()) + root.AddCommand(restore.NewRestoreCmd()) + root.AddCommand(start.NewStartCmd()) + root.AddCommand(status.NewStatusCmd()) + root.AddCommand(stop.NewStopCmd()) +} diff --git a/pkg/cleanup/bridge_other.go b/cmd/root_other.go similarity index 79% rename from pkg/cleanup/bridge_other.go rename to cmd/root_other.go index 215f255e2395..0e69822b2757 100644 --- a/pkg/cleanup/bridge_other.go +++ b/cmd/root_other.go @@ -1,7 +1,7 @@ //go:build !linux /* -Copyright 2021 k0s authors +Copyright 2024 k0s authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -package cleanup +package cmd -func newBridgeStep() Step { - return nil -} +import "github.com/spf13/cobra" + +func addPlatformSpecificCommands(root *cobra.Command) { /* no-op */ } diff --git a/cmd/start/start.go b/cmd/start/start.go index b07c5aca1bb9..36817e6901c1 100644 --- a/cmd/start/start.go +++ b/cmd/start/start.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2021 k0s authors diff --git a/cmd/status/status.go b/cmd/status/status.go index 25c9aac9141c..ec0f9957104e 100644 --- a/cmd/status/status.go +++ b/cmd/status/status.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/cmd/stop/stop.go b/cmd/stop/stop.go index 57c51ff09a24..f6d2a1dec019 100644 --- a/cmd/stop/stop.go +++ b/cmd/stop/stop.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2021 k0s authors diff --git a/internal/pkg/users/lookup_unix_test.go b/internal/pkg/users/lookup_unix_test.go index 1bf444bc429c..a240d173887a 100644 --- a/internal/pkg/users/lookup_unix_test.go +++ b/internal/pkg/users/lookup_unix_test.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2022 k0s authors diff --git a/pkg/cleanup/cleanup.go b/pkg/cleanup/cleanup.go index c07cbba24321..9d76a2c85ea7 100644 --- a/pkg/cleanup/cleanup.go +++ b/pkg/cleanup/cleanup.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2021 k0s authors diff --git a/pkg/cleanup/services.go b/pkg/cleanup/services.go index 9f91ddc377ae..834f5348a848 100644 --- a/pkg/cleanup/services.go +++ b/pkg/cleanup/services.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2021 k0s authors diff --git a/pkg/cleanup/users.go b/pkg/cleanup/users.go index 9bd2b4cf699e..875687618cb5 100644 --- a/pkg/cleanup/users.go +++ b/pkg/cleanup/users.go @@ -1,3 +1,5 @@ +//go:build unix + /* Copyright 2021 k0s authors diff --git a/pkg/install/linux_openrc.go b/pkg/install/linux_openrc.go index 4f3461a8a310..4d9f598d8404 100644 --- a/pkg/install/linux_openrc.go +++ b/pkg/install/linux_openrc.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2022 k0s authors diff --git a/pkg/install/linux_systemd.go b/pkg/install/linux_systemd.go index 635946a7553a..825cef6587b7 100644 --- a/pkg/install/linux_systemd.go +++ b/pkg/install/linux_systemd.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2024 k0s authors diff --git a/pkg/install/linux_sysv.go b/pkg/install/linux_sysv.go index 2eebbb7f3669..1189cfaff687 100644 --- a/pkg/install/linux_sysv.go +++ b/pkg/install/linux_sysv.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2022 k0s authors diff --git a/pkg/install/linux_upstart.go b/pkg/install/linux_upstart.go index 17d18e2257f2..61ea9ca2df81 100644 --- a/pkg/install/linux_upstart.go +++ b/pkg/install/linux_upstart.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2022 k0s authors diff --git a/pkg/install/service.go b/pkg/install/service.go index c7cccd5d4b1c..283fd5e43c72 100644 --- a/pkg/install/service.go +++ b/pkg/install/service.go @@ -1,3 +1,5 @@ +//go:build linux + /* Copyright 2020 k0s authors diff --git a/pkg/install/users.go b/pkg/install/users.go index 9a85ec83aeaf..ebe83d7689d6 100644 --- a/pkg/install/users.go +++ b/pkg/install/users.go @@ -65,6 +65,8 @@ func DeleteControllerUsers(systemUsers *v1beta1.SystemUser) error { if err := deleteUser(userName); err != nil { errs = append(errs, err) } + } else if !errors.Is(err, users.ErrNotExist) { + errs = append(errs, err) } }