Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed k8s client unit test panic #678

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package k8s

import (
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client/config"

Expand Down Expand Up @@ -43,14 +42,11 @@ var GetClientSetWrapper = func() (kubernetes.Interface, error) {

// GetKubeAPIServerVersion returns version of the k8s/openshift cluster
func GetKubeAPIServerVersion() (*version.Info, error) {
// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
// Create the discoveryClient
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
k8sClientSet, err := GetClientSetWrapper()
if err != nil {
return nil, err
}
sv, err := discoveryClient.ServerVersion()
sv, err := k8sClientSet.Discovery().ServerVersion()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions k8s/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package k8s

import (
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -166,7 +165,8 @@ func Test_GetVersion(t *testing.T) {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, out, fmt.Sprintf("%s.%s", major, minor))
assert.Equal(t, major, out.Major)
assert.Equal(t, minor, out.Minor)
}
})
}
Expand Down
Loading