Skip to content

Commit 4a1cc0f

Browse files
committed
505: fail with message when webhook not enabled and minReplicas is nil
1 parent 698546e commit 4a1cc0f

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

controllers/spec/common.go

+6
Original file line numberDiff line numberDiff line change
@@ -1671,3 +1671,9 @@ func getFilenameOfComponentPackage(componentPackage string) string {
16711671
}
16721672
return componentPackage
16731673
}
1674+
1675+
func panicIfNil(value interface{}, message string) {
1676+
if value == nil {
1677+
panic(message)
1678+
}
1679+
}

controllers/spec/function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func MakeFunctionHPA(function *v1alpha1.Function) *autov2beta2.HorizontalPodAuto
4141
return makeBuiltinHPA(objectMeta, *function.Spec.MinReplicas, *function.Spec.MaxReplicas, targetRef,
4242
function.Spec.Pod.BuiltinAutoscaler)
4343
} else if !isDefaultHPAEnabled(function.Spec.MinReplicas, function.Spec.MaxReplicas, function.Spec.Pod) {
44-
return makeHPA(objectMeta, *function.Spec.MinReplicas, *function.Spec.MaxReplicas, function.Spec.Pod, targetRef)
44+
return makeHPA(objectMeta, function.Spec.MinReplicas, function.Spec.MaxReplicas, function.Spec.Pod, targetRef)
4545
}
4646
return makeDefaultHPA(objectMeta, *function.Spec.MinReplicas, *function.Spec.MaxReplicas, targetRef)
4747
}

controllers/spec/hpa.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ func makeBuiltinHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas int3
154154
}
155155
}
156156

157-
func makeHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas int32, podPolicy v1alpha1.PodPolicy, targetRef autov2beta2.CrossVersionObjectReference) *autov2beta2.HorizontalPodAutoscaler {
157+
func makeHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas *int32, podPolicy v1alpha1.PodPolicy, targetRef autov2beta2.CrossVersionObjectReference) *autov2beta2.HorizontalPodAutoscaler {
158+
159+
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")
160+
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")
161+
min := *minReplicas
162+
max := *maxReplicas
158163
spec := autov2beta2.HorizontalPodAutoscalerSpec{
159164
ScaleTargetRef: targetRef,
160-
MinReplicas: &minReplicas,
161-
MaxReplicas: maxReplicas,
165+
MinReplicas: &min,
166+
MaxReplicas: max,
162167
Metrics: podPolicy.AutoScalingMetrics,
163168
Behavior: podPolicy.AutoScalingBehavior,
164169
}

controllers/spec/sink.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func MakeSinkHPA(sink *v1alpha1.Sink) *autov2beta2.HorizontalPodAutoscaler {
3737
return makeBuiltinHPA(objectMeta, *sink.Spec.MinReplicas, *sink.Spec.MaxReplicas, targetRef,
3838
sink.Spec.Pod.BuiltinAutoscaler)
3939
} else if !isDefaultHPAEnabled(sink.Spec.MinReplicas, sink.Spec.MaxReplicas, sink.Spec.Pod) {
40-
return makeHPA(objectMeta, *sink.Spec.MinReplicas, *sink.Spec.MaxReplicas, sink.Spec.Pod, targetRef)
40+
return makeHPA(objectMeta, sink.Spec.MinReplicas, sink.Spec.MaxReplicas, sink.Spec.Pod, targetRef)
4141
}
4242
return makeDefaultHPA(objectMeta, *sink.Spec.MinReplicas, *sink.Spec.MaxReplicas, targetRef)
4343
}

controllers/spec/source.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func MakeSourceHPA(source *v1alpha1.Source) *autov2beta2.HorizontalPodAutoscaler
3737
return makeBuiltinHPA(objectMeta, *source.Spec.MinReplicas, *source.Spec.MaxReplicas, targetRef,
3838
source.Spec.Pod.BuiltinAutoscaler)
3939
} else if !isDefaultHPAEnabled(source.Spec.MinReplicas, source.Spec.MaxReplicas, source.Spec.Pod) {
40-
return makeHPA(objectMeta, *source.Spec.MinReplicas, *source.Spec.MaxReplicas, source.Spec.Pod, targetRef)
40+
return makeHPA(objectMeta, source.Spec.MinReplicas, source.Spec.MaxReplicas, source.Spec.Pod, targetRef)
4141
}
4242
return makeDefaultHPA(objectMeta, *source.Spec.MinReplicas, *source.Spec.MaxReplicas, targetRef)
4343
}

0 commit comments

Comments
 (0)