mirror of https://github.com/k3s-io/k3s
Customize HPA Heapster service namespace/name
This commit makes the HPA metrics client configurable in where it looks for heapster instead of hard coding it to "kube-system/heapster". The values of "kube-system/heapster" are still recorded as constants in the metrics client package for use as default values.pull/6/head
parent
fd03c2c1d7
commit
f262560cac
|
@ -336,7 +336,8 @@ func (s *CMServer) Run(_ []string) error {
|
||||||
glog.Infof("Starting %s apis", groupVersion)
|
glog.Infof("Starting %s apis", groupVersion)
|
||||||
if containsResource(resources, "horizontalpodautoscalers") {
|
if containsResource(resources, "horizontalpodautoscalers") {
|
||||||
glog.Infof("Starting horizontal pod controller.")
|
glog.Infof("Starting horizontal pod controller.")
|
||||||
podautoscaler.NewHorizontalController(kubeClient, metrics.NewHeapsterMetricsClient(kubeClient)).
|
metricsClient := metrics.NewHeapsterMetricsClient(kubeClient, metrics.DefaultHeapsterNamespace, metrics.DefaultHeapsterService)
|
||||||
|
podautoscaler.NewHorizontalController(kubeClient, metricsClient).
|
||||||
Run(s.HorizontalPodAutoscalerSyncPeriod)
|
Run(s.HorizontalPodAutoscalerSyncPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,8 @@ func (tc *testCase) verifyResults(t *testing.T) {
|
||||||
|
|
||||||
func (tc *testCase) runTest(t *testing.T) {
|
func (tc *testCase) runTest(t *testing.T) {
|
||||||
testClient := tc.prepareTestClient(t)
|
testClient := tc.prepareTestClient(t)
|
||||||
hpaController := NewHorizontalController(testClient, metrics.NewHeapsterMetricsClient(testClient))
|
metricsClient := metrics.NewHeapsterMetricsClient(testClient, metrics.DefaultHeapsterNamespace, metrics.DefaultHeapsterService)
|
||||||
|
hpaController := NewHorizontalController(testClient, metricsClient)
|
||||||
err := hpaController.reconcileAutoscalers()
|
err := hpaController.reconcileAutoscalers()
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
if tc.verifyEvents {
|
if tc.verifyEvents {
|
||||||
|
|
|
@ -33,8 +33,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
heapsterNamespace = "kube-system"
|
DefaultHeapsterNamespace = "kube-system"
|
||||||
heapsterService = "heapster"
|
DefaultHeapsterService = "heapster"
|
||||||
)
|
)
|
||||||
|
|
||||||
var heapsterQueryStart = -5 * time.Minute
|
var heapsterQueryStart = -5 * time.Minute
|
||||||
|
@ -66,6 +66,8 @@ type metricDefinition struct {
|
||||||
type HeapsterMetricsClient struct {
|
type HeapsterMetricsClient struct {
|
||||||
client client.Interface
|
client client.Interface
|
||||||
resourceDefinitions map[api.ResourceName]metricDefinition
|
resourceDefinitions map[api.ResourceName]metricDefinition
|
||||||
|
heapsterNamespace string
|
||||||
|
heapsterService string
|
||||||
}
|
}
|
||||||
|
|
||||||
var heapsterMetricDefinitions = map[api.ResourceName]metricDefinition{
|
var heapsterMetricDefinitions = map[api.ResourceName]metricDefinition{
|
||||||
|
@ -91,10 +93,12 @@ var heapsterMetricDefinitions = map[api.ResourceName]metricDefinition{
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHeapsterMetricsClient returns a new instance of Heapster-based implementation of MetricsClient interface.
|
// NewHeapsterMetricsClient returns a new instance of Heapster-based implementation of MetricsClient interface.
|
||||||
func NewHeapsterMetricsClient(client client.Interface) *HeapsterMetricsClient {
|
func NewHeapsterMetricsClient(client client.Interface, namespace, service string) *HeapsterMetricsClient {
|
||||||
return &HeapsterMetricsClient{
|
return &HeapsterMetricsClient{
|
||||||
client: client,
|
client: client,
|
||||||
resourceDefinitions: heapsterMetricDefinitions,
|
resourceDefinitions: heapsterMetricDefinitions,
|
||||||
|
heapsterNamespace: namespace,
|
||||||
|
heapsterService: service,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +159,8 @@ func (h *HeapsterMetricsClient) getForPods(resourceName api.ResourceName, namesp
|
||||||
strings.Join(podNames, ","),
|
strings.Join(podNames, ","),
|
||||||
metricSpec.name)
|
metricSpec.name)
|
||||||
|
|
||||||
resultRaw, err := h.client.Services(heapsterNamespace).
|
resultRaw, err := h.client.Services(h.heapsterNamespace).
|
||||||
ProxyGet(heapsterService, metricPath, map[string]string{"start": startTime.Format(time.RFC3339)}).
|
ProxyGet(h.heapsterService, metricPath, map[string]string{"start": startTime.Format(time.RFC3339)}).
|
||||||
DoRaw()
|
DoRaw()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -148,7 +148,7 @@ func (tc *testCase) verifyResults(t *testing.T, val *ResourceConsumption, err er
|
||||||
|
|
||||||
func (tc *testCase) runTest(t *testing.T) {
|
func (tc *testCase) runTest(t *testing.T) {
|
||||||
testClient := tc.prepareTestClient(t)
|
testClient := tc.prepareTestClient(t)
|
||||||
metricsClient := NewHeapsterMetricsClient(testClient)
|
metricsClient := NewHeapsterMetricsClient(testClient, DefaultHeapsterNamespace, DefaultHeapsterService)
|
||||||
val, _, err := metricsClient.GetResourceConsumptionAndRequest(tc.targetResource, tc.namespace, tc.selector)
|
val, _, err := metricsClient.GetResourceConsumptionAndRequest(tc.targetResource, tc.namespace, tc.selector)
|
||||||
tc.verifyResults(t, val, err)
|
tc.verifyResults(t, val, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue