fix: move kubernetes autoscaling to v2
Signed-off-by: Matthew Clarke <mclarke@spotify.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import { V1ConfigMap } from '@kubernetes/client-node';
|
||||
import { V1CronJob } from '@kubernetes/client-node';
|
||||
import { V1DaemonSet } from '@kubernetes/client-node';
|
||||
import { V1Deployment } from '@kubernetes/client-node';
|
||||
import { V1HorizontalPodAutoscaler } from '@kubernetes/client-node';
|
||||
import { V1Ingress } from '@kubernetes/client-node';
|
||||
import { V1Job } from '@kubernetes/client-node';
|
||||
import { V1LimitRange } from '@kubernetes/client-node';
|
||||
@@ -23,6 +22,7 @@ import { V1ReplicaSet } from '@kubernetes/client-node';
|
||||
import { V1ResourceQuota } from '@kubernetes/client-node';
|
||||
import { V1Service } from '@kubernetes/client-node';
|
||||
import { V1StatefulSet } from '@kubernetes/client-node';
|
||||
import { V2HorizontalPodAutoscaler } from '@kubernetes/client-node';
|
||||
|
||||
// @public
|
||||
export const ANNOTATION_KUBERNETES_API_SERVER = 'kubernetes.io/api-server';
|
||||
@@ -192,7 +192,7 @@ export interface DeploymentResources {
|
||||
// (undocumented)
|
||||
deployments: V1Deployment[];
|
||||
// (undocumented)
|
||||
horizontalPodAutoscalers: V1HorizontalPodAutoscaler[];
|
||||
horizontalPodAutoscalers: V2HorizontalPodAutoscaler[];
|
||||
// (undocumented)
|
||||
pods: V1Pod[];
|
||||
// (undocumented)
|
||||
@@ -294,7 +294,7 @@ export const groupResponses: (
|
||||
// @public (undocumented)
|
||||
export interface HorizontalPodAutoscalersFetchResponse {
|
||||
// (undocumented)
|
||||
resources: Array<V1HorizontalPodAutoscaler>;
|
||||
resources: Array<V2HorizontalPodAutoscaler>;
|
||||
// (undocumented)
|
||||
type: 'horizontalpodautoscalers';
|
||||
}
|
||||
|
||||
@@ -1,32 +1,77 @@
|
||||
{
|
||||
"apiVersion": "autoscaling/v2",
|
||||
"kind": "HorizontalPodAutoscaler",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"autoscaling.alpha.kubernetes.io/conditions": "[{\"type\":\"AbleToScale\",\"status\":\"True\",\"lastTransitionTime\":\"2020-09-28T13:28:15Z\",\"reason\":\"SucceededGetScale\",\"message\":\"the HPA controller was able to get the target's current scale\"},{\"type\":\"ScalingActive\",\"status\":\"False\",\"lastTransitionTime\":\"2020-09-28T13:28:15Z\",\"reason\":\"FailedGetResourceMetric\",\"message\":\"the HPA was unable to compute the replica count: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)\"}]",
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"autoscaling/v1\",\"kind\":\"HorizontalPodAutoscaler\",\"metadata\":{\"annotations\":{},\"labels\":{\"backstage.io/kubernetes-id\":\"dice-roller\"},\"name\":\"dice-roller\",\"namespace\":\"default\"},\"spec\":{\"maxReplicas\":15,\"minReplicas\":10,\"scaleTargetRef\":{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"name\":\"dice-roller\"},\"targetCPUUtilizationPercentage\":50}}\n"
|
||||
},
|
||||
"creationTimestamp": "2020-09-28T13:28:00.000Z",
|
||||
"annotations": {},
|
||||
"creationTimestamp": "2024-02-13T20:13:52Z",
|
||||
"labels": {
|
||||
"backstage.io/kubernetes-id": "dice-roller"
|
||||
},
|
||||
"name": "dice-roller",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "698957",
|
||||
"selfLink": "/apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers/dice-roller",
|
||||
"uid": "a70c8a90-5605-4d7d-adea-05cfb8d9d446"
|
||||
"resourceVersion": "6717s736",
|
||||
"uid": "a34c90e1-8e8f-407f-b4c5-b4543bd56c1b"
|
||||
},
|
||||
"spec": {
|
||||
"maxReplicas": 15,
|
||||
"minReplicas": 10,
|
||||
"maxReplicas": 2,
|
||||
"metrics": [
|
||||
{
|
||||
"resource": {
|
||||
"name": "cpu",
|
||||
"target": {
|
||||
"averageUtilization": 50,
|
||||
"type": "Utilization"
|
||||
}
|
||||
},
|
||||
"type": "Resource"
|
||||
}
|
||||
],
|
||||
"minReplicas": 1,
|
||||
"scaleTargetRef": {
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"name": "dice-roller"
|
||||
},
|
||||
"targetCPUUtilizationPercentage": 50
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"currentReplicas": 13,
|
||||
"desiredReplicas": 14,
|
||||
"currentCPUUtilizationPercentage": 30
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2024-05-17T19:50:35Z",
|
||||
"message": "recent recommendations were higher than current one, applying the highest recent recommendation",
|
||||
"reason": "ScaleDownStabilized",
|
||||
"status": "True",
|
||||
"type": "AbleToScale"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2024-05-16T06:21:01Z",
|
||||
"message": "the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)",
|
||||
"reason": "ValidMetricFound",
|
||||
"status": "True",
|
||||
"type": "ScalingActive"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2024-05-16T06:21:01Z",
|
||||
"message": "the desired replica count is more than the maximum replica count",
|
||||
"reason": "TooManyReplicas",
|
||||
"status": "True",
|
||||
"type": "ScalingLimited"
|
||||
}
|
||||
],
|
||||
"currentMetrics": [
|
||||
{
|
||||
"resource": {
|
||||
"current": {
|
||||
"averageUtilization": 100,
|
||||
"averageValue": "50m",
|
||||
"value": "100m"
|
||||
},
|
||||
"name": "cpu"
|
||||
},
|
||||
"type": "Resource"
|
||||
}
|
||||
],
|
||||
"currentReplicas": 2,
|
||||
"desiredReplicas": 2,
|
||||
"lastScaleTime": "2024-02-13T20:14:23Z"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,77 @@
|
||||
{
|
||||
"apiVersion": "autoscaling/v2",
|
||||
"kind": "HorizontalPodAutoscaler",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"autoscaling.alpha.kubernetes.io/conditions": "[{\"type\":\"AbleToScale\",\"status\":\"True\",\"lastTransitionTime\":\"2020-09-28T13:28:15Z\",\"reason\":\"SucceededGetScale\",\"message\":\"the HPA controller was able to get the target's current scale\"},{\"type\":\"ScalingActive\",\"status\":\"False\",\"lastTransitionTime\":\"2020-09-28T13:28:15Z\",\"reason\":\"FailedGetResourceMetric\",\"message\":\"the HPA was unable to compute the replica count: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)\"}]",
|
||||
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"autoscaling/v1\",\"kind\":\"HorizontalPodAutoscaler\",\"metadata\":{\"annotations\":{},\"labels\":{\"backstage.io/kubernetes-id\":\"dice-roller\"},\"name\":\"dice-roller\",\"namespace\":\"default\"},\"spec\":{\"maxReplicas\":15,\"minReplicas\":10,\"scaleTargetRef\":{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"name\":\"dice-roller\"},\"targetCPUUtilizationPercentage\":50}}\n"
|
||||
},
|
||||
"creationTimestamp": "2020-09-28T13:28:00.000Z",
|
||||
"annotations": {},
|
||||
"creationTimestamp": "2024-02-13T20:13:52Z",
|
||||
"labels": {
|
||||
"backstage.io/kubernetes-id": "dice-roller"
|
||||
},
|
||||
"name": "dice-roller",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "698957",
|
||||
"selfLink": "/apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers/dice-roller",
|
||||
"uid": "a70c8a90-5605-4d7d-adea-05cfb8d9d446"
|
||||
"resourceVersion": "6717s736",
|
||||
"uid": "a34c90e1-8e8f-407f-b4c5-b4543bd56c1b"
|
||||
},
|
||||
"spec": {
|
||||
"maxReplicas": 10,
|
||||
"minReplicas": 5,
|
||||
"maxReplicas": 2,
|
||||
"metrics": [
|
||||
{
|
||||
"resource": {
|
||||
"name": "cpu",
|
||||
"target": {
|
||||
"averageUtilization": 50,
|
||||
"type": "Utilization"
|
||||
}
|
||||
},
|
||||
"type": "Resource"
|
||||
}
|
||||
],
|
||||
"minReplicas": 1,
|
||||
"scaleTargetRef": {
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"name": "dice-roller"
|
||||
},
|
||||
"targetCPUUtilizationPercentage": 70
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"currentReplicas": 10,
|
||||
"desiredReplicas": 10,
|
||||
"currentCPUUtilizationPercentage": 100
|
||||
"conditions": [
|
||||
{
|
||||
"lastTransitionTime": "2024-05-17T19:50:35Z",
|
||||
"message": "recent recommendations were higher than current one, applying the highest recent recommendation",
|
||||
"reason": "ScaleDownStabilized",
|
||||
"status": "True",
|
||||
"type": "AbleToScale"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2024-05-16T06:21:01Z",
|
||||
"message": "the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)",
|
||||
"reason": "ValidMetricFound",
|
||||
"status": "True",
|
||||
"type": "ScalingActive"
|
||||
},
|
||||
{
|
||||
"lastTransitionTime": "2024-05-16T06:21:01Z",
|
||||
"message": "the desired replica count is more than the maximum replica count",
|
||||
"reason": "TooManyReplicas",
|
||||
"status": "True",
|
||||
"type": "ScalingLimited"
|
||||
}
|
||||
],
|
||||
"currentMetrics": [
|
||||
{
|
||||
"resource": {
|
||||
"current": {
|
||||
"averageUtilization": 100,
|
||||
"averageValue": "50m",
|
||||
"value": "100m"
|
||||
},
|
||||
"name": "cpu"
|
||||
},
|
||||
"type": "Resource"
|
||||
}
|
||||
],
|
||||
"currentReplicas": 2,
|
||||
"desiredReplicas": 2,
|
||||
"lastScaleTime": "2024-02-13T20:14:23Z"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import {
|
||||
V1Pod,
|
||||
V1Deployment,
|
||||
V1HorizontalPodAutoscaler,
|
||||
V2HorizontalPodAutoscaler,
|
||||
} from '@kubernetes/client-node';
|
||||
import { detectErrors } from './error-detection';
|
||||
import * as healthyPod from './__fixtures__/pod.json';
|
||||
@@ -61,7 +61,7 @@ const oneDeployment = (deployment: V1Deployment): ObjectsByEntityResponse => {
|
||||
});
|
||||
};
|
||||
|
||||
const oneHpa = (hpa: V1HorizontalPodAutoscaler): ObjectsByEntityResponse => {
|
||||
const oneHpa = (hpa: V2HorizontalPodAutoscaler): ObjectsByEntityResponse => {
|
||||
return oneItem({
|
||||
type: 'horizontalpodautoscalers',
|
||||
resources: [hpa],
|
||||
@@ -328,7 +328,7 @@ describe('detectErrors', () => {
|
||||
|
||||
expect(err1).toStrictEqual({
|
||||
sourceRef: {
|
||||
apiGroup: 'autoscaling/v1',
|
||||
apiGroup: 'autoscaling/v2',
|
||||
kind: 'HorizontalPodAutoscaler',
|
||||
name: 'dice-roller',
|
||||
namespace: 'default',
|
||||
|
||||
@@ -21,7 +21,7 @@ import { detectErrorsInPods } from './pods';
|
||||
import { detectErrorsInDeployments } from './deployments';
|
||||
import { detectErrorsInHpa } from './hpas';
|
||||
import { Deployment } from 'kubernetes-models/apps/v1';
|
||||
import { HorizontalPodAutoscaler } from 'kubernetes-models/autoscaling/v1';
|
||||
import { HorizontalPodAutoscaler } from 'kubernetes-models/autoscaling/v2';
|
||||
import { Pod } from 'kubernetes-models/v1';
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HorizontalPodAutoscaler } from 'kubernetes-models/autoscaling/v1';
|
||||
import { HorizontalPodAutoscaler } from 'kubernetes-models/autoscaling/v2';
|
||||
import { DetectedError, ErrorMapper } from './types';
|
||||
import { detectErrorsInObjects } from './common';
|
||||
|
||||
@@ -35,7 +35,7 @@ const hpaErrorMappers: ErrorMapper<HorizontalPodAutoscaler>[] = [
|
||||
name: hpa.metadata?.name ?? 'unknown hpa',
|
||||
namespace: hpa.metadata?.namespace ?? 'unknown namespace',
|
||||
kind: 'HorizontalPodAutoscaler',
|
||||
apiGroup: 'autoscaling/v1',
|
||||
apiGroup: 'autoscaling/v2',
|
||||
},
|
||||
occurrenceCount: 1,
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
V1CronJob,
|
||||
V1DaemonSet,
|
||||
V1Deployment,
|
||||
V1HorizontalPodAutoscaler,
|
||||
V2HorizontalPodAutoscaler,
|
||||
V1Ingress,
|
||||
V1Job,
|
||||
V1LimitRange,
|
||||
@@ -186,7 +186,7 @@ export interface ResourceQuotaFetchResponse {
|
||||
/** @public */
|
||||
export interface HorizontalPodAutoscalersFetchResponse {
|
||||
type: 'horizontalpodautoscalers';
|
||||
resources: Array<V1HorizontalPodAutoscaler>;
|
||||
resources: Array<V2HorizontalPodAutoscaler>;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
@@ -282,7 +282,7 @@ export interface DeploymentResources {
|
||||
pods: V1Pod[];
|
||||
replicaSets: V1ReplicaSet[];
|
||||
deployments: V1Deployment[];
|
||||
horizontalPodAutoscalers: V1HorizontalPodAutoscaler[];
|
||||
horizontalPodAutoscalers: V2HorizontalPodAutoscaler[];
|
||||
}
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user