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

Pass server handler context to storage nodeGetter #69251

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/kubelet/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 8 additions & 7 deletions pkg/kubelet/client/kubelet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package client

import (
"context"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/kubelet/client/kubelet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave the assertion somewhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assertion is not valid nomore b/c the client doesn't receive ctx as parameter.


func TestMakeTransportInvalid(t *testing.T) {
config := &KubeletClientConfig{
EnableHttps: true,
Expand Down
1 change: 0 additions & 1 deletion pkg/registry/core/node/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions pkg/registry/core/node/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/core/node/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/core/pod/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/core/pod/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down