K8s: Fix the gitVersion response (required for kubectl) (#98571)

This commit is contained in:
Ryan McKinley
2025-01-07 11:43:19 +02:00
committed by GitHub
parent 79d565f285
commit b506fcb11c
3 changed files with 46 additions and 1 deletions
+27
View File
@@ -20,7 +20,9 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/version"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
apimachineryversion "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
@@ -601,6 +603,31 @@ func (c *K8sTestHelper) NewDiscoveryClient() *discovery.DiscoveryClient {
return client
}
func (c *K8sTestHelper) GetVersionInfo() apimachineryversion.Info {
c.t.Helper()
disco := c.NewDiscoveryClient()
req := disco.RESTClient().Get().
Prefix("version").
SetHeader("Accept", "application/json")
result := req.Do(context.Background())
require.NoError(c.t, result.Error())
raw, err := result.Raw()
require.NoError(c.t, err)
info := apimachineryversion.Info{}
err = json.Unmarshal(raw, &info)
require.NoError(c.t, err)
// Make sure the gitVersion is parsable
v, err := version.Parse(info.GitVersion)
require.NoError(c.t, err)
require.Equal(c.t, info.Major, fmt.Sprintf("%d", v.Major()))
require.Equal(c.t, info.Minor, fmt.Sprintf("%d", v.Minor()))
return info
}
func (c *K8sTestHelper) GetGroupVersionInfoJSON(group string) string {
c.t.Helper()
+3
View File
@@ -49,6 +49,9 @@ func TestIntegrationPlaylist(t *testing.T) {
EnableFeatureToggles: []string{},
}))
// Ensure the k8s version is valid
_ = h.GetVersionInfo()
// The accepted verbs will change when dual write is enabled
disco := h.GetGroupVersionInfoJSON("playlist.grafana.app")
// fmt.Printf("%s", disco)