mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Fixed Golint errors in pkg/registry/core/pod
This commit is contained in:
parent
641321c94c
commit
026ba54961
@ -154,8 +154,6 @@ pkg/registry/core/namespace/storage
|
||||
pkg/registry/core/node
|
||||
pkg/registry/core/persistentvolume
|
||||
pkg/registry/core/persistentvolumeclaim
|
||||
pkg/registry/core/pod
|
||||
pkg/registry/core/pod/rest
|
||||
pkg/registry/core/replicationcontroller
|
||||
pkg/registry/core/replicationcontroller/storage
|
||||
pkg/registry/core/rest
|
||||
|
@ -27,11 +27,13 @@ import (
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
"k8s.io/kubernetes/pkg/apis/core/validation"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/kubelet/client"
|
||||
"k8s.io/kubernetes/pkg/registry/core/pod"
|
||||
|
||||
// ensure types are installed
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
)
|
||||
|
||||
// LogREST implements the log endpoint for a Pod
|
||||
@ -49,7 +51,7 @@ func (r *LogREST) New() runtime.Object {
|
||||
return &api.Pod{}
|
||||
}
|
||||
|
||||
// LogREST implements StorageMetadata
|
||||
// ProducesMIMETypes is LogREST's implementation of the StorageMetadata interface
|
||||
func (r *LogREST) ProducesMIMETypes(verb string) []string {
|
||||
// Since the default list does not include "plain/text", we need to
|
||||
// explicitly override ProducesMIMETypes, so that it gets added to
|
||||
@ -59,7 +61,7 @@ func (r *LogREST) ProducesMIMETypes(verb string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
// LogREST implements StorageMetadata, return string as the generating object
|
||||
// ProducesObject is LogREST's implementation of the StorageMetadata interface
|
||||
func (r *LogREST) ProducesObject(verb string) interface{} {
|
||||
return ""
|
||||
}
|
||||
@ -77,7 +79,7 @@ func (r *LogREST) Get(ctx context.Context, name string, opts runtime.Object) (ru
|
||||
if errs := validation.ValidatePodLogOptions(logOpts); len(errs) > 0 {
|
||||
return nil, errors.NewInvalid(api.Kind("PodLogOptions"), name, errs)
|
||||
}
|
||||
location, transport, err := pod.LogLocation(r.Store, r.KubeletConn, ctx, name, logOpts)
|
||||
location, transport, err := pod.LogLocation(ctx, r.Store, r.KubeletConn, name, logOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (r *ProxyREST) Connect(ctx context.Context, id string, opts runtime.Object,
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Invalid options object: %#v", opts)
|
||||
}
|
||||
location, transport, err := pod.ResourceLocation(r.Store, r.ProxyTransport, ctx, id)
|
||||
location, transport, err := pod.ResourceLocation(ctx, r.Store, r.ProxyTransport, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -99,7 +99,7 @@ func (r *AttachREST) Connect(ctx context.Context, name string, opts runtime.Obje
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Invalid options object: %#v", opts)
|
||||
}
|
||||
location, transport, err := pod.AttachLocation(r.Store, r.KubeletConn, ctx, name, attachOpts)
|
||||
location, transport, err := pod.AttachLocation(ctx, r.Store, r.KubeletConn, name, attachOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -136,7 +136,7 @@ func (r *ExecREST) Connect(ctx context.Context, name string, opts runtime.Object
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid options object: %#v", opts)
|
||||
}
|
||||
location, transport, err := pod.ExecLocation(r.Store, r.KubeletConn, ctx, name, execOpts)
|
||||
location, transport, err := pod.ExecLocation(ctx, r.Store, r.KubeletConn, name, execOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -184,7 +184,7 @@ func (r *PortForwardREST) Connect(ctx context.Context, name string, opts runtime
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid options object: %#v", opts)
|
||||
}
|
||||
location, transport, err := pod.PortForwardLocation(r.Store, r.KubeletConn, ctx, name, portForwardOpts)
|
||||
location, transport, err := pod.PortForwardLocation(ctx, r.Store, r.KubeletConn, name, portForwardOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ var _ = rest.Redirector(&REST{})
|
||||
|
||||
// ResourceLocation returns a pods location from its HostIP
|
||||
func (r *REST) ResourceLocation(ctx context.Context, name string) (*url.URL, http.RoundTripper, error) {
|
||||
return registrypod.ResourceLocation(r, r.proxyTransport, ctx, name)
|
||||
return registrypod.ResourceLocation(ctx, r, r.proxyTransport, name)
|
||||
}
|
||||
|
||||
// Implement ShortNamesProvider
|
||||
|
@ -147,6 +147,7 @@ type podStatusStrategy struct {
|
||||
podStrategy
|
||||
}
|
||||
|
||||
// StatusStrategy wraps and exports the used podStrategy for the storage package.
|
||||
var StatusStrategy = podStatusStrategy{Strategy}
|
||||
|
||||
func (podStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||
@ -168,6 +169,7 @@ type podEphemeralContainersStrategy struct {
|
||||
podStrategy
|
||||
}
|
||||
|
||||
// EphemeralContainersStrategy wraps and exports the used podStrategy for the storage package.
|
||||
var EphemeralContainersStrategy = podEphemeralContainersStrategy{Strategy}
|
||||
|
||||
func (podEphemeralContainersStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
|
||||
@ -180,7 +182,7 @@ func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("not a pod")
|
||||
}
|
||||
return labels.Set(pod.ObjectMeta.Labels), PodToSelectableFields(pod), nil
|
||||
return labels.Set(pod.ObjectMeta.Labels), ToSelectableFields(pod), nil
|
||||
}
|
||||
|
||||
// MatchPod returns a generic matcher for a given label and field selector.
|
||||
@ -198,9 +200,9 @@ func NodeNameTriggerFunc(obj runtime.Object) string {
|
||||
return obj.(*api.Pod).Spec.NodeName
|
||||
}
|
||||
|
||||
// PodToSelectableFields returns a field set that represents the object
|
||||
// ToSelectableFields returns a field set that represents the object
|
||||
// TODO: fields are not labels, and the validation rules for them do not apply.
|
||||
func PodToSelectableFields(pod *api.Pod) fields.Set {
|
||||
func ToSelectableFields(pod *api.Pod) fields.Set {
|
||||
// The purpose of allocation with a given number of elements is to reduce
|
||||
// amount of allocations needed to create the fields.Set. If you add any
|
||||
// field here or the number of object-meta related fields changes, this should
|
||||
@ -226,7 +228,7 @@ type ResourceGetter interface {
|
||||
Get(context.Context, string, *metav1.GetOptions) (runtime.Object, error)
|
||||
}
|
||||
|
||||
func getPod(getter ResourceGetter, ctx context.Context, name string) (*api.Pod, error) {
|
||||
func getPod(ctx context.Context, getter ResourceGetter, name string) (*api.Pod, error) {
|
||||
obj, err := getter.Get(ctx, name, &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -251,7 +253,7 @@ func getPodIP(pod *api.Pod) string {
|
||||
}
|
||||
|
||||
// ResourceLocation returns a URL to which one can send traffic for the specified pod.
|
||||
func ResourceLocation(getter ResourceGetter, rt http.RoundTripper, ctx context.Context, id string) (*url.URL, http.RoundTripper, error) {
|
||||
func ResourceLocation(ctx context.Context, getter ResourceGetter, rt http.RoundTripper, id string) (*url.URL, http.RoundTripper, error) {
|
||||
// Allow ID as "podname" or "podname:port" or "scheme:podname:port".
|
||||
// If port is not specified, try to use the first defined port on the pod.
|
||||
scheme, name, port, valid := utilnet.SplitSchemeNamePort(id)
|
||||
@ -259,7 +261,7 @@ func ResourceLocation(getter ResourceGetter, rt http.RoundTripper, ctx context.C
|
||||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid pod request %q", id))
|
||||
}
|
||||
|
||||
pod, err := getPod(getter, ctx, name)
|
||||
pod, err := getPod(ctx, getter, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -301,13 +303,12 @@ func getContainerNames(containers []api.Container) string {
|
||||
// LogLocation returns the log URL for a pod container. If opts.Container is blank
|
||||
// and only one container is present in the pod, that container is used.
|
||||
func LogLocation(
|
||||
getter ResourceGetter,
|
||||
ctx context.Context, getter ResourceGetter,
|
||||
connInfo client.ConnectionInfoGetter,
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts *api.PodLogOptions,
|
||||
) (*url.URL, http.RoundTripper, error) {
|
||||
pod, err := getPod(getter, ctx, name)
|
||||
pod, err := getPod(ctx, getter, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -423,37 +424,37 @@ func streamParams(params url.Values, opts runtime.Object) error {
|
||||
// AttachLocation returns the attach URL for a pod container. If opts.Container is blank
|
||||
// and only one container is present in the pod, that container is used.
|
||||
func AttachLocation(
|
||||
ctx context.Context,
|
||||
getter ResourceGetter,
|
||||
connInfo client.ConnectionInfoGetter,
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts *api.PodAttachOptions,
|
||||
) (*url.URL, http.RoundTripper, error) {
|
||||
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "attach")
|
||||
return streamLocation(ctx, getter, connInfo, name, opts, opts.Container, "attach")
|
||||
}
|
||||
|
||||
// ExecLocation returns the exec URL for a pod container. If opts.Container is blank
|
||||
// and only one container is present in the pod, that container is used.
|
||||
func ExecLocation(
|
||||
ctx context.Context,
|
||||
getter ResourceGetter,
|
||||
connInfo client.ConnectionInfoGetter,
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts *api.PodExecOptions,
|
||||
) (*url.URL, http.RoundTripper, error) {
|
||||
return streamLocation(getter, connInfo, ctx, name, opts, opts.Container, "exec")
|
||||
return streamLocation(ctx, getter, connInfo, name, opts, opts.Container, "exec")
|
||||
}
|
||||
|
||||
func streamLocation(
|
||||
ctx context.Context,
|
||||
getter ResourceGetter,
|
||||
connInfo client.ConnectionInfoGetter,
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts runtime.Object,
|
||||
container,
|
||||
path string,
|
||||
) (*url.URL, http.RoundTripper, error) {
|
||||
pod, err := getPod(getter, ctx, name)
|
||||
pod, err := getPod(ctx, getter, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -489,13 +490,13 @@ func streamLocation(
|
||||
|
||||
// PortForwardLocation returns the port-forward URL for a pod.
|
||||
func PortForwardLocation(
|
||||
ctx context.Context,
|
||||
getter ResourceGetter,
|
||||
connInfo client.ConnectionInfoGetter,
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts *api.PodPortForwardOptions,
|
||||
) (*url.URL, http.RoundTripper, error) {
|
||||
pod, err := getPod(getter, ctx, name)
|
||||
pod, err := getPod(ctx, getter, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ func TestCheckLogLocation(t *testing.T) {
|
||||
InsecureSkipTLSVerifyTransport: fakeInsecureRoundTripper,
|
||||
}}
|
||||
|
||||
_, actualTransport, err := LogLocation(getter, connectionGetter, ctx, fakePodName, tc.opts)
|
||||
_, actualTransport, err := LogLocation(ctx, getter, connectionGetter, fakePodName, tc.opts)
|
||||
if !reflect.DeepEqual(err, tc.expectedErr) {
|
||||
t.Errorf("expected %v, got %v", tc.expectedErr, err)
|
||||
}
|
||||
@ -469,7 +469,7 @@ func TestSelectableFieldLabelConversions(t *testing.T) {
|
||||
apitesting.TestSelectableFieldLabelConversionsOfKind(t,
|
||||
"v1",
|
||||
"Pod",
|
||||
PodToSelectableFields(&api.Pod{}),
|
||||
ToSelectableFields(&api.Pod{}),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
@ -530,7 +530,7 @@ func TestPortForwardLocation(t *testing.T) {
|
||||
for _, tc := range tcs {
|
||||
getter := &mockPodGetter{tc.in}
|
||||
connectionGetter := &mockConnectionInfoGetter{tc.info}
|
||||
loc, _, err := PortForwardLocation(getter, connectionGetter, ctx, "test", tc.opts)
|
||||
loc, _, err := PortForwardLocation(ctx, getter, connectionGetter, "test", tc.opts)
|
||||
if !reflect.DeepEqual(err, tc.expectedErr) {
|
||||
t.Errorf("expected %v, got %v", tc.expectedErr, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user