Skip to content

Commit

Permalink
Merge pull request #53973 from m1093782566/validate-sheduler
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

validate ipvs scheduler

**What this PR does / why we need it**:

validate ipvs scheduler options

**Which issue this PR fixes**: 

closes #53975

**Special notes for your reviewer**:

It depends on work of #53780.

**Release note**:

```release-note
NONE
```

/sig network

/area kube-proxy
  • Loading branch information
Kubernetes Submit Queue committed Oct 30, 2017
2 parents 7c96feb + 518936f commit 878814b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/kube-proxy/app/validation.go
Expand Up @@ -38,6 +38,7 @@ func Validate(config *componentconfig.KubeProxyConfiguration) field.ErrorList {
allErrs = append(allErrs, validateKubeProxyConntrackConfiguration(config.Conntrack, newPath.Child("KubeProxyConntrackConfiguration"))...)
allErrs = append(allErrs, validateProxyMode(config.Mode, newPath.Child("Mode"))...)
allErrs = append(allErrs, validateClientConnectionConfiguration(config.ClientConnection, newPath.Child("ClientConnection"))...)
allErrs = append(allErrs, validateIPVSSchedulerMethod(config.IPVS.Scheduler, newPath.Child("KubeProxyIPVSConfiguration").Child("Scheduler"))...)

if config.OOMScoreAdj != nil && (*config.OOMScoreAdj < -1000 || *config.OOMScoreAdj > 1000) {
allErrs = append(allErrs, field.Invalid(newPath.Child("OOMScoreAdj"), *config.OOMScoreAdj, "must be within the range [-1000, 1000]"))
Expand Down Expand Up @@ -157,3 +158,33 @@ func validateHostPort(input string, fldPath *field.Path) field.ErrorList {

return allErrs
}

func validateIPVSSchedulerMethod(scheduler string, fldPath *field.Path) field.ErrorList {
supportedMethod := []string{
string(componentconfig.RoundRobin),
string(componentconfig.WeightedRoundRobin),
string(componentconfig.LeastConnection),
string(componentconfig.WeightedLeastConnection),
string(componentconfig.LocalityBasedLeastConnection),
string(componentconfig.LocalityBasedLeastConnectionWithReplication),
string(componentconfig.SourceHashing),
string(componentconfig.DestinationHashing),
string(componentconfig.ShortestExpectedDelay),
string(componentconfig.NeverQueue),
"",
}
allErrs := field.ErrorList{}
var found bool
for i := range supportedMethod {
if scheduler == supportedMethod[i] {
found = true
break
}
}
// Not found
if !found {
errMsg := fmt.Sprintf("must be in %v, blank means the default algorithm method (currently rr)", supportedMethod)
allErrs = append(allErrs, field.Invalid(fldPath.Child("Scheduler"), string(scheduler), errMsg))
}
return allErrs
}
42 changes: 42 additions & 0 deletions pkg/apis/componentconfig/types.go
Expand Up @@ -161,6 +161,48 @@ const (
ProxyModeIPVS ProxyMode = "ipvs"
)

// IPVSSchedulerMethod is the algorithm for allocating TCP connections and
// UDP datagrams to real servers. Scheduling algorithms are imple-
//wanted as kernel modules. Ten are shipped with the Linux Virtual Server.
type IPVSSchedulerMethod string

const (
// Robin Robin distributes jobs equally amongst the available real servers.
RoundRobin IPVSSchedulerMethod = "rr"
// Weighted Round Robin assigns jobs to real servers proportionally to there real servers' weight.
// Servers with higher weights receive new jobs first and get more jobs than servers with lower weights.
// Servers with equal weights get an equal distribution of new jobs.
WeightedRoundRobin IPVSSchedulerMethod = "wrr"
// Least Connection assigns more jobs to real servers with fewer active jobs.
LeastConnection IPVSSchedulerMethod = "lc"
// Weighted Least Connection assigns more jobs to servers with fewer jobs and
// relative to the real servers’weight(Ci/Wi).
WeightedLeastConnection IPVSSchedulerMethod = "wlc"
// Locality Based Least Connection assigns jobs destined for the same IP address to the same server if
// the server is not overloaded and available; otherwise assign jobs to servers with fewer jobs,
// and keep it for future assignment.
LocalityBasedLeastConnection IPVSSchedulerMethod = "lblc"
// Locality Based Least Connection with Replication assigns jobs destined for the same IP address to the
// least-connection node in the server set for the IP address. If all the node in the server set are over loaded,
// it picks up a node with fewer jobs in the cluster and adds it in the sever set for the target.
// If the server set has not been modified for the specified time, the most loaded node is removed from the server set,
// in order to avoid high degree of replication.
LocalityBasedLeastConnectionWithReplication IPVSSchedulerMethod = "lblcr"
// Source Hashing assigns jobs to servers through looking up a statically assigned hash table
// by their source IP addresses.
SourceHashing IPVSSchedulerMethod = "sh"
// Destination Hashing assigns jobs to servers through looking up a statically assigned hash table
// by their destination IP addresses.
DestinationHashing IPVSSchedulerMethod = "dh"
// Shortest Expected Delay assigns an incoming job to the server with the shortest expected delay.
// The expected delay that the job will experience is (Ci + 1) / Ui if sent to the ith server, in which
// Ci is the number of jobs on the the ith server and Ui is the fixed service rate (weight) of the ith server.
ShortestExpectedDelay IPVSSchedulerMethod = "sed"
// Never Queue assigns an incoming job to an idle server if there is, instead of waiting for a fast one;
// if all the servers are busy, it adopts the Shortest Expected Delay policy to assign the job.
NeverQueue IPVSSchedulerMethod = "nq"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type KubeSchedulerConfiguration struct {
Expand Down

0 comments on commit 878814b

Please sign in to comment.