Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import (
)

const (
ENV_PLATFORM = "SKUPPER_PLATFORM"
ENV_PLATFORM = "SKUPPER_PLATFORM"
ENV_SYSTEM_AUTO_RELOAD = "SKUPPER_SYSTEM_RELOAD_TYPE"

SystemReloadTypeAuto string = "auto"
SystemReloadTypeManual string = "manual"
)

type ConnectorCreateOptions struct {
Expand Down
5 changes: 5 additions & 0 deletions cmd/system-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"syscall"
"time"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/nonkube/controller"
"github.com/skupperproject/skupper/internal/utils"
"github.com/skupperproject/skupper/internal/version"
"github.com/skupperproject/skupper/pkg/nonkube/api"
)
Expand All @@ -23,6 +25,9 @@ func main() {
if api.IsRunningInContainer() {
slog.Info("Host path info:", slog.String("path", api.GetHostNamespacesPath()))
}
systemReloadType := utils.DefaultStr(os.Getenv(types.ENV_SYSTEM_AUTO_RELOAD),
types.SystemReloadTypeManual)
slog.Info("System Reload:", slog.String("type", systemReloadType))
if err := os.MkdirAll(namespacesPath, 0755); err != nil {
slog.Error("Error creating skupper namespaces directory", slog.String("path", namespacesPath), slog.Any("error", err))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/skupper/system/nonkube/system_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (cmd *CmdSystemApply) Run() error {
}

if crApplied {
fmt.Println("Custom resources are applied. If a site is already running, run `skupper system reload` to make effective the changes.")
fmt.Println("Custom resources are applied.")
}

return nil
Expand Down
10 changes: 10 additions & 0 deletions internal/cmd/skupper/system/nonkube/system_reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package nonkube
import (
"errors"
"fmt"
"os"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/config"
"github.com/skupperproject/skupper/internal/nonkube/bootstrap"
"github.com/skupperproject/skupper/internal/utils"
"github.com/skupperproject/skupper/internal/utils/validator"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,6 +42,13 @@ func (cmd *CmdSystemReload) ValidateInput(args []string) error {
var validationErrors []error
namespaceStringValidator := validator.NamespaceStringValidator()

systemReloadType := utils.DefaultStr(os.Getenv(types.ENV_SYSTEM_AUTO_RELOAD),
types.SystemReloadTypeManual)

if systemReloadType == types.SystemReloadTypeAuto {
validationErrors = append(validationErrors, fmt.Errorf("this command is disabled because automatic reloading is configured"))
}

if len(args) > 0 {
validationErrors = append(validationErrors, fmt.Errorf("this command does not accept arguments"))
}
Expand Down
22 changes: 17 additions & 5 deletions internal/cmd/skupper/system/nonkube/system_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"github.com/skupperproject/skupper/internal/config"
Expand All @@ -15,10 +16,11 @@ import (

func TestCmdSystemReload_ValidateInput(t *testing.T) {
type test struct {
name string
namespace string
args []string
expectedError string
name string
namespace string
envSystemReload string
args []string
expectedError string
}

testTable := []test{
Expand All @@ -32,11 +34,21 @@ func TestCmdSystemReload_ValidateInput(t *testing.T) {
namespace: "Invalid",
expectedError: "namespace is not valid: value does not match this regular expression: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$",
},
{
name: "command-is-disabled",
args: []string{},
namespace: "ns",
envSystemReload: types.SystemReloadTypeAuto,
expectedError: "this command is disabled because automatic reloading is configured",
},
}

for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {

t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, types.SystemReloadTypeManual)
if test.envSystemReload != "" {
t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, test.envSystemReload)
}
command := &CmdSystemReload{}
command.Namespace = test.namespace
command.CobraCmd = common.ConfigureCobraCommand(common.PlatformLinux, common.SkupperCmdDescription{}, command, nil)
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/skupper/system/nonkube/system_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"os"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/config"
"github.com/skupperproject/skupper/internal/nonkube/bootstrap"
"github.com/skupperproject/skupper/internal/utils"
"github.com/skupperproject/skupper/internal/utils/validator"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -40,6 +42,13 @@ func (cmd *CmdSystemStart) ValidateInput(args []string) error {
var validationErrors []error
namespaceStringValidator := validator.NamespaceStringValidator()

systemReloadType := utils.DefaultStr(os.Getenv(types.ENV_SYSTEM_AUTO_RELOAD),
types.SystemReloadTypeManual)

if systemReloadType == types.SystemReloadTypeAuto {
validationErrors = append(validationErrors, fmt.Errorf("this command is disabled because automatic reloading is configured"))
}

if args != nil && len(args) > 0 {
validationErrors = append(validationErrors, fmt.Errorf("this command does not accept arguments"))
}
Expand Down
22 changes: 17 additions & 5 deletions internal/cmd/skupper/system/nonkube/system_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"github.com/skupperproject/skupper/internal/config"
Expand All @@ -15,10 +16,11 @@ import (

func TestCmdSystemSetup_ValidateInput(t *testing.T) {
type test struct {
name string
args []string
namespace string
expectedError string
name string
args []string
envSystemReload string
namespace string
expectedError string
}

testTable := []test{
Expand All @@ -34,11 +36,21 @@ func TestCmdSystemSetup_ValidateInput(t *testing.T) {
namespace: "Invalid",
expectedError: "namespace is not valid: value does not match this regular expression: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$",
},
{
name: "command-is-disabled",
args: []string{},
namespace: "ns",
envSystemReload: types.SystemReloadTypeAuto,
expectedError: "this command is disabled because automatic reloading is configured",
},
}

for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {

t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, types.SystemReloadTypeManual)
if test.envSystemReload != "" {
t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, test.envSystemReload)
}
command := &CmdSystemStart{}
command.CobraCmd = common.ConfigureCobraCommand(common.PlatformLinux, common.SkupperCmdDescription{}, command, nil)
command.Namespace = test.namespace
Expand Down
10 changes: 10 additions & 0 deletions internal/cmd/skupper/system/nonkube/system_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package nonkube
import (
"errors"
"fmt"
"os"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/config"
"github.com/skupperproject/skupper/internal/nonkube/bootstrap"
"github.com/skupperproject/skupper/internal/utils"
"github.com/skupperproject/skupper/internal/utils/validator"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -34,6 +37,13 @@ func (cmd *CmdSystemStop) ValidateInput(args []string) error {
var validationErrors []error
namespaceStringValidator := validator.NamespaceStringValidator()

systemReloadType := utils.DefaultStr(os.Getenv(types.ENV_SYSTEM_AUTO_RELOAD),
types.SystemReloadTypeManual)

if systemReloadType == types.SystemReloadTypeAuto {
validationErrors = append(validationErrors, fmt.Errorf("this command is disabled because automatic reloading is configured"))
}

if len(args) > 0 {
validationErrors = append(validationErrors, fmt.Errorf("this command does not accept arguments"))
}
Expand Down
22 changes: 18 additions & 4 deletions internal/cmd/skupper/system/nonkube/system_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import (
"fmt"
"testing"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/testutils"
"gotest.tools/v3/assert"
)

func TestCmdSystemTearDown_ValidateInput(t *testing.T) {
type test struct {
name string
namespace string
args []string
expectedError string
name string
namespace string
args []string
envSystemReload string
expectedError string
}

testTable := []test{
Expand All @@ -28,11 +30,23 @@ func TestCmdSystemTearDown_ValidateInput(t *testing.T) {
namespace: "Invalid",
expectedError: "namespace is not valid: value does not match this regular expression: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$",
},
{
name: "command-is-disabled",
args: []string{},
namespace: "ns",
envSystemReload: types.SystemReloadTypeAuto,
expectedError: "this command is disabled because automatic reloading is configured",
},
}

for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {

t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, types.SystemReloadTypeManual)
if test.envSystemReload != "" {
t.Setenv(types.ENV_SYSTEM_AUTO_RELOAD, test.envSystemReload)
}

command := &CmdSystemStop{}
command.Namespace = test.namespace
command.CobraCmd = common.ConfigureCobraCommand(common.PlatformLinux, common.SkupperCmdDescription{}, command, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/kube/adaptor/config_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func syncConnectors(agent *qdr.Agent, desired *qdr.RouterConfig) error {

ignorePrefix := "auto-mesh"
if differences := qdr.ConnectorsDifference(actual, desired, &ignorePrefix); !differences.Empty() {
if err = agent.UpdateConnectorConfig(differences); err != nil {
if err = agent.UpdateConnectorConfig(differences, true); err != nil {
return fmt.Errorf("Error syncing connectors: %s", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/nonkube/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Bootstrap(config *Config) (*api.SiteState, error) {
if err != nil {
return nil, fmt.Errorf("failed to load site state: %v", err)
}
// if sources are being consume from namespace sources, they must be properly set
// if sources are being consumed from namespace sources, they must be properly set
crNamespace := siteState.GetNamespace()
targetNamespace := utils.DefaultStr(config.Namespace, "default")
if config.InputPath == sourcesPath {
Expand Down
3 changes: 3 additions & 0 deletions internal/nonkube/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/skupperproject/skupper/internal/nonkube/bootstrap/controller"
internalclient "github.com/skupperproject/skupper/internal/nonkube/client/compat"
"github.com/skupperproject/skupper/internal/nonkube/common"
"github.com/skupperproject/skupper/internal/utils"
"github.com/skupperproject/skupper/pkg/container"
"github.com/skupperproject/skupper/pkg/nonkube/api"
)
Expand Down Expand Up @@ -75,6 +76,8 @@ func Install(platform string) error {
"CONTAINER_ENDPOINT": config.containerEndpoint,
"SKUPPER_OUTPUT_PATH": config.hostDataHome,
"CONTAINER_ENGINE": config.containerEngine,
"SKUPPER_SYSTEM_RELOAD_TYPE": utils.DefaultStr(os.Getenv(types.ENV_SYSTEM_AUTO_RELOAD),
types.SystemReloadTypeManual),
}

//To mount a volume as a bind, the host path must be specified in the Name field
Expand Down
49 changes: 32 additions & 17 deletions internal/nonkube/bootstrap/teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,7 @@ func Teardown(namespace string) error {
if err != nil {
return err
}
if err := removeRouter(namespace, platform); err != nil {
return err
}

if err := removeService(namespace, platform); err != nil {
return err
}

if err := removeDefinition(namespace); err != nil {
return err
}

fmt.Printf("Namespace \"%s\" has been removed\n", namespace)
return nil
return RemoveAll(namespace, platform)

}

Expand All @@ -52,10 +39,19 @@ func removeDefinition(namespace string) error {
func removeRouter(namespace string, platform string) error {

endpoint := os.Getenv("CONTAINER_ENDPOINT")
if endpoint == "" {
endpoint = fmt.Sprintf("unix://%s/podman/podman.sock", api.GetRuntimeDir())

// the container endpoint is mapped to the podman socket inside the container
if api.IsRunningInContainer() {
endpoint = "unix:///var/run/podman.sock"
if platform == "docker" {
endpoint = "unix:///run/docker.sock"
endpoint = "unix:///var/run/docker.sock"
}
} else {
if endpoint == "" {
endpoint = fmt.Sprintf("unix://%s/podman/podman.sock", api.GetRuntimeDir())
if platform == "docker" {
endpoint = "unix:///run/docker.sock"
}
}
}

Expand Down Expand Up @@ -102,3 +98,22 @@ func removeService(namespace string, platform string) error {

return nil
}

func RemoveAll(namespace string, platform string) error {

if err := removeRouter(namespace, platform); err != nil {
return err
}

if err := removeService(namespace, platform); err != nil {
return err
}

if err := removeDefinition(namespace); err != nil {
return err
}

fmt.Printf("Namespace \"%s\" has been removed\n", namespace)
return nil

}
Loading