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
Solly Ross 2015-11-02 11:14:08 -05:00
parent fd03c2c1d7
commit f262560cac
4 changed files with 14 additions and 8 deletions

View File

@ -336,7 +336,8 @@ func (s *CMServer) Run(_ []string) error {
glog.Infof("Starting %s apis", groupVersion)
if containsResource(resources, "horizontalpodautoscalers") {
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)
}

View File

@ -206,7 +206,8 @@ func (tc *testCase) verifyResults(t *testing.T) {
func (tc *testCase) runTest(t *testing.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()
assert.Equal(t, nil, err)
if tc.verifyEvents {

View File

@ -33,8 +33,8 @@ import (
)
const (
heapsterNamespace = "kube-system"
heapsterService = "heapster"
DefaultHeapsterNamespace = "kube-system"
DefaultHeapsterService = "heapster"
)
var heapsterQueryStart = -5 * time.Minute
@ -66,6 +66,8 @@ type metricDefinition struct {
type HeapsterMetricsClient struct {
client client.Interface
resourceDefinitions map[api.ResourceName]metricDefinition
heapsterNamespace string
heapsterService string
}
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.
func NewHeapsterMetricsClient(client client.Interface) *HeapsterMetricsClient {
func NewHeapsterMetricsClient(client client.Interface, namespace, service string) *HeapsterMetricsClient {
return &HeapsterMetricsClient{
client: client,
resourceDefinitions: heapsterMetricDefinitions,
heapsterNamespace: namespace,
heapsterService: service,
}
}
@ -155,8 +159,8 @@ func (h *HeapsterMetricsClient) getForPods(resourceName api.ResourceName, namesp
strings.Join(podNames, ","),
metricSpec.name)
resultRaw, err := h.client.Services(heapsterNamespace).
ProxyGet(heapsterService, metricPath, map[string]string{"start": startTime.Format(time.RFC3339)}).
resultRaw, err := h.client.Services(h.heapsterNamespace).
ProxyGet(h.heapsterService, metricPath, map[string]string{"start": startTime.Format(time.RFC3339)}).
DoRaw()
if err != nil {

View File

@ -148,7 +148,7 @@ func (tc *testCase) verifyResults(t *testing.T, val *ResourceConsumption, err er
func (tc *testCase) runTest(t *testing.T) {
testClient := tc.prepareTestClient(t)
metricsClient := NewHeapsterMetricsClient(testClient)
metricsClient := NewHeapsterMetricsClient(testClient, DefaultHeapsterNamespace, DefaultHeapsterService)
val, _, err := metricsClient.GetResourceConsumptionAndRequest(tc.targetResource, tc.namespace, tc.selector)
tc.verifyResults(t, val, err)
}