How kubernetes maintains different api version resource?

12/4/2019

Kubernetes versions:

v1.15.2

Scenario shows:

kubernetes v1.15.2 have added some new api versions,for example, the autoscaling/v2beta2 in the autoscaling group. But after read the HorizontalController structure in kubernetes code src\k8s.io\kubernetes\pkg\controller\podautoscaler\, All the members in HorizontalController is autoscaling/v1.

type HorizontalController struct {
    scaleNamespacer scaleclient.ScalesGetter                                ==> autoscaling/v1
    hpaNamespacer   autoscalingclient.HorizontalPodAutoscalersGetter        ==> autoscaling/v1
    mapper          apimeta.RESTMapper

    replicaCalc   *ReplicaCalculator
    eventRecorder record.EventRecorder

    downscaleStabilisationWindow time.Duration

    // hpaLister is able to list/get HPAs from the shared cache from the informer passed in to
    // NewHorizontalController.
    hpaLister       autoscalinglisters.HorizontalPodAutoscalerLister        ==> autoscaling/v1
    hpaListerSynced cache.InformerSynced                                    ==> autoscaling/v1

    // podLister is able to list/get Pods from the shared cache from the informer passed in to
    // NewHorizontalController.
    podLister       corelisters.PodLister
    podListerSynced cache.InformerSynced

    // Controllers that need to be synced
    queue workqueue.RateLimitingInterface

    // Latest unstabilized recommendations for each autoscaler.
    recommendations map[string][]timestampedRecommendation
}

So how kubernetes maintans the autoscaling/v2beta2 resources with HorizontalController?

-- Miro
api-design
autoscaling
kubernetes

1 Answer

12/4/2019

In the official kubernetes documentation You can find following information:

API Object

The Horizontal Pod Autoscaler is an API resource in the Kubernetes autoscaling API group. The current stable version, which only includes support for CPU autoscaling, can be found in the autoscaling/v1 API version.

The beta version, which includes support for scaling on memory and custom metrics, can be found in autoscaling/v2beta2. The new fields introduced in autoscaling/v2beta2 are preserved as annotations when working with autoscaling/v1.

More details about the API object can be found at HorizontalPodAutoscaler Object.

Also according to kubernetes documentation about API overview under API versioning:

API versioning

To eliminate fields or restructure resource representations, Kubernetes supports multiple API versions, each at a different API path. For example: /api/v1 or /apis/extensions/v1beta1.

The version is set at the API level rather than at the resource or field level to:

  • Ensure that the API presents a clear and consistent view of system resources and behavior.
  • Enable control access to end-of-life and/or experimental APIs.

The JSON and Protobuf serialization schemas follow the same guidelines for schema changes. The following descriptions cover both formats.


So You can find all apis versions for autoscaling like v2beta2 under kubernetes/pkg/apis/autoscaling/ .

For example using HTTP GET would be like this: GET /apis/autoscaling/v2beta2

-- Piotr Malec
Source: StackOverflow