@@ -77,6 +77,9 @@ func SetScalingValues(templateMap map[string]interface{}, customScalingKey strin
7777 return merged , errors .New (fmt .Sprintf ("no json path found for [%s]" , customScalingKey ))
7878 }
7979 autoscalingJsonPathKey := autoscalingJsonPath .(string )
80+ if len (autoscalingJsonPathKey ) == 0 {
81+ return merged , nil
82+ }
8083 mergedRes , err := sjson .Set (string (merged ), autoscalingJsonPathKey , value )
8184 if err != nil {
8285 return merged , err
@@ -97,6 +100,7 @@ func FetchRequiredReplicaCount(currentReplicaCount float64, reqMaxReplicas float
97100}
98101
99102func GetAutoScalingReplicaCount (templateMap map [string ]interface {}, appName string ) * util4.HpaResourceRequest {
103+ hpaResourceRequest := & util4.HpaResourceRequest {}
100104 hasOverride := false
101105 if _ , ok := templateMap [bean3 .FullnameOverride ]; ok {
102106 appNameOverride := templateMap [bean3 .FullnameOverride ].(string )
@@ -113,37 +117,66 @@ func GetAutoScalingReplicaCount(templateMap map[string]interface{}, appName stri
113117 }
114118 }
115119 }
116- hpaResourceRequest := & util4.HpaResourceRequest {}
117120 hpaResourceRequest .Version = ""
118121 hpaResourceRequest .Group = autoscaling .ServiceName
119122 hpaResourceRequest .Kind = bean3 .HorizontalPodAutoscaler
120123 if _ , ok := templateMap [bean3 .KedaAutoscaling ]; ok {
121124 as := templateMap [bean3 .KedaAutoscaling ]
122- asd := as .(map [string ]interface {})
125+ asd , ok := as .(map [string ]interface {})
126+ if ! ok {
127+ return hpaResourceRequest
128+ }
123129 if _ , ok := asd [bean3 .Enabled ]; ok {
124- enable := asd [bean3 .Enabled ].(bool )
130+ enable , ok := asd [bean3 .Enabled ].(bool )
131+ if ! ok {
132+ return hpaResourceRequest
133+ }
125134 if enable {
126- hpaResourceRequest .IsEnable = enable
127- hpaResourceRequest .ReqReplicaCount = templateMap [bean3 .ReplicaCount ].(float64 )
128- hpaResourceRequest .ReqMaxReplicas = asd ["maxReplicaCount" ].(float64 )
129- hpaResourceRequest .ReqMinReplicas = asd ["minReplicaCount" ].(float64 )
130135 hpaResourceRequest .ResourceName = fmt .Sprintf ("%s-%s-%s" , "keda-hpa" , appName , "keda" )
136+ hpaResourceRequest .ReqReplicaCount , ok = templateMap [bean3 .ReplicaCount ].(float64 )
137+ if ! ok {
138+ return hpaResourceRequest
139+ }
140+ hpaResourceRequest .ReqMaxReplicas , ok = asd ["maxReplicaCount" ].(float64 )
141+ if ! ok {
142+ return hpaResourceRequest
143+ }
144+ hpaResourceRequest .ReqMinReplicas , ok = asd ["minReplicaCount" ].(float64 )
145+ if ! ok {
146+ return hpaResourceRequest
147+ }
148+ hpaResourceRequest .IsEnable = true
131149 return hpaResourceRequest
132150 }
133151 }
134152 }
135153
136154 if _ , ok := templateMap [autoscaling .ServiceName ]; ok {
137155 as := templateMap [autoscaling .ServiceName ]
138- asd := as .(map [string ]interface {})
156+ asd , ok := as .(map [string ]interface {})
157+ if ! ok {
158+ return hpaResourceRequest
159+ }
139160 if _ , ok := asd [bean3 .Enabled ]; ok {
140- enable := asd [bean3 .Enabled ].(bool )
161+ enable , ok := asd [bean3 .Enabled ].(bool )
162+ if ! ok {
163+ return hpaResourceRequest
164+ }
141165 if enable {
142- hpaResourceRequest .IsEnable = asd [bean3 .Enabled ].(bool )
143- hpaResourceRequest .ReqReplicaCount = templateMap [bean3 .ReplicaCount ].(float64 )
144- hpaResourceRequest .ReqMaxReplicas = asd ["MaxReplicas" ].(float64 )
145- hpaResourceRequest .ReqMinReplicas = asd ["MinReplicas" ].(float64 )
146166 hpaResourceRequest .ResourceName = fmt .Sprintf ("%s-%s" , appName , "hpa" )
167+ hpaResourceRequest .ReqReplicaCount , ok = templateMap [bean3 .ReplicaCount ].(float64 )
168+ if ! ok {
169+ return hpaResourceRequest
170+ }
171+ hpaResourceRequest .ReqMaxReplicas , ok = asd ["MaxReplicas" ].(float64 )
172+ if ! ok {
173+ return hpaResourceRequest
174+ }
175+ hpaResourceRequest .ReqMinReplicas , ok = asd ["MinReplicas" ].(float64 )
176+ if ! ok {
177+ return hpaResourceRequest
178+ }
179+ hpaResourceRequest .IsEnable = true
147180 return hpaResourceRequest
148181 }
149182 }
0 commit comments