Files
talos/internal/integration/k8s/version.go
Andrey Smirnov 63212ab17e test: fix integration test for k8s version
Push versions to constants, introduce 'platform' to version API to
discover node mode. Check kernel version for non-containers.

A bit of refactoring on version package to expose something closer to a
single response.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-11-11 13:42:21 -08:00

59 lines
1.9 KiB
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/.
// +build integration_k8s
package k8s
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/talos-systems/talos/internal/integration/base"
"github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/constants"
)
// VersionSuite verifies Talos version
type VersionSuite struct {
base.K8sSuite
}
// SuiteName ...
func (suite *VersionSuite) SuiteName() string {
return "k8s.VersionSuite"
}
// TestExpectedVersion verifies that node versions matches expected
func (suite *VersionSuite) TestExpectedVersion() {
v, err := suite.Client.Version(context.Background())
suite.Require().NoError(err)
checkKernelVersion := v.Response[0].Platform != nil && v.Response[0].Platform.Mode != runtime.Container.String()
nodes, err := suite.Clientset.CoreV1().Nodes().List(metav1.ListOptions{})
suite.Require().NoError(err)
expectedTalosVersion := fmt.Sprintf("Talos (%s)", suite.Version)
expectedContainerRuntimeVersion := fmt.Sprintf("containerd://%s", constants.DefaultContainerdVersion)
expectedKubeletVersion := fmt.Sprintf("v%s", constants.DefaultKubernetesVersion)
expectedKernelVersion := constants.DefaultKernelVersion
for _, node := range nodes.Items {
suite.Assert().Equal(expectedTalosVersion, node.Status.NodeInfo.OSImage)
suite.Assert().Equal("linux", node.Status.NodeInfo.OperatingSystem)
suite.Assert().Equal(expectedContainerRuntimeVersion, node.Status.NodeInfo.ContainerRuntimeVersion)
suite.Assert().Equal(expectedKubeletVersion, node.Status.NodeInfo.KubeletVersion)
if checkKernelVersion {
suite.Assert().Equal(expectedKernelVersion, node.Status.NodeInfo.KernelVersion)
}
}
}
func init() {
allSuites = append(allSuites, new(VersionSuite))
}