Skip to content

Commit

Permalink
Refactor reading & validating PriorityAndFairnessConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
jupblb committed Aug 5, 2022
1 parent d55af61 commit eb8f548
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 154 deletions.
13 changes: 3 additions & 10 deletions staging/src/k8s.io/apiserver/pkg/apis/apiserver/types.go
Expand Up @@ -174,29 +174,24 @@ type PriorityAndFairnessConfiguration struct {
metav1.TypeMeta

// WorkEstimatorConfig holds work estimator parameters.
// +optional
WorkEstimator *WorkEstimatorConfiguration
WorkEstimator WorkEstimatorConfiguration
}

// WorkEstimatorConfiguration holds work estimator parameters.
type WorkEstimatorConfiguration struct {
// ListWorkEstimator holds work estimator parameters related to list requests.
// +optional
ListWorkEstimator *ListWorkEstimatorConfiguration
ListWorkEstimator ListWorkEstimatorConfiguration
// MutatingWorkEstimator holds work estimator parameters
// related to requests that mutate watched objects.
// +optional
MutatingWorkEstimator *MutatingWorkEstimatorConfiguration
MutatingWorkEstimator MutatingWorkEstimatorConfiguration

// MaximumSeats is the maximum number of seats a request can occupy
// +optional
MaximumSeats uint64
}

// ListWorkEstimatorConfiguration holds work estimator parameters related to list requests.
type ListWorkEstimatorConfiguration struct {
// ObjectsPerSeat is a number of objects from a single list request per seat.
// +optional
ObjectsPerSeat float64
}

Expand All @@ -206,13 +201,11 @@ type MutatingWorkEstimatorConfiguration struct {
// EventAdditionalDuration is the additional amount of time that a mutating request occupies seats
// to account for the work involved in sending the corresponding WATCH notifications. Setting its
// value to 0 effectively disables this behavior but a request may still occupy seats.
// +optional
EventAdditionalDuration metav1.Duration
// WatchesPerSeat is the ratio between the number of WATCHes that will get notified and
// the number of seats occupied for EventAdditionalDuration to account for the work of
// sending those notifications. Setting its value to 0 disables mutating work estimator.
// Setting its value to a number higher than any number of watches disables this behavior but
// a request may still occupy a seat as per EventAdditionalDuration.
// +optional
WatchesPerSeat float64
}
Expand Up @@ -30,3 +30,18 @@ func Convert_v1alpha1_EgressSelection_To_apiserver_EgressSelection(in *EgressSel
}
return nil
}

func Convert_Pointer_uint64_To_uint64(in **uint64, out *uint64, s conversion.Scope) error {
if *in == nil {
*out = 0
return nil
}
*out = uint64(**in)
return nil
}

func Convert_uint64_To_Pointer_uint64(in *uint64, out **uint64, s conversion.Scope) error {
temp := uint64(*in)
*out = &temp
return nil
}
@@ -0,0 +1,56 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

var (
defaultEventAdditionalDuration = 5 * time.Millisecond
defaultMaximumSeats uint64 = 10
defaultObjectsPerSeat = 100.0
defaultWatchesPerSeat = 10.0
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

func SetDefaults_WorkEstimatorConfiguration(obj *WorkEstimatorConfiguration) {
if obj.MaximumSeats == nil {
obj.MaximumSeats = &defaultMaximumSeats
}
}

func SetDefaults_ListWorkEstimatorConfiguration(obj *ListWorkEstimatorConfiguration) {
if obj.ObjectsPerSeat == nil {
obj.ObjectsPerSeat = &defaultObjectsPerSeat
}
}

func SetDefaults_MutatingWorkEstimatorConfiguration(obj *MutatingWorkEstimatorConfiguration) {
if obj.EventAdditionalDuration == nil {
obj.EventAdditionalDuration = &metav1.Duration{Duration: defaultEventAdditionalDuration}
}
if obj.WatchesPerSeat == nil {
obj.WatchesPerSeat = &defaultWatchesPerSeat
}
}
Expand Up @@ -43,7 +43,7 @@ func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
localSchemeBuilder.Register(addDefaultingFuncs, addKnownTypes)
}

// Adds the list of known types to the given scheme.
Expand Down
Expand Up @@ -176,29 +176,28 @@ type PriorityAndFairnessConfiguration struct {

// WorkEstimator holds work estimator parameters.
// +optional
WorkEstimator *WorkEstimatorConfiguration `json:"workEstimator,omitempty"`
WorkEstimator WorkEstimatorConfiguration `json:"workEstimator,omitempty"`
}

// WorkEstimatorConfiguration holds work estimator parameters.
type WorkEstimatorConfiguration struct {
// ListWorkEstimator holds work estimator parameters related to list requests.
// +optional
ListWorkEstimator *ListWorkEstimatorConfiguration `json:"listRequests,omitempty"`
ListWorkEstimator ListWorkEstimatorConfiguration `json:"listRequests,omitempty"`
// MutatingWorkEstimator holds work estimator parameters
// related to requests that mutate watched objects.
// +optional
MutatingWorkEstimator *MutatingWorkEstimatorConfiguration `json:"mutatingRequests,omitempty"`
MutatingWorkEstimator MutatingWorkEstimatorConfiguration `json:"mutatingRequests,omitempty"`

// MaximumSeats is the maximum number of seats a request can occupy
// +optional
MaximumSeats uint64 `json:"maximumSeats,omitempty"`
MaximumSeats *uint64 `json:"maximumSeats,omitempty"`
}

// ListWorkEstimatorConfiguration holds work estimator parameters related to list requests.
type ListWorkEstimatorConfiguration struct {
// ObjectsPerSeat is a number of objects from a single list request per seat.
// +optional
ObjectsPerSeat float64 `json:"objectsPerSeat,omitempty"`
ObjectsPerSeat *float64 `json:"objectsPerSeat,omitempty"`
}

// MutatingWorkEstimatorConfiguration holds work estimator
Expand All @@ -208,12 +207,12 @@ type MutatingWorkEstimatorConfiguration struct {
// to account for the work involved in sending the corresponding WATCH notifications. Setting its
// value to 0 effectively disables this behavior but a request may still occupy seats.
// +optional
EventAdditionalDuration metav1.Duration `json:"eventAdditionalDuration,omitempty"`
EventAdditionalDuration *metav1.Duration `json:"eventAdditionalDuration,omitempty"`
// WatchesPerSeat is the ratio between the number of WATCHes that will get notified and
// the number of seats occupied for EventAdditionalDuration to account for the work of
// sending those notifications. Setting its value to 0 disables mutating work estimator.
// Setting its value to a number higher than any number of watches disables this behavior but
// a request may still occupy a seat as per EventAdditionalDuration.
// +optional
WatchesPerSeat float64 `json:"watchesPerSeat,omitempty"`
WatchesPerSeat *float64 `json:"watchesPerSeat,omitempty"`
}

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

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

0 comments on commit eb8f548

Please sign in to comment.