2022-10-06 06:58:56 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package versions
|
|
|
|
|
|
|
|
import (
|
2023-12-14 08:51:10 -05:00
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
"strings"
|
2022-10-06 06:58:56 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-12-14 08:51:10 -05:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/vincent-petithory/dataurl"
|
2022-10-06 06:58:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionFromDockerImage(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
imageName string
|
|
|
|
wantVersion string
|
|
|
|
wantPanic bool
|
|
|
|
}{
|
|
|
|
"valid image name": {
|
2022-12-12 05:35:12 -05:00
|
|
|
imageName: "registry.test.foo/kube-apiserver:v1.18.0",
|
2022-10-06 06:58:56 -04:00
|
|
|
wantVersion: "v1.18.0",
|
|
|
|
},
|
|
|
|
"valid image name with sha": {
|
2022-12-12 05:35:12 -05:00
|
|
|
imageName: "registry.test.foo/kube-apiserver:v1.18.0@sha256:1234567890abcdef",
|
2022-10-06 06:58:56 -04:00
|
|
|
wantVersion: "v1.18.0",
|
|
|
|
},
|
|
|
|
"invalid image name": {
|
2022-12-12 05:35:12 -05:00
|
|
|
imageName: "registry.test.foo/kube-apiserver",
|
2022-10-06 06:58:56 -04:00
|
|
|
wantPanic: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
if tc.wantPanic {
|
|
|
|
assert.Panics(func() { versionFromDockerImage(tc.imageName) })
|
|
|
|
} else {
|
|
|
|
assert.Equal(tc.wantVersion, versionFromDockerImage(tc.imageName))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-12-14 08:51:10 -05:00
|
|
|
|
|
|
|
func TestKubernetesImagePatchCompatibility(t *testing.T) {
|
|
|
|
// This test ensures that pinned Kubernetes images correspond to the
|
2023-12-21 14:56:55 -05:00
|
|
|
// supported Kubernetes versions.
|
2023-12-14 08:51:10 -05:00
|
|
|
for v, clusterConfig := range VersionConfigs {
|
|
|
|
t.Run(string(v), func(t *testing.T) {
|
|
|
|
for i, component := range clusterConfig.KubernetesComponents.GetUpgradableComponents() {
|
|
|
|
if !strings.HasPrefix(component.Url, "data:") {
|
2023-12-21 14:56:55 -05:00
|
|
|
// This test only applies to kubeadm patches.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.Contains(component.InstallPath, "/etcd") {
|
|
|
|
// The etcd version is not derived from the Kubernetes version
|
2023-12-14 08:51:10 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
t.Run(fmt.Sprintf("%d-%s", i, path.Base(component.InstallPath)), func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
dataURL, err := dataurl.DecodeString(component.Url)
|
|
|
|
require.NoError(err)
|
|
|
|
require.Contains(string(dataURL.Data), clusterConfig.ClusterVersion)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|