From d72cbcb339221d37315d0c41c80ddd35799fc092 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 15 May 2017 19:04:09 -0400 Subject: [PATCH] [k8s.io/metrics] proto tags for metrics/v1alpha1 This commit adds proto tags to `k8s.io/metrics/pkg/apis/metrics/v1alpha1`. The tags are more-or-less what's suggested by `go-to-protobuf`, with the exception of the use of `castvalue`. `castvalue` is used to force gogo-proto to realize that the value of `ResourceList` (which is `map[ResourceName]Quantity`) is actually a type that it should consider when recording which packages are used. Otherwise, it ignores the type, using an unnamed import for the `k8s.io/apimachinery/pkg/api/resource`, which causes compilation errors. --- .../pkg/apis/metrics/v1alpha1/types.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/staging/src/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go b/staging/src/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go index 452fc6a346e..345d2d95759 100644 --- a/staging/src/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go +++ b/staging/src/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go @@ -29,15 +29,15 @@ import ( // resource usage metrics of a node. type NodeMetrics struct { metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // The following fields define time interval from which metrics were // collected from the interval [Timestamp-Window, Timestamp]. - Timestamp metav1.Time `json:"timestamp"` - Window metav1.Duration `json:"window"` + Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` + Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` // The memory usage is the memory working set. - Usage v1.ResourceList `json:"usage"` + Usage v1.ResourceList `json:"usage" protobuf:"bytes,4,rep,name=usage,casttype=k8s.io/client-go/pkg/api/v1.ResourceList,castkey=k8s.io/client-go/pkg/api/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"` } // NodeMetricsList is a list of NodeMetrics. @@ -45,10 +45,10 @@ type NodeMetricsList struct { metav1.TypeMeta `json:",inline"` // Standard list metadata. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds - metav1.ListMeta `json:"metadata,omitempty"` + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // List of node metrics. - Items []NodeMetrics `json:"items"` + Items []NodeMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` } // +genclient=true @@ -58,15 +58,15 @@ type NodeMetricsList struct { // resource usage metrics of a pod. type PodMetrics struct { metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // The following fields define time interval from which metrics were // collected from the interval [Timestamp-Window, Timestamp]. - Timestamp metav1.Time `json:"timestamp"` - Window metav1.Duration `json:"window"` + Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` + Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` // Metrics for all containers are collected within the same time window. - Containers []ContainerMetrics `json:"containers"` + Containers []ContainerMetrics `json:"containers" protobuf:"bytes,4,rep,name=containers"` } // PodMetricsList is a list of PodMetrics. @@ -74,16 +74,16 @@ type PodMetricsList struct { metav1.TypeMeta `json:",inline"` // Standard list metadata. // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds - metav1.ListMeta `json:"metadata,omitempty"` + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // List of pod metrics. - Items []PodMetrics `json:"items"` + Items []PodMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` } // resource usage metrics of a container. type ContainerMetrics struct { // Container name corresponding to the one from pod.spec.containers. - Name string `json:"name"` + Name string `json:"name" protobuf:"bytes,1,opt,name=name"` // The memory usage is the memory working set. - Usage v1.ResourceList `json:"usage"` + Usage v1.ResourceList `json:"usage" protobuf:"bytes,2,rep,name=usage,casttype=k8s.io/client-go/pkg/api/v1.ResourceList,castkey=k8s.io/client-go/pkg/api/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"` }