Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the configured platform #1876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions internal/cmd/skupper/system/nonkube/system_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package nonkube

import (
"fmt"
"os"
"testing"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/utils"
"github.com/skupperproject/skupper/internal/config"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/skupperproject/skupper/pkg/nonkube/bootstrap"
"gotest.tools/v3/assert"
"os"
"testing"
)

func TestCmdSystemReload_ValidateInput(t *testing.T) {
Expand Down Expand Up @@ -70,6 +72,7 @@ func TestCmdSystemReload_InputToOptions(t *testing.T) {
for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {
os.Setenv(types.ENV_PLATFORM, test.platform)
config.ClearPlatform()

cmd := newCmdSystemReloadWithMocks(false, false)
cmd.Namespace = test.namespace
Expand Down
9 changes: 6 additions & 3 deletions internal/cmd/skupper/system/nonkube/system_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package nonkube

import (
"fmt"
"os"
"strings"
"testing"

"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/utils"
"github.com/skupperproject/skupper/internal/config"
"github.com/skupperproject/skupper/pkg/nonkube/api"
"github.com/skupperproject/skupper/pkg/nonkube/bootstrap"
"gotest.tools/v3/assert"
"os"
"strings"
"testing"
)

func TestCmdSystemSetup_ValidateInput(t *testing.T) {
Expand Down Expand Up @@ -113,6 +115,7 @@ func TestCmdSystemSetup_InputToOptions(t *testing.T) {
for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {
os.Setenv(types.ENV_PLATFORM, test.platform)
config.ClearPlatform()

cmd := newCmdSystemSetupWithMocks(false, false)
cmd.Flags = &test.flags
Expand Down
21 changes: 16 additions & 5 deletions internal/config/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/pkg/utils"
"gopkg.in/yaml.v3"
"k8s.io/utils/ptr"
)

type PlatformInfo struct {
Expand Down Expand Up @@ -131,9 +132,14 @@ var (
)

var (
Platform string
Platform string
configuredPlatform *types.Platform
)

func ClearPlatform() {
configuredPlatform = nil
}

// GetPlatform returns the runtime platform defined,
// where the lookup goes through the following sequence:
// - Platform variable,
Expand All @@ -143,6 +149,10 @@ var (
// In case the defined platform is invalid, "kubernetes"
// will be returned.
func GetPlatform() types.Platform {
if configuredPlatform != nil {
return *configuredPlatform
}

p := &PlatformInfo{}
var platform types.Platform
_ = p.Load()
Expand All @@ -165,14 +175,15 @@ func GetPlatform() types.Platform {
}
switch platform {
case types.PlatformPodman:
return types.PlatformPodman
configuredPlatform = &platform
case types.PlatformDocker:
return types.PlatformDocker
configuredPlatform = &platform
case types.PlatformSystemd:
return types.PlatformSystemd
configuredPlatform = &platform
default:
return types.PlatformKubernetes
configuredPlatform = ptr.To(types.PlatformKubernetes)
}
return *configuredPlatform
}

func getDataHome() string {
Expand Down
1 change: 1 addition & 0 deletions pkg/nonkube/api/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func TestGetPlatform(t *testing.T) {
assert.Assert(t, info.Update(tt.cfgVal), "error setting platform in %s", f.Name())
}

config.ClearPlatform()
got := config.GetPlatform()

// removing temporary file
Expand Down