Skip to content

Commit

Permalink
505: fail with message when webhook not enabled and minReplicas is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
imaffe committed Dec 5, 2022
1 parent 698546e commit 0442021
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,3 +1671,9 @@ func getFilenameOfComponentPackage(componentPackage string) string {
}
return componentPackage
}

func panicIfNil(value any, message string) {
if value == nil {
panic(message)
}
}
11 changes: 8 additions & 3 deletions controllers/spec/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ func makeBuiltinHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas int3
}
}

func makeHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas int32, podPolicy v1alpha1.PodPolicy, targetRef autov2beta2.CrossVersionObjectReference) *autov2beta2.HorizontalPodAutoscaler {
func makeHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas *int32, podPolicy v1alpha1.PodPolicy, targetRef autov2beta2.CrossVersionObjectReference) *autov2beta2.HorizontalPodAutoscaler {

panicIfNil(minReplicas, "MinReplicas should not be nil but is nil; This is likely because the webhook is not installed properly so it does not have a default value")
panicIfNil(maxReplicas, "MaxReplicas should not be nil but is nil; This is likely because the webhook is not installed properly so it does not have a default value")
min := *minReplicas
max := *maxReplicas
spec := autov2beta2.HorizontalPodAutoscalerSpec{
ScaleTargetRef: targetRef,
MinReplicas: &minReplicas,
MaxReplicas: maxReplicas,
MinReplicas: &min,
MaxReplicas: max,
Metrics: podPolicy.AutoScalingMetrics,
Behavior: podPolicy.AutoScalingBehavior,
}
Expand Down

0 comments on commit 0442021

Please sign in to comment.