mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #114632 from neolit123/1.27-fix-dry-run-server-version
kubeadm: handle dry run GET actions from fake discovery
This commit is contained in:
commit
a6d66d15f6
@ -119,8 +119,16 @@ func NewDryRunClientWithOpts(opts DryRunClientOptions) clientset.Interface {
|
||||
Reaction: func(action core.Action) (bool, runtime.Object, error) {
|
||||
getAction, ok := action.(core.GetAction)
|
||||
if !ok {
|
||||
// something's wrong, we can't handle this event
|
||||
return true, nil, errors.New("can't cast get reactor event action object to GetAction interface")
|
||||
// If the GetAction cast fails, this could be an ActionImpl with a "get" verb.
|
||||
// Such actions could be invoked from any of the fake discovery calls, such as ServerVersion().
|
||||
// Attempt the cast to ActionImpl and construct a GetActionImpl from it.
|
||||
actionImpl, ok := action.(core.ActionImpl)
|
||||
if ok {
|
||||
getAction = core.GetActionImpl{ActionImpl: actionImpl}
|
||||
} else {
|
||||
// something's wrong, we can't handle this event
|
||||
return true, nil, errors.New("can't cast get reactor event action object to GetAction interface")
|
||||
}
|
||||
}
|
||||
handled, obj, err := opts.Getter.HandleGetAction(getAction)
|
||||
|
||||
|
@ -18,12 +18,15 @@ package apiclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
rbac "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
pkgversion "k8s.io/apimachinery/pkg/version"
|
||||
fakediscovery "k8s.io/client-go/discovery/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
@ -109,3 +112,24 @@ func TestLogDryRunAction(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryServerVersion(t *testing.T) {
|
||||
dryRunGetter := &InitDryRunGetter{
|
||||
controlPlaneName: "controlPlane",
|
||||
serviceSubnet: "serviceSubnet",
|
||||
}
|
||||
c := NewDryRunClient(dryRunGetter, io.Discard)
|
||||
fakeclientDiscovery, ok := c.Discovery().(*fakediscovery.FakeDiscovery)
|
||||
if !ok {
|
||||
t.Fatal("could not obtain FakeDiscovery from dry run client")
|
||||
}
|
||||
const gitVersion = "foo"
|
||||
fakeclientDiscovery.FakedServerVersion = &pkgversion.Info{GitVersion: gitVersion}
|
||||
ver, err := c.Discovery().ServerVersion()
|
||||
if err != nil {
|
||||
t.Fatalf("Get ServerVersion failed.: %v", err)
|
||||
}
|
||||
if ver.GitVersion != gitVersion {
|
||||
t.Fatalf("GitVersion did not match, expected %s, got %s", gitVersion, ver.GitVersion)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user