diff --git a/resource_customizations/keda.sh/ScaledObject/health.lua b/resource_customizations/keda.sh/ScaledObject/health.lua new file mode 100644 index 000000000000..84cc5ad17a43 --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/health.lua @@ -0,0 +1,35 @@ +local hs = {} +local healthy = false +local degraded = false +local suspended = false +if obj.status ~= nil then + if obj.status.conditions ~= nil then + for i, condition in ipairs(obj.status.conditions) do + if condition.status == "False" and condition.type == "Ready" then + hs.message = condition.message + degraded = true + end + if condition.status == "True" and condition.type == "Ready" then + hs.message = condition.message + healthy = true + end + if condition.status == "True" and condition.type == "Paused" then + hs.message = condition.message + suspended = true + end + end + end +end +if degraded == true then + hs.status = "Degraded" + return hs +elseif healthy == true and suspended == false then + hs.status = "Healthy" + return hs +elseif healthy == true and suspended == true then + hs.status = "Suspended" + return hs +end +hs.status = "Progressing" +hs.message = "Creating HorizontalPodAutoscaler Object" +return hs \ No newline at end of file diff --git a/resource_customizations/keda.sh/ScaledObject/health_test.yaml b/resource_customizations/keda.sh/ScaledObject/health_test.yaml new file mode 100644 index 000000000000..969334650ba1 --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/health_test.yaml @@ -0,0 +1,21 @@ +tests: +- healthStatus: + status: Progressing + message: "Creating HorizontalPodAutoscaler Object" + inputPath: testdata/keda-progressing.yaml +- healthStatus: + status: Degraded + message: "ScaledObject doesn't have correct Idle/Min/Max Replica Counts specification" + inputPath: testdata/keda-degraded-1.yaml +- healthStatus: + status: Degraded + message: "ScaledObject doesn't have correct triggers specification" + inputPath: testdata/keda-degraded.yaml +- healthStatus: + status: Healthy + message: "ScaledObject is defined correctly and is ready for scaling" + inputPath: testdata/keda-healthy.yaml +- healthStatus: + status: Suspended + message: "ScaledObject is paused" + inputPath: testdata/keda-suspended.yaml diff --git a/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded-1.yaml b/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded-1.yaml new file mode 100644 index 000000000000..3c3aba78a16a --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded-1.yaml @@ -0,0 +1,52 @@ +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + annotations: + finalizers: + - finalizer.keda.sh + labels: + argocd.argoproj.io/instance: keda-default + name: keda + namespace: keda + resourceVersion: '160591442' + uid: 73ee438a-f383-43f3-9346-b901d9773f4b +spec: + maxReplicaCount: 3 + minReplicaCount: 0 + scaleTargetRef: + name: keda + triggers: + - metadata: + desiredReplicas: '1' + end: 00 17 * * 1-5 + start: 00 08 * * 1-5 + timezone: Europe/Stockholm + type: cron +status: + conditions: + - message: >- + ScaledObject doesn't have correct Idle/Min/Max Replica Counts specification + reason: ScaledObjectCheckFailed + status: 'False' + type: Ready + - message: ScaledObject check failed + reason: UnknownState + status: Unknown + type: Active + - message: No fallbacks are active on this scaled object + reason: NoFallbackFound + status: 'False' + type: Fallback + - status: Unknown + type: Paused + externalMetricNames: + - s0-cron-Europe-Stockholm-0008xx1-5-0019xx1-5 + hpaName: keda-hpa + lastActiveTime: '2023-12-18T17:59:55Z' + originalReplicaCount: 1 + scaleTargetGVKR: + group: apps + kind: Deployment + resource: deployments + version: v1 + scaleTargetKind: apps/v1.Deployment \ No newline at end of file diff --git a/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded.yaml b/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded.yaml new file mode 100644 index 000000000000..4996905fed7f --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/testdata/keda-degraded.yaml @@ -0,0 +1,51 @@ +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + annotations: + finalizers: + - finalizer.keda.sh + labels: + argocd.argoproj.io/instance: keda-default + name: keda + namespace: keda + resourceVersion: '160591442' + uid: 73ee438a-f383-43f3-9346-b901d9773f4b +spec: + maxReplicaCount: 3 + minReplicaCount: 0 + scaleTargetRef: + name: keda + triggers: + - metadata: + desiredReplicas: '1' + end: 00 17 * * 1-5 + start: 00 08 * * 1-5 + timezone: Europe/Stockholm + type: cron +status: + conditions: + - message: ScaledObject doesn't have correct triggers specification + reason: ScaledObjectCheckFailed + status: 'False' + type: Ready + - message: Scaling is not performed because triggers are not active + reason: ScalerNotActive + status: 'False' + type: Active + - message: No fallbacks are active on this scaled object + reason: NoFallbackFound + status: 'False' + type: Fallback + - status: Unknown + type: Paused + externalMetricNames: + - s0-cron-Europe-Stockholm-0008xx1-5-0019xx1-5 + hpaName: keda-hpa + lastActiveTime: '2023-12-18T17:59:55Z' + originalReplicaCount: 1 + scaleTargetGVKR: + group: apps + kind: Deployment + resource: deployments + version: v1 + scaleTargetKind: apps/v1.Deployment \ No newline at end of file diff --git a/resource_customizations/keda.sh/ScaledObject/testdata/keda-healthy.yaml b/resource_customizations/keda.sh/ScaledObject/testdata/keda-healthy.yaml new file mode 100644 index 000000000000..38bd24dc1953 --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/testdata/keda-healthy.yaml @@ -0,0 +1,51 @@ +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + annotations: + finalizers: + - finalizer.keda.sh + labels: + argocd.argoproj.io/instance: keda-default + name: keda + namespace: keda + resourceVersion: '160591442' + uid: 73ee438a-f383-43f3-9346-b901d9773f4b +spec: + maxReplicaCount: 3 + minReplicaCount: 0 + scaleTargetRef: + name: backstage + triggers: + - metadata: + desiredReplicas: '1' + end: 00 17 * * 1-5 + start: 00 08 * * 1-5 + timezone: Europe/Stockholm + type: cron +status: + conditions: + - message: ScaledObject is defined correctly and is ready for scaling + reason: ScaledObjectReady + status: 'True' + type: Ready + - message: Scaling is not performed because triggers are not active + reason: ScalerNotActive + status: 'False' + type: Active + - message: No fallbacks are active on this scaled object + reason: NoFallbackFound + status: 'False' + type: Fallback + - status: Unknown + type: Paused + externalMetricNames: + - s0-cron-Europe-Stockholm-0008xx1-5-0019xx1-5 + hpaName: keda-hpa-backstage-kambi-standard-chart + lastActiveTime: '2023-12-18T17:59:55Z' + originalReplicaCount: 1 + scaleTargetGVKR: + group: apps + kind: Deployment + resource: deployments + version: v1 + scaleTargetKind: apps/v1.Deployment \ No newline at end of file diff --git a/resource_customizations/keda.sh/ScaledObject/testdata/keda-progressing.yaml b/resource_customizations/keda.sh/ScaledObject/testdata/keda-progressing.yaml new file mode 100644 index 000000000000..2206bfbff97f --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/testdata/keda-progressing.yaml @@ -0,0 +1,30 @@ +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + annotations: + finalizers: + - finalizer.keda.sh + labels: + argocd.argoproj.io/instance: keda-default + name: keda + namespace: keda + resourceVersion: '160591442' + uid: 73ee438a-f383-43f3-9346-b901d9773f4b +spec: + maxReplicaCount: 3 + minReplicaCount: 0 + scaleTargetRef: + name: backstage + triggers: + - metadata: + desiredReplicas: '1' + end: 00 17 * * 1-5 + start: 00 08 * * 1-5 + timezone: Europe/Stockholm + type: cron +status: + conditions: + - message: Creating HorizontalPodAutoscaler Object + reason: Running + status: 'True' + type: Running \ No newline at end of file diff --git a/resource_customizations/keda.sh/ScaledObject/testdata/keda-suspended.yaml b/resource_customizations/keda.sh/ScaledObject/testdata/keda-suspended.yaml new file mode 100644 index 000000000000..a2d0b2b5dcf6 --- /dev/null +++ b/resource_customizations/keda.sh/ScaledObject/testdata/keda-suspended.yaml @@ -0,0 +1,51 @@ +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + annotations: + finalizers: + - finalizer.keda.sh + labels: + argocd.argoproj.io/instance: keda-default + name: keda + namespace: keda + resourceVersion: '160591442' + uid: 73ee438a-f383-43f3-9346-b901d9773f4b +spec: + maxReplicaCount: 3 + minReplicaCount: 0 + scaleTargetRef: + name: backstage + triggers: + - metadata: + desiredReplicas: '1' + end: 00 17 * * 1-5 + start: 00 08 * * 1-5 + timezone: Europe/Stockholm + type: cron +status: + conditions: + - message: ScaledObject is defined correctly and is ready for scaling + reason: ScaledObjectReady + status: 'True' + type: Ready + - message: ScaledObject check failed + reason: UnknownState + status: Unknown + type: Active + - status: Unknown + type: Fallback + - message: ScaledObject is paused + reason: ScaledObjectPaused + status: 'True' + type: Paused + externalMetricNames: + - s0-cron-Europe-Stockholm-0008xx1-5-0019xx1-5 + hpaName: keda-hpa-backstage-kambi-standard-chart + lastActiveTime: '2023-12-18T17:59:55Z' + originalReplicaCount: 1 + scaleTargetGVKR: + group: apps + kind: Deployment + resource: deployments + version: v1 + scaleTargetKind: apps/v1.Deployment \ No newline at end of file