Skip to content

Commit 99f3195

Browse files
authored
Merge pull request kubernetes#68015 from damemi/hpa-metrics-specificity
Support backwards compatibility for v1beta1 custom metrics client
2 parents 5510be2 + 76bd48b commit 99f3195

File tree

27 files changed

+1005
-136
lines changed

27 files changed

+1005
-136
lines changed

api/openapi-spec/swagger.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger-spec/autoscaling_v2beta2.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kube-controller-manager/app/autoscaling.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/client-go/scale"
2929
"k8s.io/kubernetes/pkg/controller/podautoscaler"
3030
"k8s.io/kubernetes/pkg/controller/podautoscaler/metrics"
31+
3132
resourceclient "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1"
3233
"k8s.io/metrics/pkg/client/custom_metrics"
3334
"k8s.io/metrics/pkg/client/external_metrics"
@@ -48,9 +49,19 @@ func startHPAController(ctx ControllerContext) (http.Handler, bool, error) {
4849

4950
func startHPAControllerWithRESTClient(ctx ControllerContext) (http.Handler, bool, error) {
5051
clientConfig := ctx.ClientBuilder.ConfigOrDie("horizontal-pod-autoscaler")
52+
hpaClient := ctx.ClientBuilder.ClientOrDie("horizontal-pod-autoscaler")
53+
54+
apiVersionsGetter := custom_metrics.NewAvailableAPIsGetter(hpaClient.Discovery())
55+
// invalidate the discovery information roughly once per resync interval our API
56+
// information is *at most* two resync intervals old.
57+
go custom_metrics.PeriodicallyInvalidate(
58+
apiVersionsGetter,
59+
ctx.ComponentConfig.HPAController.HorizontalPodAutoscalerSyncPeriod.Duration,
60+
ctx.Stop)
61+
5162
metricsClient := metrics.NewRESTMetricsClient(
5263
resourceclient.NewForConfigOrDie(clientConfig),
53-
custom_metrics.NewForConfigOrDie(clientConfig),
64+
custom_metrics.NewForConfig(clientConfig, ctx.RESTMapper, apiVersionsGetter),
5465
external_metrics.NewForConfigOrDie(clientConfig),
5566
)
5667
return startHPAControllerWithMetricsClient(ctx, metricsClient)

docs/api-reference/autoscaling/v2beta2/definitions.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/api/autoscaling/v2beta2/generated.proto

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/api/autoscaling/v2beta2/types.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,18 @@ type MetricTarget struct {
200200
// type represents whether the metric type is Utilization, Value, or AverageValue
201201
Type MetricTargetType `json:"type" protobuf:"bytes,1,name=type"`
202202
// value is the target value of the metric (as a quantity).
203-
Value *resource.Quantity `json:"value,omitempty" protobuf:"bytes,2,name=value"`
203+
// +optional
204+
Value *resource.Quantity `json:"value,omitempty" protobuf:"bytes,2,opt,name=value"`
204205
// averageValue is the target value of the average of the
205206
// metric across all relevant pods (as a quantity)
206-
AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,3,name=averageValue"`
207-
207+
// +optional
208+
AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,3,opt,name=averageValue"`
208209
// averageUtilization is the target value of the average of the
209210
// resource metric across all relevant pods, represented as a percentage of
210211
// the requested value of the resource for the pods.
211212
// Currently only valid for Resource metric source type
212-
AverageUtilization *int32 `json:"averageUtilization,omitempty" protobuf:"bytes,4,name=averageUtilization"`
213+
// +optional
214+
AverageUtilization *int32 `json:"averageUtilization,omitempty" protobuf:"bytes,4,opt,name=averageUtilization"`
213215
}
214216

215217
// MetricTargetType specifies the type of metric being targeted, and should be either
@@ -364,14 +366,17 @@ type ExternalMetricStatus struct {
364366
// MetricValueStatus holds the current value for a metric
365367
type MetricValueStatus struct {
366368
// value is the current value of the metric (as a quantity).
367-
Value *resource.Quantity `json:"value" protobuf:"bytes,1,name=value"`
369+
// +optional
370+
Value *resource.Quantity `json:"value,omitempty" protobuf:"bytes,1,opt,name=value"`
368371
// averageValue is the current value of the average of the
369372
// metric across all relevant pods (as a quantity)
370-
AverageValue *resource.Quantity `json:"averageValue" protobuf:"bytes,2,name=averageValue"`
373+
// +optional
374+
AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,2,opt,name=averageValue"`
371375
// currentAverageUtilization is the current value of the average of the
372376
// resource metric across all relevant pods, represented as a percentage of
373377
// the requested value of the resource for the pods.
374-
AverageUtilization *int32 `json:"averageUtilization" protobuf:"bytes,3,name=averageUtilization"`
378+
// +optional
379+
AverageUtilization *int32 `json:"averageUtilization,omitempty" protobuf:"bytes,3,opt,name=averageUtilization"`
375380
}
376381

377382
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

staging/src/k8s.io/metrics/Godeps/Godeps.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/metrics/pkg/apis/custom_metrics/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4646
scheme.AddKnownTypes(SchemeGroupVersion,
4747
&MetricValue{},
4848
&MetricValueList{},
49+
&MetricListOptions{},
4950
)
5051
return nil
5152
}

staging/src/k8s.io/metrics/pkg/apis/custom_metrics/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ type MetricValue struct {
7171
// for all objects matching the given label selector
7272
const AllObjects = "*"
7373

74+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
75+
76+
// MetricListOptions is used to select metrics by their label selectors
77+
type MetricListOptions struct {
78+
metav1.TypeMeta `json:",inline"`
79+
80+
// A selector to restrict the list of returned objects by their labels.
81+
// Defaults to everything.
82+
// +optional
83+
LabelSelector string `json:"labelSelector,omitempty" protobuf:"bytes,1,opt,name=labelSelector"`
84+
85+
// A selector to restrict the list of returned metrics by their labels
86+
// +optional
87+
MetricLabelSelector string `json:"metricLabelSelector,omitempty" protobuf:"bytes,2,opt,name=metricLabelSelector"`
88+
}
89+
7490
// NOTE: ObjectReference is copied from k8s.io/kubernetes/pkg/api/types.go. We
7591
// cannot depend on k8s.io/kubernetes/pkg/api because that creates cyclic
7692
// dependency between k8s.io/metrics and k8s.io/kubernetes. We cannot depend on

0 commit comments

Comments
 (0)