talos/cmd/installer/pkg/install/preflight_test.go
Robin Elfrink 7ce053638d
fix: ignore digest part of images when checking version
When using digests with images in machineconfig (e.g.
`repo/kubelet:v1.32.1@sha:...`) strip the digest part before checking
semantic version validity.

Signed-off-by: Robin Elfrink <robin@15augustus.nl>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-02-14 15:50:44 +04:00

43 lines
978 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package install_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/siderolabs/talos/cmd/installer/pkg/install"
)
func TestKubernetesVersionFromImageRef(t *testing.T) {
t.Parallel()
for _, test := range []struct {
imageRef string
expectedVersion string
}{
{
imageRef: "ghcr.io/siderolabs/kubelet:v1.32.2",
expectedVersion: "1.32.2",
},
{
imageRef: "ghcr.io/siderolabs/kubelet:v1.32.2@sha256:123456",
expectedVersion: "1.32.2",
},
} {
t.Run(test.imageRef, func(t *testing.T) {
t.Parallel()
version, err := install.KubernetesVersionFromImageRef(test.imageRef)
require.NoError(t, err)
assert.Equal(t, test.expectedVersion, version.String())
})
}
}