Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/deployment/manifest/ManifestCreationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ func (impl *ManifestCreationServiceImpl) autoscalingCheckBeforeTrigger(ctx conte

hpaResourceRequest := helper.GetAutoScalingReplicaCount(templateMap, appName)
impl.logger.Debugw("autoscalingCheckBeforeTrigger", "pipelineId", pipelineId, "hpaResourceRequest", hpaResourceRequest)
if hpaResourceRequest.IsEnable {
if hpaResourceRequest != nil && hpaResourceRequest.IsEnable {
var resourceManifest map[string]interface{}

resourceManifest, err = impl.getK8sHPAResourceManifest(newCtx, clusterId, namespace, hpaResourceRequest)
Expand All @@ -991,7 +991,11 @@ func (impl *ManifestCreationServiceImpl) autoscalingCheckBeforeTrigger(ctx conte
}

if len(resourceManifest) > 0 {
statusMap := resourceManifest["status"].(map[string]interface{})
statusMap, ok := resourceManifest["status"].(map[string]interface{})
if !ok {
impl.logger.Warnw("error occurred while parsing hpa resource manifest, status is not a map", "resourceManifestStatus", resourceManifest["status"])
return merged, nil
}
currentReplicaVal := statusMap["currentReplicas"]
// currentReplicas key might not be available in manifest while k8s is calculating replica count
// it's a valid case so, we are not throwing error
Expand All @@ -1016,7 +1020,7 @@ func (impl *ManifestCreationServiceImpl) autoscalingCheckBeforeTrigger(ctx conte
impl.logger.Debugw("autoscaling is not enabled", "pipelineId", pipelineId)
}

//check for custom chart support
// check for custom chart support
if autoscalingEnabledPath, ok := templateMap[appBean.CustomAutoScalingEnabledPathKey]; ok {
if deploymentType == models.DEPLOYMENTTYPE_STOP {
merged, err = helper.SetScalingValues(templateMap, appBean.CustomAutoScalingEnabledPathKey, merged, false)
Expand Down
59 changes: 46 additions & 13 deletions pkg/deployment/manifest/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func SetScalingValues(templateMap map[string]interface{}, customScalingKey strin
return merged, errors.New(fmt.Sprintf("no json path found for [%s]", customScalingKey))
}
autoscalingJsonPathKey := autoscalingJsonPath.(string)
if len(autoscalingJsonPathKey) == 0 {
return merged, nil
}
mergedRes, err := sjson.Set(string(merged), autoscalingJsonPathKey, value)
if err != nil {
return merged, err
Expand All @@ -97,6 +100,7 @@ func FetchRequiredReplicaCount(currentReplicaCount float64, reqMaxReplicas float
}

func GetAutoScalingReplicaCount(templateMap map[string]interface{}, appName string) *util4.HpaResourceRequest {
hpaResourceRequest := &util4.HpaResourceRequest{}
hasOverride := false
if _, ok := templateMap[bean3.FullnameOverride]; ok {
appNameOverride := templateMap[bean3.FullnameOverride].(string)
Expand All @@ -113,37 +117,66 @@ func GetAutoScalingReplicaCount(templateMap map[string]interface{}, appName stri
}
}
}
hpaResourceRequest := &util4.HpaResourceRequest{}
hpaResourceRequest.Version = ""
hpaResourceRequest.Group = autoscaling.ServiceName
hpaResourceRequest.Kind = bean3.HorizontalPodAutoscaler
if _, ok := templateMap[bean3.KedaAutoscaling]; ok {
as := templateMap[bean3.KedaAutoscaling]
asd := as.(map[string]interface{})
asd, ok := as.(map[string]interface{})
if !ok {
return hpaResourceRequest
}
if _, ok := asd[bean3.Enabled]; ok {
enable := asd[bean3.Enabled].(bool)
enable, ok := asd[bean3.Enabled].(bool)
if !ok {
return hpaResourceRequest
}
if enable {
hpaResourceRequest.IsEnable = enable
hpaResourceRequest.ReqReplicaCount = templateMap[bean3.ReplicaCount].(float64)
hpaResourceRequest.ReqMaxReplicas = asd["maxReplicaCount"].(float64)
hpaResourceRequest.ReqMinReplicas = asd["minReplicaCount"].(float64)
hpaResourceRequest.ResourceName = fmt.Sprintf("%s-%s-%s", "keda-hpa", appName, "keda")
hpaResourceRequest.ReqReplicaCount, ok = templateMap[bean3.ReplicaCount].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.ReqMaxReplicas, ok = asd["maxReplicaCount"].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.ReqMinReplicas, ok = asd["minReplicaCount"].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.IsEnable = true
return hpaResourceRequest
}
}
}

if _, ok := templateMap[autoscaling.ServiceName]; ok {
as := templateMap[autoscaling.ServiceName]
asd := as.(map[string]interface{})
asd, ok := as.(map[string]interface{})
if !ok {
return hpaResourceRequest
}
if _, ok := asd[bean3.Enabled]; ok {
enable := asd[bean3.Enabled].(bool)
enable, ok := asd[bean3.Enabled].(bool)
if !ok {
return hpaResourceRequest
}
if enable {
hpaResourceRequest.IsEnable = asd[bean3.Enabled].(bool)
hpaResourceRequest.ReqReplicaCount = templateMap[bean3.ReplicaCount].(float64)
hpaResourceRequest.ReqMaxReplicas = asd["MaxReplicas"].(float64)
hpaResourceRequest.ReqMinReplicas = asd["MinReplicas"].(float64)
hpaResourceRequest.ResourceName = fmt.Sprintf("%s-%s", appName, "hpa")
hpaResourceRequest.ReqReplicaCount, ok = templateMap[bean3.ReplicaCount].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.ReqMaxReplicas, ok = asd["MaxReplicas"].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.ReqMinReplicas, ok = asd["MinReplicas"].(float64)
if !ok {
return hpaResourceRequest
}
hpaResourceRequest.IsEnable = true
return hpaResourceRequest
}
}
Expand Down