diff --git a/pkg/config/runtime.go b/pkg/config/runtime.go index 7bcfded69e9c..0f8ed1aef3da 100644 --- a/pkg/config/runtime.go +++ b/pkg/config/runtime.go @@ -17,13 +17,10 @@ limitations under the License. package config import ( - "bufio" - "bytes" "errors" "fmt" "os" "path/filepath" - "strings" "github.com/k0sproject/k0s/internal/pkg/dir" "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" @@ -68,12 +65,6 @@ func LoadRuntimeConfig(k0sVars *CfgVars) (*RuntimeConfigSpec, error) { return nil, err } - // "migrate" old runtime config to allow running commands on a new binary while an old version is still running. - // the legacy runtime config gets deleted when the server running on the old binary is stopped. - if isLegacy(content) { - return migrateLegacyRuntimeConfig(k0sVars, content) - } - config := &RuntimeConfig{} if err := yaml.Unmarshal(content, config); err != nil { return nil, err @@ -106,36 +97,6 @@ func LoadRuntimeConfig(k0sVars *CfgVars) (*RuntimeConfigSpec, error) { return spec, nil } -func migrateLegacyRuntimeConfig(k0sVars *CfgVars, content []byte) (*RuntimeConfigSpec, error) { - cfg := &v1beta1.ClusterConfig{} - - if err := yaml.Unmarshal(content, cfg); err != nil { - return nil, fmt.Errorf("failed to unmarshal legacy runtime config: %w", err) - } - - // generate a new runtime config - return &RuntimeConfigSpec{K0sVars: k0sVars, NodeConfig: cfg, Pid: os.Getpid()}, nil -} - -func isLegacy(data []byte) bool { - scanner := bufio.NewScanner(bytes.NewReader(data)) - - for scanner.Scan() { - line := scanner.Text() - - if strings.HasPrefix(line, "kind:") { - value := strings.TrimSpace(strings.TrimPrefix(line, "kind:")) - return value != RuntimeConfigKind - } - } - - if err := scanner.Err(); err != nil { - fmt.Fprintln(os.Stderr, "error scanning runtime config:", err) - } - - return false -} - func NewRuntimeConfig(k0sVars *CfgVars) (*RuntimeConfigSpec, error) { if _, err := LoadRuntimeConfig(k0sVars); err == nil { return nil, ErrK0sAlreadyRunning diff --git a/pkg/config/runtime_test.go b/pkg/config/runtime_test.go index 0e57882e5870..aaeda0c02fb4 100644 --- a/pkg/config/runtime_test.go +++ b/pkg/config/runtime_test.go @@ -24,38 +24,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestLoadRuntimeConfig_Legacy(t *testing.T) { - tmpfile, err := os.CreateTemp("", "runtime-config") - assert.NoError(t, err) - defer os.Remove(tmpfile.Name()) - - // prepare k0sVars - k0sVars := &CfgVars{ - DataDir: "/var/lib/k0s-custom", - RuntimeConfigPath: tmpfile.Name(), - } - - content := []byte(`apiVersion: k0s.k0sproject.io/v1beta1 -kind: ClusterConfig -metadata: - name: k0s -spec: - api: - address: 10.2.3.4 -`) - err = os.WriteFile(k0sVars.RuntimeConfigPath, content, 0644) - assert.NoError(t, err) - - spec, err := LoadRuntimeConfig(k0sVars) - assert.NoError(t, err) - assert.NotNil(t, spec) - assert.Equal(t, "/var/lib/k0s-custom", spec.K0sVars.DataDir) - assert.Equal(t, os.Getpid(), spec.Pid) - assert.NotNil(t, spec.NodeConfig) - assert.NotNil(t, spec.NodeConfig.Spec.API) - assert.Equal(t, "10.2.3.4", spec.NodeConfig.Spec.API.Address) -} - func TestLoadRuntimeConfig_K0sNotRunning(t *testing.T) { // create a temporary file for runtime config tmpfile, err := os.CreateTemp("", "runtime-config")