Skip to content

Instantly share code, notes, and snippets.

@orangedeng
Last active January 10, 2019 08:26
Show Gist options
  • Save orangedeng/4875007a967cb13570541aa7eb973700 to your computer and use it in GitHub Desktop.
Save orangedeng/4875007a967cb13570541aa7eb973700 to your computer and use it in GitHub Desktop.
HPA support design

HPA design

Feature/enhancement description

Support to Configure HorizontalPodAutoscaler in Rancher UI. And Support to configure HPA rules for deployment when we creating them.

Requirements

API and object model changes

TypeMeta

APIGroup autoscaling
Version v2beta2
Kind HorizontalPodAutoscaler

There are 3 versions for HorizontalPodAutoscaler.

  • v1 - only support cpu average for scaling metric. Since k8s 1.1
  • v2beta1 - support multiple metric type including cpu, memory and custom metrics. Only value and average value of target metric are supported. Since k8s 1.6
  • v2beta2 - Including v2beta1 and support Utilization metric type. Since k8s 1.12

So the best api verison for the HPA object is v2beta1

Rancher API Schema for HPA

HorizontalPodAutoscaler:

Name Type Create Update Null Required Remark
id dnsLabel
name string * * * (set id if null)
namespaceId dnsLabel
description string * * * annotation field
workloadId dnsLabel * * * workloadId will be translated into CrossVersionObjectReference
minReplicas int * * *
maxReplicas int * * *
metrics array[metricSpec] * * *
observedGeneration int64 from embed status field
lastScaleTime time from embed status field
currentReplicas int32 from embed status field
desiredReplicas int32 from embed status field
currentMetrics array[metricStatus] from embed status field
conditions array[condition] from embed status field, ScalingActive/AbleToScale/ScalingLimited

MetricSpec:

Name Type Create Update Null Required Remark
type enum Object,Pods,Resource,External
name dnsLabel use for type Object, Pods and External
selector labelSelector use for type Object, Pods and External
describedObject crossVersionObjectReference use for type Object
metricType enum metrics quantity type, value, averageValue and averageUtilization, if value or averageValue is set, the value should be in quantity format. If averageUtilization is set, value should be in number format
value string value for the metric
resourceName enum cpu, memory, storage and ephemeral-storage only used when type is Resource

MetricStatus:

Name Type Create Update Null Required Remark
type enum Object,Pods,Resource,External
name dnsLabel use for type Object, Pods and External
selector labelSelector use for type Object, Pods and External
describedObject crossVersionObjectReference use for type Object
metricType enum metrics quantity type, value, averageValue and averageUtilization
value quantity current value for the metric
resourceName enum cpu, memory, storage and ephemeral-storage only used when type is Resource

New field for deployment/replicaController for autoscaling.

Name Type Create Update Null Required Remark
scaling scaling * * * annotation field of deployment and replicaController

Scaling:

One scaling object will repect to one HPA object with several metrics in it.

Name Type Create Update Null Required Remark
minReplicas int * * *
maxReplicas int * * *
metrics array[scalingMetric] * * *

ScalingMetric:

Name Type Create Update Null Required Remark
name string only support cpu,memory
valueType enum only support averageUtilization, averageValue
value quantity the value to trigger scaling

Custom API logic

For HorizontalPodAutoscaler

  • Embed spec and status
  • Add description for resource object

For HorizontalPodAutoscalerSpec

  • Transform workloadId to scaleTargetRef. And only deployment and replicaController should be allowed to be set.

For MetricSpec

  • Embed objectMetricSource, podsMetricSource, resourceMetricSource and externalMetricStatus. Create new mapper to assign different value with different type.

For MetricStatus

  • Embed objectMetricStatus, podsMetricStatus, resourceMetricStatus and externalMetricStatus. Create new mapper to assign different value with different type.

Business logic changes

Adding new logic for workload.

  • Add new controllers for deployment and replicaController to handle the new autoscaling field.

RBAC

HorizontalPodAutoscaler is a namespaced resource. It has the same RBAC rules as other namespaced resources.

Other important design or architecture changes

Testing

Three aspect should be test when adding HPA object

  • For the deployment and replicaController, we should test the new annotation field. Each scaling should create a HPA object accordingly.
  • For the HPA resource, It should test the API translation from Rancher API to Kubernetes object is ok or not.
  • For the HPA, we should test the rules we set for scaling will work as expected.

Changelog

Review action items and notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment