Skip to content
Merged
4 changes: 4 additions & 0 deletions internal/cmd/skupper/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ for other Kubernetes flavors, loadbalancer is the default.`

FlagDescUninstallForce = "all existing sites (active or not) will be deleted"

FlagNameUpgrade = "upgrade"
FlagDescUpgrade = "replace the running system controller container with the images specified in the environment variables or the current image by default"

FlagNameHA = "enable-ha"
FlagDescHA = "Configure the site for high availability (EnableHA). EnableHA sites have two active routers"

Expand Down Expand Up @@ -297,4 +300,5 @@ type CommandSystemDeleteFlags struct {

type CommandSystemInstallFlags struct {
ReloadType string
Upgrade bool
}
30 changes: 21 additions & 9 deletions internal/cmd/skupper/connector/nonkube/connector_create_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package nonkube

import (
"os"
"testing"

"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"github.com/skupperproject/skupper/internal/nonkube/client/fs"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"

"gotest.tools/v3/assert"
"k8s.io/apimachinery/pkg/runtime"
)

func TestNonKubeCmdConnectorCreate_ValidateInput(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
Comment thread
nluaces marked this conversation as resolved.
Resolved
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}
type test struct {
name string
namespace string
Expand Down Expand Up @@ -284,16 +291,21 @@ func TestNonKubeCmdConnectorCreate_Run(t *testing.T) {
}

for _, test := range testTable {
command := &CmdConnectorCreate{}

command.connectorName = test.connectorName
command.port = test.connectorPort
command.host = test.host
command.connectorType = test.connectorType
command.namespace = test.namespace
command.connectorHandler = fs.NewConnectorHandler(command.namespace)
defer command.connectorHandler.Delete("test1")
t.Run(test.name, func(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}

command := &CmdConnectorCreate{}

command.connectorName = test.connectorName
command.port = test.connectorPort
command.host = test.host
command.connectorType = test.connectorType
command.namespace = test.namespace
command.connectorHandler = fs.NewConnectorHandler(command.namespace)

err := command.Run()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func TestCmdConnectorUpdate_ValidateInput(t *testing.T) {
}

func TestCmdConnectorUpdate_Run(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}

type test struct {
name string
namespace string
Expand Down
14 changes: 13 additions & 1 deletion internal/cmd/skupper/listener/nonkube/listener_create_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package nonkube

import (
"os"
"testing"

"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"github.com/skupperproject/skupper/internal/nonkube/client/fs"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"

"gotest.tools/v3/assert"
"k8s.io/apimachinery/pkg/runtime"
)

func TestNonKubeCmdListenerCreate_ValidateInput(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}
type test struct {
name string
namespace string
Expand Down Expand Up @@ -231,6 +238,12 @@ func TestNonKubeCmdListenerCreate_InputToOptions(t *testing.T) {
}

func TestNonKubeCmdListenerCreate_Run(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}

type test struct {
name string
k8sObjects []runtime.Object
Expand Down Expand Up @@ -284,7 +297,6 @@ func TestNonKubeCmdListenerCreate_Run(t *testing.T) {
command.listenerType = test.listenerType
command.namespace = "test"
command.listenerHandler = fs.NewListenerHandler(command.namespace)
defer command.listenerHandler.Delete("test1")
t.Run(test.name, func(t *testing.T) {

err := command.Run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func TestCmdListenerUpdate_ValidateInput(t *testing.T) {
}

func TestCmdListenerUpdate_Run(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}

type test struct {
name string
namespace string
Expand Down
14 changes: 13 additions & 1 deletion internal/cmd/skupper/site/nonkube/site_create_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package nonkube

import (
"os"
"testing"

"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"github.com/skupperproject/skupper/internal/nonkube/client/fs"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"
"gotest.tools/v3/assert"
)

func TestNonKubeCmdSiteCreate_ValidateInput(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}
type test struct {
name string
namespace string
Expand Down Expand Up @@ -144,6 +151,12 @@ func TestNonKubeCmdSiteCreate_InputToOptions(t *testing.T) {
}

func TestNonKubeCmdSiteCreate_Run(t *testing.T) {
if os.Getuid() == 0 {
api.DefaultRootDataHome = t.TempDir()
} else {
t.Setenv("XDG_DATA_HOME", t.TempDir())
}

type test struct {
name string
siteName string
Expand Down Expand Up @@ -171,7 +184,6 @@ func TestNonKubeCmdSiteCreate_Run(t *testing.T) {
command.siteName = test.siteName
command.linkAccessEnabled = test.linkAccessEnabled
command.siteHandler = fs.NewSiteHandler(command.namespace)
defer command.siteHandler.Delete("my-site")
t.Run(test.name, func(t *testing.T) {

err := command.Run()
Expand Down
29 changes: 24 additions & 5 deletions internal/cmd/skupper/system/nonkube/system_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type CmdSystemInstall struct {
CobraCmd *cobra.Command
Namespace string
SystemInstall func(string, string) error
SystemUpgrade func(string) error
Flags *common.CommandSystemInstallFlags
reloadType string
upgrade bool
}

func NewCmdSystemInstall() *CmdSystemInstall {
Expand All @@ -30,6 +32,7 @@ func NewCmdSystemInstall() *CmdSystemInstall {

func (cmd *CmdSystemInstall) NewClient(cobraCommand *cobra.Command, args []string) {
cmd.SystemInstall = bootstrap.Install
cmd.SystemUpgrade = bootstrap.Upgrade
}

func (cmd *CmdSystemInstall) ValidateInput(args []string) error {
Expand All @@ -45,7 +48,17 @@ func (cmd *CmdSystemInstall) ValidateInput(args []string) error {
validationErrors = append(validationErrors, fmt.Errorf("the selected platform is not supported by this command. There is nothing to install"))
}

if cmd.Flags != nil && cmd.Flags.ReloadType != "" {
if cmd.Flags != nil && cmd.Flags.Upgrade {
reloadTypeSpecified := false
if cmd.CobraCmd != nil && cmd.CobraCmd.Flags().Changed(common.FlagNameReloadType) {
reloadTypeSpecified = true
} else if cmd.CobraCmd == nil && cmd.Flags.ReloadType != "" {
reloadTypeSpecified = true
}
if reloadTypeSpecified {
validationErrors = append(validationErrors, fmt.Errorf("--%s cannot be specified with --%s", common.FlagNameReloadType, common.FlagNameUpgrade))
}
} else if cmd.Flags != nil && cmd.Flags.ReloadType != "" {
ok, err := reloadTypeValidator.Evaluate(cmd.Flags.ReloadType)
if !ok {
validationErrors = append(validationErrors, fmt.Errorf("reload type is not valid: %s", err))
Expand All @@ -59,15 +72,21 @@ func (cmd *CmdSystemInstall) InputToOptions() {
if cmd.Flags != nil && cmd.Flags.ReloadType != "" {
cmd.reloadType = cmd.Flags.ReloadType
}
if cmd.Flags != nil {
cmd.upgrade = cmd.Flags.Upgrade
}
}

func (cmd *CmdSystemInstall) Run() error {
err := cmd.SystemInstall(string(config.GetPlatform()), cmd.reloadType)

var err error
if cmd.upgrade {
err = cmd.SystemUpgrade(string(config.GetPlatform()))
} else {
err = cmd.SystemInstall(string(config.GetPlatform()), cmd.reloadType)
}
if err != nil {
return fmt.Errorf("failed to configure the environment : %s", err)
return fmt.Errorf("failed to configure the environment: %s", err)
}

return nil
}

Expand Down
82 changes: 66 additions & 16 deletions internal/cmd/skupper/system/nonkube/system_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestCmdSystemInstall_ValidateInput(t *testing.T) {
args []string
platform string
reloadType string
upgrade bool
expectedError string
}

Expand All @@ -39,6 +40,19 @@ func TestCmdSystemInstall_ValidateInput(t *testing.T) {
platform: "podman",
expectedError: "reload type is not valid: value both not allowed. It should be one of this options: [manual auto]",
},
{
name: "reload type cannot be specified with upgrade",
reloadType: "manual",
upgrade: true,
platform: "podman",
expectedError: "--reload-type cannot be specified with --upgrade",
},
{
name: "upgrade without reload type is allowed",
upgrade: true,
platform: "podman",
expectedError: "",
},
}

for _, test := range testTable {
Expand All @@ -50,36 +64,67 @@ func TestCmdSystemInstall_ValidateInput(t *testing.T) {

command := &CmdSystemInstall{Flags: &cmd.CommandSystemInstallFlags{}}
command.Flags.ReloadType = test.reloadType
command.Flags.Upgrade = test.upgrade

testutils.CheckValidateInput(t, command, test.expectedError, test.args)
})
}
}

func TestCmdSystemInstall_InputToOptions(t *testing.T) {
t.Run("upgrade flag is propagated", func(t *testing.T) {
command := &CmdSystemInstall{
Flags: &cmd.CommandSystemInstallFlags{Upgrade: true},
}
command.InputToOptions()
assert.Check(t, command.upgrade == true)
})

t.Run("upgrade flag defaults to false", func(t *testing.T) {
command := &CmdSystemInstall{
Flags: &cmd.CommandSystemInstallFlags{},
}
command.InputToOptions()
assert.Check(t, command.upgrade == false)
})
}

func TestCmdSystemInstall_Run(t *testing.T) {
type test struct {
name string
socketEnablementFails bool
errorMessage string
name string
upgrade bool
installFails bool
upgradeFails bool
errorMessage string
}

testTable := []test{
{
name: "runs ok",
socketEnablementFails: false,
errorMessage: "",
name: "install runs ok",
errorMessage: "",
},
{
name: "install fails",
installFails: true,
errorMessage: "failed to configure the environment: systemd failed to enable podman socket",
},
{
name: "upgrade runs ok",
upgrade: true,
errorMessage: "",
},
{
name: "socket enablement fails",
socketEnablementFails: true,
errorMessage: "failed to configure the environment : systemd failed to enable podman socket",
name: "upgrade fails",
upgrade: true,
upgradeFails: true,
errorMessage: "failed to configure the environment: upgrade failed",
},
}

for _, test := range testTable {
command := newCmdSystemInstallWithMocks(test.socketEnablementFails)

t.Run(test.name, func(t *testing.T) {
command := newCmdSystemInstallWithMocks(test.installFails, test.upgradeFails)
command.upgrade = test.upgrade

err := command.Run()
if err != nil {
Expand All @@ -93,20 +138,25 @@ func TestCmdSystemInstall_Run(t *testing.T) {

// --- helper methods

func newCmdSystemInstallWithMocks(podmanSocketEnablementFails bool) *CmdSystemInstall {

func newCmdSystemInstallWithMocks(installFails bool, upgradeFails bool) *CmdSystemInstall {
cmdMock := &CmdSystemInstall{
SystemInstall: mockCmdSystemInstall,
SystemUpgrade: mockCmdSystemUpgrade,
}

if podmanSocketEnablementFails {
if installFails {
cmdMock.SystemInstall = mockCmdSystemInstallSocketEnablementFails
}

if upgradeFails {
cmdMock.SystemUpgrade = mockCmdSystemUpgradeFails
}
return cmdMock
}

func mockCmdSystemInstall(platform string, reloadType string) error { return nil }
func mockCmdSystemInstallSocketEnablementFails(platform string, reloadType string) error {
return fmt.Errorf("systemd failed to enable podman socket")
}
func mockCmdSystemUpgrade(platform string) error { return nil }
func mockCmdSystemUpgradeFails(platform string) error {
return fmt.Errorf("upgrade failed")
}
Loading
Loading