@soft-stech/keda
Version:
KEDA(Kubernetes Event-driven Autoscaling) models
323 lines (322 loc) • 12.9 kB
JavaScript
import { z } from "zod";
import { iObjectMetaSchema } from "@soft-stech/apimachinery/apis/meta/v1/ObjectMeta.schema";
/**
* ScaledObject is a specification for a ScaledObject resource
*/
export const IScaledObjectSchema = z.object({
/**
* APIVersion defines the versioned schema of this representation of an object.
* Servers should convert recognized schemas to the latest internal value, and
* may reject unrecognized values.
* More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
*/
apiVersion: z.literal("keda.sh/v1alpha1"),
/**
* Kind is a string value representing the REST resource this object represents.
* Servers may infer this from the endpoint the client submits requests to.
* Cannot be updated.
* In CamelCase.
* More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
*/
kind: z.literal("ScaledObject"),
metadata: iObjectMetaSchema.optional(),
/**
* ScaledObjectSpec is the spec for a ScaledObject resource
*/
spec: z.object({
/**
* AdvancedConfig specifies advance scaling options
*/
advanced: z
.object({
/**
* HorizontalPodAutoscalerConfig specifies horizontal scale config
*/
horizontalPodAutoscalerConfig: z
.object({
/**
* HorizontalPodAutoscalerBehavior configures the scaling behavior of the target
* in both Up and Down directions (scaleUp and scaleDown fields respectively).
*/
behavior: z
.object({
/**
* scaleDown is scaling policy for scaling Down.
* If not set, the default value is to allow to scale down to minReplicas pods, with a
* 300 second stabilization window (i.e., the highest recommendation for
* the last 300sec is used).
*/
scaleDown: z
.object({
/**
* policies is a list of potential scaling polices which can be used during scaling.
* At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid
*/
policies: z
.array(z.object({
/**
* periodSeconds specifies the window of time for which the policy should hold true.
* PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).
* @format int32
*/
periodSeconds: z.int32(),
/**
* type is used to specify the scaling policy.
*/
type: z.string(),
/**
* value contains the amount of change which is permitted by the policy.
* It must be greater than zero
* @format int32
*/
value: z.int32()
}))
.optional(),
/**
* selectPolicy is used to specify which policy should be used.
* If not set, the default value Max is used.
*/
selectPolicy: z.string().optional(),
/**
* stabilizationWindowSeconds is the number of seconds for which past recommendations should be
* considered while scaling up or scaling down.
* StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour).
* If not set, use the default values:
* - For scale up: 0 (i.e. no stabilization is done).
* - For scale down: 300 (i.e. the stabilization window is 300 seconds long).
* @maximum 3600
* @format int32
*/
stabilizationWindowSeconds: z.int32().max(3600).optional()
})
.optional(),
/**
* scaleUp is scaling policy for scaling Up.
* If not set, the default value is the higher of:
* \* increase no more than 4 pods per 60 seconds
* \* double the number of pods per 60 seconds
* No stabilization is used.
*/
scaleUp: z
.object({
/**
* policies is a list of potential scaling polices which can be used during scaling.
* At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid
*/
policies: z
.array(z.object({
/**
* periodSeconds specifies the window of time for which the policy should hold true.
* PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).
* @format int32
*/
periodSeconds: z.int32(),
/**
* type is used to specify the scaling policy.
*/
type: z.string(),
/**
* value contains the amount of change which is permitted by the policy.
* It must be greater than zero
* @format int32
*/
value: z.int32()
}))
.optional(),
/**
* selectPolicy is used to specify which policy should be used.
* If not set, the default value Max is used.
*/
selectPolicy: z.string().optional(),
/**
* stabilizationWindowSeconds is the number of seconds for which past recommendations should be
* considered while scaling up or scaling down.
* StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour).
* If not set, use the default values:
* - For scale up: 0 (i.e. no stabilization is done).
* - For scale down: 300 (i.e. the stabilization window is 300 seconds long).
* @maximum 3600
* @format int32
*/
stabilizationWindowSeconds: z.int32().max(3600).optional()
})
.optional()
})
.optional(),
name: z.string().optional()
})
.optional(),
restoreToOriginalReplicaCount: z.boolean().optional(),
/**
* ScalingModifiers describes advanced scaling logic options like formula
*/
scalingModifiers: z
.object({
activationTarget: z.string().optional(),
formula: z.string().optional(),
/**
* MetricTargetType specifies the type of metric being targeted, and should be either
* "Value", "AverageValue", or "Utilization"
*/
metricType: z.string().optional(),
target: z.string().optional()
})
.optional()
})
.optional(),
/**
*
* @format int32
*/
cooldownPeriod: z.int32().optional(),
/**
* Fallback is the spec for fallback options
*/
fallback: z
.object({
/**
*
* @format int32
*/
failureThreshold: z.int32(),
/**
*
* @format int32
*/
replicas: z.int32()
})
.optional(),
/**
*
* @format int32
*/
idleReplicaCount: z.int32().optional(),
/**
*
* @format int32
*/
initialCooldownPeriod: z.int32().optional(),
/**
*
* @format int32
*/
maxReplicaCount: z.int32().optional(),
/**
*
* @format int32
*/
minReplicaCount: z.int32().optional(),
/**
*
* @format int32
*/
pollingInterval: z.int32().optional(),
/**
* ScaleTarget holds the reference to the scale target Object
*/
scaleTargetRef: z.object({
apiVersion: z.string().optional(),
envSourceContainerName: z.string().optional(),
kind: z.string().optional(),
name: z.string()
}),
triggers: z.array(z.object({
/**
* AuthenticationRef points to the TriggerAuthentication or ClusterTriggerAuthentication object that
* is used to authenticate the scaler with the environment
*/
authenticationRef: z
.object({
/**
* Kind of the resource being referred to. Defaults to TriggerAuthentication.
*/
kind: z.string().optional(),
name: z.string()
})
.optional(),
metadata: z.record(z.string(), z.string()),
/**
* MetricTargetType specifies the type of metric being targeted, and should be either
* "Value", "AverageValue", or "Utilization"
*/
metricType: z.string().optional(),
name: z.string().optional(),
type: z.string(),
useCachedMetrics: z.boolean().optional()
}))
}),
/**
* ScaledObjectStatus is the status for a ScaledObject resource
*/
status: z
.object({
compositeScalerName: z.string().optional(),
/**
* Conditions an array representation to store multiple Conditions
*/
conditions: z
.array(z.object({
/**
* A human readable message indicating details about the transition.
*/
message: z.string().optional(),
/**
* The reason for the condition's last transition.
*/
reason: z.string().optional(),
/**
* Status of the condition, one of True, False, Unknown.
*/
status: z.string(),
/**
* Type of condition
*/
type: z.string()
}))
.optional(),
externalMetricNames: z.array(z.string()).optional(),
health: z
.record(z.string(), z.object({
/**
*
* @format int32
*/
numberOfFailures: z.int32().optional(),
/**
* HealthStatusType is an indication of whether the health status is happy or failing
*/
status: z.string().optional()
}))
.optional(),
hpaName: z.string().optional(),
/**
*
* @format date-time
*/
lastActiveTime: z.iso.datetime().optional().nullable(),
/**
*
* @format int32
*/
originalReplicaCount: z.int32().optional(),
/**
*
* @format int32
*/
pausedReplicaCount: z.int32().optional(),
resourceMetricNames: z.array(z.string()).optional(),
/**
* GroupVersionKindResource provides unified structure for schema.GroupVersionKind and Resource
*/
scaleTargetGVKR: z
.object({
group: z.string(),
kind: z.string(),
resource: z.string(),
version: z.string()
})
.optional(),
scaleTargetKind: z.string().optional()
})
.optional()
});