Skip to content

Commit

Permalink
Properly initialize HPA objects with defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Naik <arjun@arjunnaik.in>
  • Loading branch information
arjunrn committed Dec 9, 2019
1 parent fd8ca5d commit 8b159e8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/api/testing/defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func TestDefaulting(t *testing.T) {
{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2beta1", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v2beta1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "batch", Version: "v1", Kind: "Job"}: {},
{Group: "batch", Version: "v1", Kind: "JobList"}: {},
{Group: "batch", Version: "v1beta1", Kind: "CronJob"}: {},
Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/autoscaling/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
},
},
}
stabilizationWindow := int32(c.RandUint64())
maxPolicy := autoscaling.MaxPolicySelect
minPolicy := autoscaling.MinPolicySelect
s.Behavior = &autoscaling.HorizontalPodAutoscalerBehavior{
ScaleUp: &autoscaling.HPAScalingRules{
StabilizationWindowSeconds: &stabilizationWindow,
SelectPolicy: &maxPolicy,
Policies: []autoscaling.HPAScalingPolicy{
{
Type: autoscaling.PodsScalingPolicy,
Value: int32(c.RandUint64()),
PeriodSeconds: int32(c.RandUint64()),
},
{
Type: autoscaling.PercentScalingPolicy,
Value: int32(c.RandUint64()),
PeriodSeconds: int32(c.RandUint64()),
},
},
},
ScaleDown: &autoscaling.HPAScalingRules{
StabilizationWindowSeconds: &stabilizationWindow,
SelectPolicy: &minPolicy,
Policies: []autoscaling.HPAScalingPolicy{
{
Type: autoscaling.PodsScalingPolicy,
Value: int32(c.RandUint64()),
PeriodSeconds: int32(c.RandUint64()),
},
{
Type: autoscaling.PercentScalingPolicy,
Value: int32(c.RandUint64()),
PeriodSeconds: int32(c.RandUint64()),
},
},
},
}
},
func(s *autoscaling.HorizontalPodAutoscalerStatus, c fuzz.Continue) {
c.FuzzNoCustom(s) // fuzz self without calling this function again
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/autoscaling/v2beta2/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ limitations under the License.
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/autoscaling
// +k8s:conversion-gen-external-types=k8s.io/api/autoscaling/v2beta2
// +k8s:defaulter-gen=TypeMeta
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/autoscaling/v2beta2

package v2beta2 // import "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
18 changes: 18 additions & 0 deletions pkg/apis/autoscaling/v2beta2/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b159e8

Please sign in to comment.