diff --git a/hack/update-generated-pod-resources-dockerized.sh b/hack/update-generated-pod-resources-dockerized.sh index fc4ff8d5a97..98955cc382b 100755 --- a/hack/update-generated-pod-resources-dockerized.sh +++ b/hack/update-generated-pod-resources-dockerized.sh @@ -16,14 +16,14 @@ # This script generates `*/api.pb.go` from the protobuf file `*/api.proto`. # Example: -# kube::protoc::generate_proto "${POD_RESOURCES_ALPHA}" +# kube::protoc::generate_proto "${POD_RESOURCES}" set -o errexit set -o nounset set -o pipefail KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" -POD_RESOURCES_ALPHA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/" +POD_RESOURCES="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/" source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::protoc::generate_proto "${POD_RESOURCES_ALPHA}" +kube::protoc::generate_proto "${POD_RESOURCES}" diff --git a/hack/update-generated-pod-resources.sh b/hack/update-generated-pod-resources.sh index 5c295062d88..c51a156064d 100755 --- a/hack/update-generated-pod-resources.sh +++ b/hack/update-generated-pod-resources.sh @@ -14,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script generates `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.pb.go` -# from the protobuf file `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto` +# This script generates `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.pb.go` +# from the protobuf file `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto` # for pods. # Usage: `hack/update-generated-pod-resources.sh`. diff --git a/hack/verify-generated-pod-resources.sh b/hack/verify-generated-pod-resources.sh index eddfd9316b2..46e7442964f 100755 --- a/hack/verify-generated-pod-resources.sh +++ b/hack/verify-generated-pod-resources.sh @@ -24,26 +24,26 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -POD_RESOURCES_ALPHA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/" +POD_RESOURCES="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/" source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env function cleanup { - rm -rf "${POD_RESOURCES_ALPHA}/_tmp/" + rm -rf "${POD_RESOURCES}/_tmp/" } trap cleanup EXIT -mkdir -p "${POD_RESOURCES_ALPHA}/_tmp" -cp "${POD_RESOURCES_ALPHA}/api.pb.go" "${POD_RESOURCES_ALPHA}/_tmp/" +mkdir -p "${POD_RESOURCES}/_tmp" +cp "${POD_RESOURCES}/api.pb.go" "${POD_RESOURCES}/_tmp/" ret=0 KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-pod-resources.sh" -diff -I "gzipped FileDescriptorProto" -I "0x" -Naupr "${POD_RESOURCES_ALPHA}/_tmp/api.pb.go" "${POD_RESOURCES_ALPHA}/api.pb.go" || ret=$? +diff -I "gzipped FileDescriptorProto" -I "0x" -Naupr "${POD_RESOURCES}/_tmp/api.pb.go" "${POD_RESOURCES}/api.pb.go" || ret=$? if [[ $ret -eq 0 ]]; then echo "Generated pod resources api is up to date." - cp "${POD_RESOURCES_ALPHA}/_tmp/api.pb.go" "${POD_RESOURCES_ALPHA}/" + cp "${POD_RESOURCES}/_tmp/api.pb.go" "${POD_RESOURCES}/" else echo "Generated pod resources api is out of date. Please run hack/update-generated-pod-resources.sh" exit 1 diff --git a/pkg/kubelet/apis/podresources/BUILD b/pkg/kubelet/apis/podresources/BUILD index a8c0bf9981a..3a64e413dff 100644 --- a/pkg/kubelet/apis/podresources/BUILD +++ b/pkg/kubelet/apis/podresources/BUILD @@ -5,13 +5,17 @@ go_library( srcs = [ "client.go", "constants.go", - "server.go", + "server_v1.go", + "server_v1alpha1.go", + "types.go", ], importpath = "k8s.io/kubernetes/pkg/kubelet/apis/podresources", visibility = ["//visibility:public"], deps = [ + "//pkg/kubelet/metrics:go_default_library", "//pkg/kubelet/util:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:go_default_library", "//vendor/google.golang.org/grpc:go_default_library", ], @@ -19,12 +23,16 @@ go_library( go_test( name = "go_default_test", - srcs = ["server_test.go"], + srcs = [ + "server_v1_test.go", + "server_v1alpha1_test.go", + ], embed = [":go_default_library"], deps = [ "//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/types:go_default_library", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:go_default_library", "//vendor/github.com/stretchr/testify/mock:go_default_library", ], diff --git a/pkg/kubelet/apis/podresources/client.go b/pkg/kubelet/apis/podresources/client.go index 2e871137a51..2d27c623e0c 100644 --- a/pkg/kubelet/apis/podresources/client.go +++ b/pkg/kubelet/apis/podresources/client.go @@ -23,12 +23,17 @@ import ( "google.golang.org/grpc" - podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" + "k8s.io/kubelet/pkg/apis/podresources/v1" + "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" "k8s.io/kubernetes/pkg/kubelet/util" ) -// GetClient returns a client for the PodResourcesLister grpc service -func GetClient(socket string, connectionTimeout time.Duration, maxMsgSize int) (podresourcesapi.PodResourcesListerClient, *grpc.ClientConn, error) { +// Note: Consumers of the pod resources API should not be importing this package. +// They should copy paste the function in their project. + +// GetV1alpha1Client returns a client for the PodResourcesLister grpc service +// Note: This is deprecated +func GetV1alpha1Client(socket string, connectionTimeout time.Duration, maxMsgSize int) (v1alpha1.PodResourcesListerClient, *grpc.ClientConn, error) { addr, dialer, err := util.GetAddressAndDialer(socket) if err != nil { return nil, nil, err @@ -40,5 +45,21 @@ func GetClient(socket string, connectionTimeout time.Duration, maxMsgSize int) ( if err != nil { return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err) } - return podresourcesapi.NewPodResourcesListerClient(conn), conn, nil + return v1alpha1.NewPodResourcesListerClient(conn), conn, nil +} + +// GetV1Client returns a client for the PodResourcesLister grpc service +func GetV1Client(socket string, connectionTimeout time.Duration, maxMsgSize int) (v1.PodResourcesListerClient, *grpc.ClientConn, error) { + addr, dialer, err := util.GetAddressAndDialer(socket) + if err != nil { + return nil, nil, err + } + ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) + defer cancel() + + conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) + if err != nil { + return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err) + } + return v1.NewPodResourcesListerClient(conn), conn, nil } diff --git a/pkg/kubelet/apis/podresources/server_v1.go b/pkg/kubelet/apis/podresources/server_v1.go new file mode 100644 index 00000000000..20a6abb8ec5 --- /dev/null +++ b/pkg/kubelet/apis/podresources/server_v1.go @@ -0,0 +1,80 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package podresources + +import ( + "context" + + "k8s.io/kubernetes/pkg/kubelet/metrics" + + "k8s.io/kubelet/pkg/apis/podresources/v1" + "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" +) + +// podResourcesServerV1alpha1 implements PodResourcesListerServer +type v1PodResourcesServer struct { + podsProvider PodsProvider + devicesProvider DevicesProvider +} + +// NewV1PodResourcesServer returns a PodResourcesListerServer which lists pods provided by the PodsProvider +// with device information provided by the DevicesProvider +func NewV1PodResourcesServer(podsProvider PodsProvider, devicesProvider DevicesProvider) v1.PodResourcesListerServer { + return &v1PodResourcesServer{ + podsProvider: podsProvider, + devicesProvider: devicesProvider, + } +} + +func alphaDevicesToV1(alphaDevs []*v1alpha1.ContainerDevices) []*v1.ContainerDevices { + var devs []*v1.ContainerDevices + for _, alphaDev := range alphaDevs { + dev := v1.ContainerDevices(*alphaDev) + devs = append(devs, &dev) + } + + return devs +} + +// List returns information about the resources assigned to pods on the node +func (p *v1PodResourcesServer) List(ctx context.Context, req *v1.ListPodResourcesRequest) (*v1.ListPodResourcesResponse, error) { + metrics.PodResourcesEndpointRequestsTotalCount.WithLabelValues("v1").Inc() + + pods := p.podsProvider.GetPods() + podResources := make([]*v1.PodResources, len(pods)) + p.devicesProvider.UpdateAllocatedDevices() + + for i, pod := range pods { + pRes := v1.PodResources{ + Name: pod.Name, + Namespace: pod.Namespace, + Containers: make([]*v1.ContainerResources, len(pod.Spec.Containers)), + } + + for j, container := range pod.Spec.Containers { + pRes.Containers[j] = &v1.ContainerResources{ + Name: container.Name, + Devices: alphaDevicesToV1(p.devicesProvider.GetDevices(string(pod.UID), container.Name)), + } + } + podResources[i] = &pRes + } + + return &v1.ListPodResourcesResponse{ + PodResources: podResources, + }, nil +} diff --git a/pkg/kubelet/apis/podresources/server_v1_test.go b/pkg/kubelet/apis/podresources/server_v1_test.go new file mode 100644 index 00000000000..c0d1dfba68b --- /dev/null +++ b/pkg/kubelet/apis/podresources/server_v1_test.go @@ -0,0 +1,139 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package podresources + +import ( + "context" + "testing" + + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1" + "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" +) + +func TestListPodResourcesV1(t *testing.T) { + podName := "pod-name" + podNamespace := "pod-namespace" + podUID := types.UID("pod-uid") + containerName := "container-name" + + devs := []*v1alpha1.ContainerDevices{ + { + ResourceName: "resource", + DeviceIds: []string{"dev0", "dev1"}, + }, + } + + for _, tc := range []struct { + desc string + pods []*v1.Pod + devices []*v1alpha1.ContainerDevices + expectedResponse *podresourcesapi.ListPodResourcesResponse + }{ + { + desc: "no pods", + pods: []*v1.Pod{}, + devices: []*v1alpha1.ContainerDevices{}, + expectedResponse: &podresourcesapi.ListPodResourcesResponse{}, + }, + { + desc: "pod without devices", + pods: []*v1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + Namespace: podNamespace, + UID: podUID, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: containerName, + }, + }, + }, + }, + }, + devices: []*v1alpha1.ContainerDevices{}, + expectedResponse: &podresourcesapi.ListPodResourcesResponse{ + PodResources: []*podresourcesapi.PodResources{ + { + Name: podName, + Namespace: podNamespace, + Containers: []*podresourcesapi.ContainerResources{ + { + Name: containerName, + Devices: []*podresourcesapi.ContainerDevices{}, + }, + }, + }, + }, + }, + }, + { + desc: "pod with devices", + pods: []*v1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + Namespace: podNamespace, + UID: podUID, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: containerName, + }, + }, + }, + }, + }, + devices: devs, + expectedResponse: &podresourcesapi.ListPodResourcesResponse{ + PodResources: []*podresourcesapi.PodResources{ + { + Name: podName, + Namespace: podNamespace, + Containers: []*podresourcesapi.ContainerResources{ + { + Name: containerName, + Devices: alphaDevicesToV1(devs), + }, + }, + }, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + m := new(mockProvider) + m.On("GetPods").Return(tc.pods) + m.On("GetDevices", string(podUID), containerName).Return(tc.devices) + m.On("UpdateAllocatedDevices").Return() + server := NewV1PodResourcesServer(m, m) + resp, err := server.List(context.TODO(), &podresourcesapi.ListPodResourcesRequest{}) + if err != nil { + t.Errorf("want err = %v, got %q", nil, err) + } + if tc.expectedResponse.String() != resp.String() { + t.Errorf("want resp = %s, got %s", tc.expectedResponse.String(), resp.String()) + } + }) + } +} diff --git a/pkg/kubelet/apis/podresources/server.go b/pkg/kubelet/apis/podresources/server_v1alpha1.go similarity index 65% rename from pkg/kubelet/apis/podresources/server.go rename to pkg/kubelet/apis/podresources/server_v1alpha1.go index 752d64c344f..4d4cb7ca5cb 100644 --- a/pkg/kubelet/apis/podresources/server.go +++ b/pkg/kubelet/apis/podresources/server_v1alpha1.go @@ -19,38 +19,29 @@ package podresources import ( "context" - "k8s.io/api/core/v1" + "k8s.io/kubernetes/pkg/kubelet/metrics" + "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" ) -// DevicesProvider knows how to provide the devices used by the given container -type DevicesProvider interface { - GetDevices(podUID, containerName string) []*v1alpha1.ContainerDevices - UpdateAllocatedDevices() -} - -// PodsProvider knows how to provide the pods admitted by the node -type PodsProvider interface { - GetPods() []*v1.Pod -} - -// podResourcesServer implements PodResourcesListerServer -type podResourcesServer struct { +// podResourcesServerV1alpha1 implements PodResourcesListerServer +type v1alpha1PodResourcesServer struct { podsProvider PodsProvider devicesProvider DevicesProvider } -// NewPodResourcesServer returns a PodResourcesListerServer which lists pods provided by the PodsProvider +// NewV1alpha1PodResourcesServer returns a PodResourcesListerServer which lists pods provided by the PodsProvider // with device information provided by the DevicesProvider -func NewPodResourcesServer(podsProvider PodsProvider, devicesProvider DevicesProvider) v1alpha1.PodResourcesListerServer { - return &podResourcesServer{ +func NewV1alpha1PodResourcesServer(podsProvider PodsProvider, devicesProvider DevicesProvider) v1alpha1.PodResourcesListerServer { + return &v1alpha1PodResourcesServer{ podsProvider: podsProvider, devicesProvider: devicesProvider, } } // List returns information about the resources assigned to pods on the node -func (p *podResourcesServer) List(ctx context.Context, req *v1alpha1.ListPodResourcesRequest) (*v1alpha1.ListPodResourcesResponse, error) { +func (p *v1alpha1PodResourcesServer) List(ctx context.Context, req *v1alpha1.ListPodResourcesRequest) (*v1alpha1.ListPodResourcesResponse, error) { + metrics.PodResourcesEndpointRequestsTotalCount.WithLabelValues("v1alpha1").Inc() pods := p.podsProvider.GetPods() podResources := make([]*v1alpha1.PodResources, len(pods)) p.devicesProvider.UpdateAllocatedDevices() diff --git a/pkg/kubelet/apis/podresources/server_test.go b/pkg/kubelet/apis/podresources/server_v1alpha1_test.go similarity index 97% rename from pkg/kubelet/apis/podresources/server_test.go rename to pkg/kubelet/apis/podresources/server_v1alpha1_test.go index e9bda48504e..302d8c95fa0 100644 --- a/pkg/kubelet/apis/podresources/server_test.go +++ b/pkg/kubelet/apis/podresources/server_v1alpha1_test.go @@ -46,7 +46,7 @@ func (m *mockProvider) UpdateAllocatedDevices() { m.Called() } -func TestListPodResources(t *testing.T) { +func TestListPodResourcesV1alpha1(t *testing.T) { podName := "pod-name" podNamespace := "pod-namespace" podUID := types.UID("pod-uid") @@ -145,7 +145,7 @@ func TestListPodResources(t *testing.T) { m.On("GetPods").Return(tc.pods) m.On("GetDevices", string(podUID), containerName).Return(tc.devices) m.On("UpdateAllocatedDevices").Return() - server := NewPodResourcesServer(m, m) + server := NewV1alpha1PodResourcesServer(m, m) resp, err := server.List(context.TODO(), &v1alpha1.ListPodResourcesRequest{}) if err != nil { t.Errorf("want err = %v, got %q", nil, err) diff --git a/pkg/kubelet/apis/podresources/types.go b/pkg/kubelet/apis/podresources/types.go new file mode 100644 index 00000000000..7f330185686 --- /dev/null +++ b/pkg/kubelet/apis/podresources/types.go @@ -0,0 +1,33 @@ +/* +Copyright 2020 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package podresources + +import ( + "k8s.io/api/core/v1" + "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" +) + +// DevicesProvider knows how to provide the devices used by the given container +type DevicesProvider interface { + GetDevices(podUID, containerName string) []*v1alpha1.ContainerDevices + UpdateAllocatedDevices() +} + +// PodsProvider knows how to provide the pods admitted by the node +type PodsProvider interface { + GetPods() []*v1.Pod +} diff --git a/pkg/kubelet/metrics/metrics.go b/pkg/kubelet/metrics/metrics.go index 91ee37c8a0e..b903f5cd2cb 100644 --- a/pkg/kubelet/metrics/metrics.go +++ b/pkg/kubelet/metrics/metrics.go @@ -60,6 +60,8 @@ const ( // Metrics keys of device plugin operations DevicePluginRegistrationCountKey = "device_plugin_registration_total" DevicePluginAllocationDurationKey = "device_plugin_alloc_duration_seconds" + // Metrics keys of pod resources operations + PodResourcesEndpointRequestsTotalKey = "pod_resources_endpoint_requests_total" // Metric keys for node config AssignedConfigKey = "node_config_assigned" @@ -277,6 +279,18 @@ var ( []string{"resource_name"}, ) + // PodResourcesEndpointRequestsTotalCount is a Counter that tracks the cumulative number of requests to the PodResource endpoints. + // Broken down by server API version. + PodResourcesEndpointRequestsTotalCount = metrics.NewCounterVec( + &metrics.CounterOpts{ + Subsystem: KubeletSubsystem, + Name: PodResourcesEndpointRequestsTotalKey, + Help: "Cumulative number of requests to the PodResource endpoint. Broken down by server api version.", + StabilityLevel: metrics.ALPHA, + }, + []string{"server_api_version"}, + ) + // Metrics for node config // AssignedConfig is a Gauge that is set 1 if the Kubelet has a NodeConfig assigned. diff --git a/pkg/kubelet/server/BUILD b/pkg/kubelet/server/BUILD index 0b91da87faa..2d6bf833237 100644 --- a/pkg/kubelet/server/BUILD +++ b/pkg/kubelet/server/BUILD @@ -50,6 +50,7 @@ go_library( "//staging/src/k8s.io/component-base/logs:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library", "//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:go_default_library", "//vendor/github.com/emicklei/go-restful:go_default_library", "//vendor/github.com/google/cadvisor/container:go_default_library", diff --git a/pkg/kubelet/server/server.go b/pkg/kubelet/server/server.go index 6a682f35d1d..23e7c362afc 100644 --- a/pkg/kubelet/server/server.go +++ b/pkg/kubelet/server/server.go @@ -60,7 +60,8 @@ import ( "k8s.io/component-base/logs" compbasemetrics "k8s.io/component-base/metrics" "k8s.io/component-base/metrics/legacyregistry" - podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" + podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1" + podresourcesapiv1alpha1 "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" "k8s.io/kubernetes/pkg/api/legacyscheme" api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core/v1/validation" @@ -180,7 +181,8 @@ func ListenAndServeKubeletReadOnlyServer(host HostInterface, resourceAnalyzer st // ListenAndServePodResources initializes a gRPC server to serve the PodResources service func ListenAndServePodResources(socket string, podsProvider podresources.PodsProvider, devicesProvider podresources.DevicesProvider) { server := grpc.NewServer() - podresourcesapi.RegisterPodResourcesListerServer(server, podresources.NewPodResourcesServer(podsProvider, devicesProvider)) + podresourcesapiv1alpha1.RegisterPodResourcesListerServer(server, podresources.NewV1alpha1PodResourcesServer(podsProvider, devicesProvider)) + podresourcesapi.RegisterPodResourcesListerServer(server, podresources.NewV1PodResourcesServer(podsProvider, devicesProvider)) l, err := util.CreateListener(socket) if err != nil { klog.Fatalf("Failed to create listener for podResources endpoint: %v", err) diff --git a/staging/src/k8s.io/kubelet/BUILD b/staging/src/k8s.io/kubelet/BUILD index 3a6b0cafc55..3cabbc615f7 100644 --- a/staging/src/k8s.io/kubelet/BUILD +++ b/staging/src/k8s.io/kubelet/BUILD @@ -15,6 +15,7 @@ filegroup( "//staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1:all-srcs", "//staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1:all-srcs", "//staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1:all-srcs", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:all-srcs", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:all-srcs", "//staging/src/k8s.io/kubelet/pkg/apis/stats/v1alpha1:all-srcs", ], diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/BUILD b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/BUILD new file mode 100644 index 00000000000..8b57794062f --- /dev/null +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/BUILD @@ -0,0 +1,30 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["api.pb.go"], + importmap = "k8s.io/kubernetes/vendor/k8s.io/kubelet/pkg/apis/podresources/v1", + importpath = "k8s.io/kubelet/pkg/apis/podresources/v1", + visibility = ["//visibility:public"], + deps = [ + "//vendor/github.com/gogo/protobuf/gogoproto:go_default_library", + "//vendor/github.com/gogo/protobuf/proto:go_default_library", + "//vendor/google.golang.org/grpc:go_default_library", + "//vendor/google.golang.org/grpc/codes:go_default_library", + "//vendor/google.golang.org/grpc/status:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.pb.go b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.pb.go new file mode 100644 index 00000000000..8bca22bd2a9 --- /dev/null +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.pb.go @@ -0,0 +1,1400 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: api.proto + +package v1 + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// ListPodResourcesRequest is the request made to the PodResourcesLister service +type ListPodResourcesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListPodResourcesRequest) Reset() { *m = ListPodResourcesRequest{} } +func (*ListPodResourcesRequest) ProtoMessage() {} +func (*ListPodResourcesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{0} +} +func (m *ListPodResourcesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListPodResourcesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListPodResourcesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListPodResourcesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListPodResourcesRequest.Merge(m, src) +} +func (m *ListPodResourcesRequest) XXX_Size() int { + return m.Size() +} +func (m *ListPodResourcesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListPodResourcesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListPodResourcesRequest proto.InternalMessageInfo + +// ListPodResourcesResponse is the response returned by List function +type ListPodResourcesResponse struct { + PodResources []*PodResources `protobuf:"bytes,1,rep,name=pod_resources,json=podResources,proto3" json:"pod_resources,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListPodResourcesResponse) Reset() { *m = ListPodResourcesResponse{} } +func (*ListPodResourcesResponse) ProtoMessage() {} +func (*ListPodResourcesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{1} +} +func (m *ListPodResourcesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListPodResourcesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListPodResourcesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListPodResourcesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListPodResourcesResponse.Merge(m, src) +} +func (m *ListPodResourcesResponse) XXX_Size() int { + return m.Size() +} +func (m *ListPodResourcesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListPodResourcesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListPodResourcesResponse proto.InternalMessageInfo + +func (m *ListPodResourcesResponse) GetPodResources() []*PodResources { + if m != nil { + return m.PodResources + } + return nil +} + +// PodResources contains information about the node resources assigned to a pod +type PodResources struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"` + Containers []*ContainerResources `protobuf:"bytes,3,rep,name=containers,proto3" json:"containers,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *PodResources) Reset() { *m = PodResources{} } +func (*PodResources) ProtoMessage() {} +func (*PodResources) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{2} +} +func (m *PodResources) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PodResources) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PodResources.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PodResources) XXX_Merge(src proto.Message) { + xxx_messageInfo_PodResources.Merge(m, src) +} +func (m *PodResources) XXX_Size() int { + return m.Size() +} +func (m *PodResources) XXX_DiscardUnknown() { + xxx_messageInfo_PodResources.DiscardUnknown(m) +} + +var xxx_messageInfo_PodResources proto.InternalMessageInfo + +func (m *PodResources) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *PodResources) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + +func (m *PodResources) GetContainers() []*ContainerResources { + if m != nil { + return m.Containers + } + return nil +} + +// ContainerResources contains information about the resources assigned to a container +type ContainerResources struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Devices []*ContainerDevices `protobuf:"bytes,2,rep,name=devices,proto3" json:"devices,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContainerResources) Reset() { *m = ContainerResources{} } +func (*ContainerResources) ProtoMessage() {} +func (*ContainerResources) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{3} +} +func (m *ContainerResources) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContainerResources) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContainerResources.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ContainerResources) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContainerResources.Merge(m, src) +} +func (m *ContainerResources) XXX_Size() int { + return m.Size() +} +func (m *ContainerResources) XXX_DiscardUnknown() { + xxx_messageInfo_ContainerResources.DiscardUnknown(m) +} + +var xxx_messageInfo_ContainerResources proto.InternalMessageInfo + +func (m *ContainerResources) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *ContainerResources) GetDevices() []*ContainerDevices { + if m != nil { + return m.Devices + } + return nil +} + +// ContainerDevices contains information about the devices assigned to a container +type ContainerDevices struct { + ResourceName string `protobuf:"bytes,1,opt,name=resource_name,json=resourceName,proto3" json:"resource_name,omitempty"` + DeviceIds []string `protobuf:"bytes,2,rep,name=device_ids,json=deviceIds,proto3" json:"device_ids,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContainerDevices) Reset() { *m = ContainerDevices{} } +func (*ContainerDevices) ProtoMessage() {} +func (*ContainerDevices) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{4} +} +func (m *ContainerDevices) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContainerDevices) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContainerDevices.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ContainerDevices) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContainerDevices.Merge(m, src) +} +func (m *ContainerDevices) XXX_Size() int { + return m.Size() +} +func (m *ContainerDevices) XXX_DiscardUnknown() { + xxx_messageInfo_ContainerDevices.DiscardUnknown(m) +} + +var xxx_messageInfo_ContainerDevices proto.InternalMessageInfo + +func (m *ContainerDevices) GetResourceName() string { + if m != nil { + return m.ResourceName + } + return "" +} + +func (m *ContainerDevices) GetDeviceIds() []string { + if m != nil { + return m.DeviceIds + } + return nil +} + +func init() { + proto.RegisterType((*ListPodResourcesRequest)(nil), "v1.ListPodResourcesRequest") + proto.RegisterType((*ListPodResourcesResponse)(nil), "v1.ListPodResourcesResponse") + proto.RegisterType((*PodResources)(nil), "v1.PodResources") + proto.RegisterType((*ContainerResources)(nil), "v1.ContainerResources") + proto.RegisterType((*ContainerDevices)(nil), "v1.ContainerDevices") +} + +func init() { proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) } + +var fileDescriptor_00212fb1f9d3bf1c = []byte{ + // 339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x4e, 0xf2, 0x40, + 0x10, 0xc7, 0x59, 0x20, 0xdf, 0x97, 0x8e, 0x90, 0x90, 0x8d, 0xd1, 0x8a, 0xb8, 0x21, 0xeb, 0x85, + 0x8b, 0x25, 0x60, 0xf4, 0x01, 0xc4, 0x8b, 0x89, 0x31, 0xda, 0x83, 0xd1, 0x13, 0x29, 0xed, 0x8a, + 0x7b, 0xa0, 0xbb, 0x76, 0x5b, 0xe2, 0xd1, 0x47, 0xf0, 0xb1, 0x38, 0x7a, 0xf4, 0x28, 0xf5, 0x45, + 0xcc, 0xee, 0xa6, 0xa1, 0x08, 0x9e, 0x3a, 0xf3, 0xff, 0xcd, 0xcc, 0xbf, 0x9d, 0x29, 0x38, 0x81, + 0xe4, 0x9e, 0x4c, 0x44, 0x2a, 0x70, 0x75, 0x3e, 0x68, 0x9f, 0x4c, 0x79, 0xfa, 0x9c, 0x4d, 0xbc, + 0x50, 0xcc, 0xfa, 0x53, 0x31, 0x15, 0x7d, 0x83, 0x26, 0xd9, 0x93, 0xc9, 0x4c, 0x62, 0x22, 0xdb, + 0x42, 0x0f, 0x60, 0xff, 0x9a, 0xab, 0xf4, 0x56, 0x44, 0x3e, 0x53, 0x22, 0x4b, 0x42, 0xa6, 0x7c, + 0xf6, 0x92, 0x31, 0x95, 0xd2, 0x3b, 0x70, 0x37, 0x91, 0x92, 0x22, 0x56, 0x0c, 0x9f, 0x41, 0x53, + 0x8a, 0x68, 0x9c, 0x14, 0xc0, 0x45, 0xdd, 0x5a, 0x6f, 0x67, 0xd8, 0xf2, 0xe6, 0x03, 0x6f, 0xad, + 0xa1, 0x21, 0x4b, 0x19, 0x7d, 0x85, 0x46, 0x99, 0x62, 0x0c, 0xf5, 0x38, 0x98, 0x31, 0x17, 0x75, + 0x51, 0xcf, 0xf1, 0x4d, 0x8c, 0x3b, 0xe0, 0xe8, 0xa7, 0x92, 0x41, 0xc8, 0xdc, 0xaa, 0x01, 0x2b, + 0x01, 0x9f, 0x03, 0x84, 0x22, 0x4e, 0x03, 0x1e, 0xb3, 0x44, 0xb9, 0x35, 0xe3, 0xba, 0xa7, 0x5d, + 0x47, 0x85, 0xba, 0xf2, 0x2e, 0x55, 0xd2, 0x07, 0xc0, 0x9b, 0x15, 0x5b, 0xfd, 0x3d, 0xf8, 0x1f, + 0xb1, 0x39, 0xd7, 0x1f, 0x55, 0x35, 0xe3, 0x77, 0xd7, 0xc6, 0x5f, 0x5a, 0xe6, 0x17, 0x45, 0xf4, + 0x1e, 0x5a, 0xbf, 0x21, 0x3e, 0x86, 0x66, 0xb1, 0x9a, 0x71, 0xc9, 0xa0, 0x51, 0x88, 0x37, 0xda, + 0xe8, 0x08, 0xc0, 0xce, 0x18, 0xf3, 0xc8, 0x7a, 0x39, 0xbe, 0x63, 0x95, 0xab, 0x48, 0x0d, 0x1f, + 0x01, 0x97, 0x77, 0xa5, 0x4f, 0xc1, 0x12, 0x3c, 0x82, 0xba, 0x8e, 0xf0, 0xa1, 0x7e, 0xa9, 0x3f, + 0x2e, 0xd7, 0xee, 0x6c, 0x87, 0xf6, 0x76, 0xb4, 0x72, 0xd1, 0x59, 0x2c, 0x09, 0xfa, 0x5c, 0x92, + 0xca, 0x5b, 0x4e, 0xd0, 0x22, 0x27, 0xe8, 0x23, 0x27, 0xe8, 0x2b, 0x27, 0xe8, 0xfd, 0x9b, 0x54, + 0x26, 0xff, 0xcc, 0x9f, 0x71, 0xfa, 0x13, 0x00, 0x00, 0xff, 0xff, 0x1c, 0x28, 0xb2, 0xaa, 0x59, + 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// PodResourcesListerClient is the client API for PodResourcesLister service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type PodResourcesListerClient interface { + List(ctx context.Context, in *ListPodResourcesRequest, opts ...grpc.CallOption) (*ListPodResourcesResponse, error) +} + +type podResourcesListerClient struct { + cc *grpc.ClientConn +} + +func NewPodResourcesListerClient(cc *grpc.ClientConn) PodResourcesListerClient { + return &podResourcesListerClient{cc} +} + +func (c *podResourcesListerClient) List(ctx context.Context, in *ListPodResourcesRequest, opts ...grpc.CallOption) (*ListPodResourcesResponse, error) { + out := new(ListPodResourcesResponse) + err := c.cc.Invoke(ctx, "/v1.PodResourcesLister/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// PodResourcesListerServer is the server API for PodResourcesLister service. +type PodResourcesListerServer interface { + List(context.Context, *ListPodResourcesRequest) (*ListPodResourcesResponse, error) +} + +// UnimplementedPodResourcesListerServer can be embedded to have forward compatible implementations. +type UnimplementedPodResourcesListerServer struct { +} + +func (*UnimplementedPodResourcesListerServer) List(ctx context.Context, req *ListPodResourcesRequest) (*ListPodResourcesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterPodResourcesListerServer(s *grpc.Server, srv PodResourcesListerServer) { + s.RegisterService(&_PodResourcesLister_serviceDesc, srv) +} + +func _PodResourcesLister_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListPodResourcesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PodResourcesListerServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/v1.PodResourcesLister/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PodResourcesListerServer).List(ctx, req.(*ListPodResourcesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _PodResourcesLister_serviceDesc = grpc.ServiceDesc{ + ServiceName: "v1.PodResourcesLister", + HandlerType: (*PodResourcesListerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "List", + Handler: _PodResourcesLister_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api.proto", +} + +func (m *ListPodResourcesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListPodResourcesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListPodResourcesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *ListPodResourcesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListPodResourcesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListPodResourcesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PodResources) > 0 { + for iNdEx := len(m.PodResources) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PodResources[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintApi(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *PodResources) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PodResources) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PodResources) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Containers) > 0 { + for iNdEx := len(m.Containers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Containers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintApi(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Namespace) > 0 { + i -= len(m.Namespace) + copy(dAtA[i:], m.Namespace) + i = encodeVarintApi(dAtA, i, uint64(len(m.Namespace))) + i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintApi(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ContainerResources) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ContainerResources) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ContainerResources) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Devices) > 0 { + for iNdEx := len(m.Devices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Devices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintApi(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintApi(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ContainerDevices) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ContainerDevices) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ContainerDevices) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DeviceIds) > 0 { + for iNdEx := len(m.DeviceIds) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.DeviceIds[iNdEx]) + copy(dAtA[i:], m.DeviceIds[iNdEx]) + i = encodeVarintApi(dAtA, i, uint64(len(m.DeviceIds[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.ResourceName) > 0 { + i -= len(m.ResourceName) + copy(dAtA[i:], m.ResourceName) + i = encodeVarintApi(dAtA, i, uint64(len(m.ResourceName))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintApi(dAtA []byte, offset int, v uint64) int { + offset -= sovApi(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ListPodResourcesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *ListPodResourcesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PodResources) > 0 { + for _, e := range m.PodResources { + l = e.Size() + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func (m *PodResources) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + l = len(m.Namespace) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + if len(m.Containers) > 0 { + for _, e := range m.Containers { + l = e.Size() + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func (m *ContainerResources) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + if len(m.Devices) > 0 { + for _, e := range m.Devices { + l = e.Size() + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func (m *ContainerDevices) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ResourceName) + if l > 0 { + n += 1 + l + sovApi(uint64(l)) + } + if len(m.DeviceIds) > 0 { + for _, s := range m.DeviceIds { + l = len(s) + n += 1 + l + sovApi(uint64(l)) + } + } + return n +} + +func sovApi(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozApi(x uint64) (n int) { + return sovApi(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ListPodResourcesRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ListPodResourcesRequest{`, + `}`, + }, "") + return s +} +func (this *ListPodResourcesResponse) String() string { + if this == nil { + return "nil" + } + repeatedStringForPodResources := "[]*PodResources{" + for _, f := range this.PodResources { + repeatedStringForPodResources += strings.Replace(f.String(), "PodResources", "PodResources", 1) + "," + } + repeatedStringForPodResources += "}" + s := strings.Join([]string{`&ListPodResourcesResponse{`, + `PodResources:` + repeatedStringForPodResources + `,`, + `}`, + }, "") + return s +} +func (this *PodResources) String() string { + if this == nil { + return "nil" + } + repeatedStringForContainers := "[]*ContainerResources{" + for _, f := range this.Containers { + repeatedStringForContainers += strings.Replace(f.String(), "ContainerResources", "ContainerResources", 1) + "," + } + repeatedStringForContainers += "}" + s := strings.Join([]string{`&PodResources{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Namespace:` + fmt.Sprintf("%v", this.Namespace) + `,`, + `Containers:` + repeatedStringForContainers + `,`, + `}`, + }, "") + return s +} +func (this *ContainerResources) String() string { + if this == nil { + return "nil" + } + repeatedStringForDevices := "[]*ContainerDevices{" + for _, f := range this.Devices { + repeatedStringForDevices += strings.Replace(f.String(), "ContainerDevices", "ContainerDevices", 1) + "," + } + repeatedStringForDevices += "}" + s := strings.Join([]string{`&ContainerResources{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Devices:` + repeatedStringForDevices + `,`, + `}`, + }, "") + return s +} +func (this *ContainerDevices) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ContainerDevices{`, + `ResourceName:` + fmt.Sprintf("%v", this.ResourceName) + `,`, + `DeviceIds:` + fmt.Sprintf("%v", this.DeviceIds) + `,`, + `}`, + }, "") + return s +} +func valueToStringApi(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *ListPodResourcesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListPodResourcesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListPodResourcesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ListPodResourcesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListPodResourcesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListPodResourcesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PodResources", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PodResources = append(m.PodResources, &PodResources{}) + if err := m.PodResources[len(m.PodResources)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PodResources) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PodResources: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PodResources: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Namespace", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Namespace = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Containers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Containers = append(m.Containers, &ContainerResources{}) + if err := m.Containers[len(m.Containers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ContainerResources) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ContainerResources: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContainerResources: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Devices", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Devices = append(m.Devices, &ContainerDevices{}) + if err := m.Devices[len(m.Devices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ContainerDevices) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ContainerDevices: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContainerDevices: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ResourceName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ResourceName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeviceIds", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApi + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthApi + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthApi + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DeviceIds = append(m.DeviceIds, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipApi(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthApi + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipApi(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowApi + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthApi + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupApi + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthApi + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowApi = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupApi = fmt.Errorf("proto: unexpected end of group") +) diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto new file mode 100644 index 00000000000..ef4c7f96d6a --- /dev/null +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto @@ -0,0 +1,48 @@ +// To regenerate api.pb.go run hack/update-generated-pod-resources.sh +syntax = "proto3"; + +package v1; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.stringer_all) = true; +option (gogoproto.goproto_getters_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.goproto_unrecognized_all) = false; + + +// PodResourcesLister is a service provided by the kubelet that provides information about the +// node resources consumed by pods and containers on the node +service PodResourcesLister { + rpc List(ListPodResourcesRequest) returns (ListPodResourcesResponse) {} +} + +// ListPodResourcesRequest is the request made to the PodResourcesLister service +message ListPodResourcesRequest {} + +// ListPodResourcesResponse is the response returned by List function +message ListPodResourcesResponse { + repeated PodResources pod_resources = 1; +} + +// PodResources contains information about the node resources assigned to a pod +message PodResources { + string name = 1; + string namespace = 2; + repeated ContainerResources containers = 3; +} + +// ContainerResources contains information about the resources assigned to a container +message ContainerResources { + string name = 1; + repeated ContainerDevices devices = 2; +} + +// ContainerDevices contains information about the devices assigned to a container +message ContainerDevices { + string resource_name = 1; + repeated string device_ids = 2; +} diff --git a/test/e2e_node/BUILD b/test/e2e_node/BUILD index 7b89ed0fa2a..02afb1ccf3a 100644 --- a/test/e2e_node/BUILD +++ b/test/e2e_node/BUILD @@ -47,6 +47,7 @@ go_library( "//staging/src/k8s.io/cri-api/pkg/apis:go_default_library", "//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library", "//staging/src/k8s.io/kubelet/config/v1beta1:go_default_library", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/stats/v1alpha1:go_default_library", "//test/e2e/common:go_default_library", @@ -197,6 +198,7 @@ go_test( "//staging/src/k8s.io/component-base/metrics/testutil:go_default_library", "//staging/src/k8s.io/cri-api/pkg/apis:go_default_library", "//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library", + "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1:go_default_library", "//staging/src/k8s.io/kubelet/pkg/apis/stats/v1alpha1:go_default_library", "//staging/src/k8s.io/mount-utils:go_default_library", diff --git a/test/e2e_node/device_plugin_test.go b/test/e2e_node/device_plugin_test.go index 5d2f6bf6ecd..7ea69d7ee64 100644 --- a/test/e2e_node/device_plugin_test.go +++ b/test/e2e_node/device_plugin_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" + kubeletpodresourcesv1 "k8s.io/kubelet/pkg/apis/podresources/v1" kubeletpodresourcesv1alpha1 "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" "k8s.io/kubernetes/pkg/features" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" @@ -157,25 +158,56 @@ func testDevicePlugin(f *framework.Framework, pluginSockDir string) { devID1 := parseLog(f, pod1.Name, pod1.Name, deviceIDRE) gomega.Expect(devID1).To(gomega.Not(gomega.Equal(""))) - podResources, err := getNodeDevices() - var resourcesForOurPod *kubeletpodresourcesv1alpha1.PodResources - framework.Logf("pod resources %v", podResources) + v1alphaPodResources, err := getV1alpha1NodeDevices() framework.ExpectNoError(err) - framework.ExpectEqual(len(podResources.PodResources), 2) - for _, res := range podResources.GetPodResources() { + framework.Logf("v1alpha pod resources %v", v1alphaPodResources) + + v1PodResources, err := getV1NodeDevices() + framework.ExpectNoError(err) + framework.Logf("v1 pod resources %v", v1PodResources) + + framework.ExpectEqual(len(v1alphaPodResources.PodResources), 2) + framework.ExpectEqual(len(v1PodResources.PodResources), 2) + + var v1alphaResourcesForOurPod *kubeletpodresourcesv1alpha1.PodResources + for _, res := range v1alphaPodResources.GetPodResources() { if res.Name == pod1.Name { - resourcesForOurPod = res + v1alphaResourcesForOurPod = res } } - framework.Logf("resourcesForOurPod %v", resourcesForOurPod) - gomega.Expect(resourcesForOurPod).NotTo(gomega.BeNil()) - framework.ExpectEqual(resourcesForOurPod.Name, pod1.Name) - framework.ExpectEqual(resourcesForOurPod.Namespace, pod1.Namespace) - framework.ExpectEqual(len(resourcesForOurPod.Containers), 1) - framework.ExpectEqual(resourcesForOurPod.Containers[0].Name, pod1.Spec.Containers[0].Name) - framework.ExpectEqual(len(resourcesForOurPod.Containers[0].Devices), 1) - framework.ExpectEqual(resourcesForOurPod.Containers[0].Devices[0].ResourceName, resourceName) - framework.ExpectEqual(len(resourcesForOurPod.Containers[0].Devices[0].DeviceIds), 1) + framework.Logf("v1alphaResourcesForOurPod %v", v1alphaResourcesForOurPod) + + var v1ResourcesForOurPod *kubeletpodresourcesv1.PodResources + for _, res := range v1PodResources.GetPodResources() { + if res.Name == pod1.Name { + v1ResourcesForOurPod = res + } + } + framework.Logf("v1ResourcesForOurPod %v", v1ResourcesForOurPod) + + gomega.Expect(v1alphaResourcesForOurPod).NotTo(gomega.BeNil()) + gomega.Expect(v1ResourcesForOurPod).NotTo(gomega.BeNil()) + + framework.ExpectEqual(v1alphaResourcesForOurPod.Name, pod1.Name) + framework.ExpectEqual(v1ResourcesForOurPod.Name, pod1.Name) + + framework.ExpectEqual(v1alphaResourcesForOurPod.Namespace, pod1.Namespace) + framework.ExpectEqual(v1ResourcesForOurPod.Namespace, pod1.Namespace) + + framework.ExpectEqual(len(v1alphaResourcesForOurPod.Containers), 1) + framework.ExpectEqual(len(v1ResourcesForOurPod.Containers), 1) + + framework.ExpectEqual(v1alphaResourcesForOurPod.Containers[0].Name, pod1.Spec.Containers[0].Name) + framework.ExpectEqual(v1ResourcesForOurPod.Containers[0].Name, pod1.Spec.Containers[0].Name) + + framework.ExpectEqual(len(v1alphaResourcesForOurPod.Containers[0].Devices), 1) + framework.ExpectEqual(len(v1ResourcesForOurPod.Containers[0].Devices), 1) + + framework.ExpectEqual(v1alphaResourcesForOurPod.Containers[0].Devices[0].ResourceName, resourceName) + framework.ExpectEqual(v1ResourcesForOurPod.Containers[0].Devices[0].ResourceName, resourceName) + + framework.ExpectEqual(len(v1alphaResourcesForOurPod.Containers[0].Devices[0].DeviceIds), 1) + framework.ExpectEqual(len(v1ResourcesForOurPod.Containers[0].Devices[0].DeviceIds), 1) pod1, err = f.PodClient().Get(context.TODO(), pod1.Name, metav1.GetOptions{}) framework.ExpectNoError(err) diff --git a/test/e2e_node/util.go b/test/e2e_node/util.go index bae5d51f04f..fd6273eac55 100644 --- a/test/e2e_node/util.go +++ b/test/e2e_node/util.go @@ -38,6 +38,7 @@ import ( internalapi "k8s.io/cri-api/pkg/apis" "k8s.io/klog/v2" kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1" + kubeletpodresourcesv1 "k8s.io/kubelet/pkg/apis/podresources/v1" kubeletpodresourcesv1alpha1 "k8s.io/kubelet/pkg/apis/podresources/v1alpha1" stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" "k8s.io/kubernetes/pkg/features" @@ -103,12 +104,12 @@ func getNodeSummary() (*stats.Summary, error) { return &summary, nil } -func getNodeDevices() (*kubeletpodresourcesv1alpha1.ListPodResourcesResponse, error) { +func getV1alpha1NodeDevices() (*kubeletpodresourcesv1alpha1.ListPodResourcesResponse, error) { endpoint, err := util.LocalEndpoint(defaultPodResourcesPath, podresources.Socket) if err != nil { return nil, fmt.Errorf("Error getting local endpoint: %v", err) } - client, conn, err := podresources.GetClient(endpoint, defaultPodResourcesTimeout, defaultPodResourcesMaxSize) + client, conn, err := podresources.GetV1alpha1Client(endpoint, defaultPodResourcesTimeout, defaultPodResourcesMaxSize) if err != nil { return nil, fmt.Errorf("Error getting grpc client: %v", err) } @@ -122,6 +123,25 @@ func getNodeDevices() (*kubeletpodresourcesv1alpha1.ListPodResourcesResponse, er return resp, nil } +func getV1NodeDevices() (*kubeletpodresourcesv1.ListPodResourcesResponse, error) { + endpoint, err := util.LocalEndpoint(defaultPodResourcesPath, podresources.Socket) + if err != nil { + return nil, fmt.Errorf("Error getting local endpoint: %v", err) + } + client, conn, err := podresources.GetV1Client(endpoint, defaultPodResourcesTimeout, defaultPodResourcesMaxSize) + if err != nil { + return nil, fmt.Errorf("Error getting gRPC client: %v", err) + } + defer conn.Close() + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + resp, err := client.List(ctx, &kubeletpodresourcesv1.ListPodResourcesRequest{}) + if err != nil { + return nil, fmt.Errorf("%v.Get(_) = _, %v", client, err) + } + return resp, nil +} + // Returns the current KubeletConfiguration func getCurrentKubeletConfig() (*kubeletconfig.KubeletConfiguration, error) { // namespace only relevant if useProxy==true, so we don't bother diff --git a/vendor/modules.txt b/vendor/modules.txt index ee71360e369..674cb0f893d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2427,6 +2427,7 @@ k8s.io/kubectl/pkg/validation k8s.io/kubelet/config/v1beta1 k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1 k8s.io/kubelet/pkg/apis/pluginregistration/v1 +k8s.io/kubelet/pkg/apis/podresources/v1 k8s.io/kubelet/pkg/apis/podresources/v1alpha1 k8s.io/kubelet/pkg/apis/stats/v1alpha1 # k8s.io/legacy-cloud-providers v0.0.0 => ./staging/src/k8s.io/legacy-cloud-providers