func (b *BufferPolicy) ValidateBufferPolicy(causes []metav1.StatusCause) []metav1.StatusCause {
	if b == nil {
		return append(causes, metav1.StatusCause{
			Type:    metav1.CauseTypeFieldValueInvalid,
			Field:   "buffer",
			Message: "Buffer policy config params are missing",
		})
	}
	if b.MinReplicas > b.MaxReplicas {
		causes = append(causes, metav1.StatusCause{
			Type:    metav1.CauseTypeFieldValueInvalid,
			Field:   "minReplicas",
			Message: "minReplicas is bigger than maxReplicas",
		})
	}
	if b.BufferSize.Type == intstr.Int {
		if b.BufferSize.IntValue() <= 0 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "bufferSize",
				Message: "bufferSize must be bigger than 0",
			})
		}
		if b.MaxReplicas < int32(b.BufferSize.IntValue()) {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "maxReplicas",
				Message: "maxReplicas must be bigger than bufferSize",
			})
		}
		if b.MinReplicas != 0 && b.MinReplicas < int32(b.BufferSize.IntValue()) {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "minReplicas",
				Message: "minReplicas is smaller than bufferSize",
			})
		}
	} else {
		r, err := intstr.GetValueFromIntOrPercent(&b.BufferSize, 100, true)
		if err != nil || r < 1 || r > 99 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "bufferSize",
				Message: "bufferSize does not have a valid percentage value (1%-99%)",
			})
		}
		// When there is no allocated gameservers in a fleet,
		// Fleetautoscaler would reduce size of a fleet to MinReplicas.
		// If we have 0 MinReplicas and 0 Allocated then Fleetautoscaler would set Ready Replicas to 0
		// and we will not be able to raise the number of GS in a Fleet above zero
		if b.MinReplicas < 1 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "minReplicas",
				Message: "minReplicas should be above 0 when used with percentage value bufferSize",
			})
		}
	}
	return causes
}
// ValidateBufferPolicy validates the FleetAutoscaler Buffer policy settings
ValidateBufferPolicy validates the FleetAutoscaler Buffer policy settings
// ValidateBufferPolicy validates the FleetAutoscaler Buffer policy settings
func (b *BufferPolicy) ValidateBufferPolicy(causes []metav1.StatusCause) []metav1.StatusCause {
	if b == nil {
		return append(causes, metav1.StatusCause{
			Type:    metav1.CauseTypeFieldValueInvalid,
			Field:   "buffer",
			Message: "Buffer policy config params are missing",
		})
	}
	if b.MinReplicas > b.MaxReplicas {
		causes = append(causes, metav1.StatusCause{
			Type:    metav1.CauseTypeFieldValueInvalid,
			Field:   "minReplicas",
			Message: "minReplicas is bigger than maxReplicas",
		})
	}
	if b.BufferSize.Type == intstr.Int {
		if b.BufferSize.IntValue() <= 0 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "bufferSize",
				Message: "bufferSize must be bigger than 0",
			})
		}
		if b.MaxReplicas < int32(b.BufferSize.IntValue()) {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "maxReplicas",
				Message: "maxReplicas must be bigger than bufferSize",
			})
		}
		if b.MinReplicas != 0 && b.MinReplicas < int32(b.BufferSize.IntValue()) {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "minReplicas",
				Message: "minReplicas is smaller than bufferSize",
			})
		}
	} else {
		r, err := intstr.GetValueFromIntOrPercent(&b.BufferSize, 100, true)
		if err != nil || r < 1 || r > 99 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "bufferSize",
				Message: "bufferSize does not have a valid percentage value (1%-99%)",
			})
		}
		if b.MinReplicas < 1 {
			causes = append(causes, metav1.StatusCause{
				Type:    metav1.CauseTypeFieldValueInvalid,
				Field:   "minReplicas",
				Message: "minReplicas should be above 0 when used with percentage value bufferSize",
			})
		}
	}
	return causes
}
func ( b * BufferPolicy ) ValidateBufferPolicy ( causes [ ] metav1 . StatusCause ) [ ] metav1 . StatusCause { if b == nil { return append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } if b . MinReplicas > b . MaxReplicas { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } if b . BufferSize . Type == intstr . Int { if b . BufferSize . IntValue ( ) <= 0 { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } if b . MaxReplicas < int32 ( b . BufferSize . IntValue ( ) ) { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } if b . MinReplicas != 0 && b . MinReplicas < int32 ( b . BufferSize . IntValue ( ) ) { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } } else { r , err := intstr . GetValueFromIntOrPercent ( & b . BufferSize , 100 , true ) if err != nil || r < 1 || r > 99 { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } if b . MinReplicas < 1 { causes = append ( causes , metav1 . StatusCause { Type : metav1 . CauseTypeFieldValueInvalid , Field : " " , Message : " " , } ) } } return causes }
ValidateBufferPolicy validates the FleetAutoscaler Buffer policy settings
ValidateBufferPolicy validates the FleetAutoscaler Buffer policy settings
// When there is no allocated gameservers in a fleet, // Fleetautoscaler would reduce size of a fleet to MinReplicas. // If we have 0 MinReplicas and 0 Allocated then Fleetautoscaler would set Ready Replicas to 0 // and we will not be able to raise the number of GS in a Fleet above zero