mirror of https://github.com/k3s-io/k3s
pass handler ctx to node rest nodegetter
parent
b442c25325
commit
3370907fe5
|
@ -26,10 +26,7 @@ go_test(
|
|||
srcs = ["kubelet_client_test.go"],
|
||||
data = ["//pkg/client/testdata"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||
],
|
||||
deps = ["//staging/src/k8s.io/client-go/rest:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -62,7 +63,7 @@ type ConnectionInfo struct {
|
|||
|
||||
// ConnectionInfoGetter provides ConnectionInfo for the kubelet running on a named node
|
||||
type ConnectionInfoGetter interface {
|
||||
GetConnectionInfo(nodeName types.NodeName) (*ConnectionInfo, error)
|
||||
GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error)
|
||||
}
|
||||
|
||||
func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {
|
||||
|
@ -103,14 +104,14 @@ func (c *KubeletClientConfig) transportConfig() *transport.Config {
|
|||
|
||||
// NodeGetter defines an interface for looking up a node by name
|
||||
type NodeGetter interface {
|
||||
Get(name string, options metav1.GetOptions) (*v1.Node, error)
|
||||
Get(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error)
|
||||
}
|
||||
|
||||
// NodeGetterFunc allows implementing NodeGetter with a function
|
||||
type NodeGetterFunc func(name string, options metav1.GetOptions) (*v1.Node, error)
|
||||
type NodeGetterFunc func(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error)
|
||||
|
||||
func (f NodeGetterFunc) Get(name string, options metav1.GetOptions) (*v1.Node, error) {
|
||||
return f(name, options)
|
||||
func (f NodeGetterFunc) Get(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error) {
|
||||
return f(ctx, name, options)
|
||||
}
|
||||
|
||||
// NodeConnectionInfoGetter obtains connection info from the status of a Node API object
|
||||
|
@ -153,8 +154,8 @@ func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (k *NodeConnectionInfoGetter) GetConnectionInfo(nodeName types.NodeName) (*ConnectionInfo, error) {
|
||||
node, err := k.nodes.Get(string(nodeName), metav1.GetOptions{})
|
||||
func (k *NodeConnectionInfoGetter) GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error) {
|
||||
node, err := k.nodes.Get(ctx, string(nodeName), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -19,14 +19,9 @@ package client
|
|||
import (
|
||||
"testing"
|
||||
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// Ensure a node client can be used as a NodeGetter.
|
||||
// This allows anyone with a node client to easily construct a NewNodeConnectionInfoGetter.
|
||||
var _ = NodeGetter(v1core.NodeInterface(nil))
|
||||
|
||||
func TestMakeTransportInvalid(t *testing.T) {
|
||||
config := &KubeletClientConfig{
|
||||
EnableHttps: true,
|
||||
|
|
|
@ -41,7 +41,6 @@ go_library(
|
|||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library",
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
@ -104,8 +103,8 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, kubeletClientConfig client
|
|||
proxyREST := &noderest.ProxyREST{Store: store, ProxyTransport: proxyTransport}
|
||||
|
||||
// Build a NodeGetter that looks up nodes using the REST handler
|
||||
nodeGetter := client.NodeGetterFunc(func(nodeName string, options metav1.GetOptions) (*v1.Node, error) {
|
||||
obj, err := nodeREST.Get(genericapirequest.NewContext(), nodeName, &options)
|
||||
nodeGetter := client.NodeGetterFunc(func(ctx context.Context, nodeName string, options metav1.GetOptions) (*v1.Node, error) {
|
||||
obj, err := nodeREST.Get(ctx, nodeName, &options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
|
|||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid node request %q", id))
|
||||
}
|
||||
|
||||
info, err := connection.GetConnectionInfo(types.NodeName(name))
|
||||
info, err := connection.GetConnectionInfo(ctx, types.NodeName(name))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -352,7 +352,7 @@ func LogLocation(
|
|||
// If pod has not been assigned a host, return an empty location
|
||||
return nil, nil, nil
|
||||
}
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(nodeName)
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(ctx, nodeName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ func streamLocation(
|
|||
// If pod has not been assigned a host, return an empty location
|
||||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("pod %s does not have a host assigned", name))
|
||||
}
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(nodeName)
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(ctx, nodeName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ func PortForwardLocation(
|
|||
// If pod has not been assigned a host, return an empty location
|
||||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("pod %s does not have a host assigned", name))
|
||||
}
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(nodeName)
|
||||
nodeInfo, err := connInfo.GetConnectionInfo(ctx, nodeName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -395,7 +395,7 @@ type mockConnectionInfoGetter struct {
|
|||
info *client.ConnectionInfo
|
||||
}
|
||||
|
||||
func (g mockConnectionInfoGetter) GetConnectionInfo(nodeName types.NodeName) (*client.ConnectionInfo, error) {
|
||||
func (g mockConnectionInfoGetter) GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*client.ConnectionInfo, error) {
|
||||
return g.info, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue