mirror of https://github.com/grafana/grafana.git
K8s: Fix the gitVersion response (required for kubectl) (#98571)
This commit is contained in:
parent
79d565f285
commit
b506fcb11c
|
@ -232,7 +232,22 @@ func SetupConfig(
|
||||||
serverConfig.BuildHandlerChainFunc = buildHandlerChainFunc
|
serverConfig.BuildHandlerChainFunc = buildHandlerChainFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
serverConfig.EffectiveVersion = utilversion.DefaultKubeEffectiveVersion()
|
v := utilversion.DefaultKubeEffectiveVersion()
|
||||||
|
patchver := 0 // required for semver
|
||||||
|
|
||||||
|
info := v.BinaryVersion().Info()
|
||||||
|
info.BuildDate = time.Unix(buildTimestamp, 0).UTC().Format(time.RFC3339)
|
||||||
|
info.GitVersion = fmt.Sprintf("%s.%s.%d+grafana-v%s", info.Major, info.Minor, patchver, buildVersion)
|
||||||
|
info.GitCommit = fmt.Sprintf("%s@%s", buildBranch, buildCommit)
|
||||||
|
info.GitTreeState = fmt.Sprintf("grafana v%s", buildVersion)
|
||||||
|
|
||||||
|
info2 := v.EmulationVersion().Info()
|
||||||
|
info2.BuildDate = info.BuildDate
|
||||||
|
info2.GitVersion = fmt.Sprintf("%s.%s.%d+grafana-v%s", info2.Major, info2.Minor, patchver, buildVersion)
|
||||||
|
info2.GitCommit = info.GitCommit
|
||||||
|
info2.GitTreeState = info.GitTreeState
|
||||||
|
|
||||||
|
serverConfig.EffectiveVersion = v
|
||||||
|
|
||||||
if err := AddPostStartHooks(serverConfig, builders); err != nil {
|
if err := AddPostStartHooks(serverConfig, builders); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -20,7 +20,9 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
|
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
|
||||||
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
|
@ -601,6 +603,31 @@ func (c *K8sTestHelper) NewDiscoveryClient() *discovery.DiscoveryClient {
|
||||||
return client
|
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 {
|
func (c *K8sTestHelper) GetGroupVersionInfoJSON(group string) string {
|
||||||
c.t.Helper()
|
c.t.Helper()
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,9 @@ func TestIntegrationPlaylist(t *testing.T) {
|
||||||
EnableFeatureToggles: []string{},
|
EnableFeatureToggles: []string{},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Ensure the k8s version is valid
|
||||||
|
_ = h.GetVersionInfo()
|
||||||
|
|
||||||
// The accepted verbs will change when dual write is enabled
|
// The accepted verbs will change when dual write is enabled
|
||||||
disco := h.GetGroupVersionInfoJSON("playlist.grafana.app")
|
disco := h.GetGroupVersionInfoJSON("playlist.grafana.app")
|
||||||
// fmt.Printf("%s", disco)
|
// fmt.Printf("%s", disco)
|
||||||
|
|
Loading…
Reference in New Issue