Merge pull request #83671 from yue9944882/flow-control-api-model
Apiserver flowcontrol api models Kubernetes-commit: 510fb38f275bdfbd61b2ceba5162209e88cf9634
This commit is contained in:
commit
49d6d41cba
|
@ -576,15 +576,15 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "b19d8caf39be"
|
||||
"Rev": "b98ecd433b91"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "bb31b70367b7"
|
||||
"Rev": "50aa20a7b23f"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"Rev": "e9766ae82012"
|
||||
"Rev": "890ae1879817"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/component-base",
|
||||
|
|
12
go.mod
12
go.mod
|
@ -40,9 +40,9 @@ require (
|
|||
gopkg.in/square/go-jose.v2 v2.2.2
|
||||
gopkg.in/yaml.v2 v2.2.4
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
k8s.io/api v0.0.0-20191031065753-b19d8caf39be
|
||||
k8s.io/apimachinery v0.0.0-20191030190112-bb31b70367b7
|
||||
k8s.io/client-go v0.0.0-20191101230044-e9766ae82012
|
||||
k8s.io/api v0.0.0-20191102065807-b98ecd433b91
|
||||
k8s.io/apimachinery v0.0.0-20191102025618-50aa20a7b23f
|
||||
k8s.io/client-go v0.0.0-20191102070040-890ae1879817
|
||||
k8s.io/component-base v0.0.0-20191101230432-fc40a62c56dd
|
||||
k8s.io/klog v1.0.0
|
||||
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf
|
||||
|
@ -60,8 +60,8 @@ replace (
|
|||
golang.org/x/sys => golang.org/x/sys v0.0.0-20190209173611-3b5209105503
|
||||
golang.org/x/text => golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
|
||||
golang.org/x/time => golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
|
||||
k8s.io/api => k8s.io/api v0.0.0-20191031065753-b19d8caf39be
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191030190112-bb31b70367b7
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20191101230044-e9766ae82012
|
||||
k8s.io/api => k8s.io/api v0.0.0-20191102065807-b98ecd433b91
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191102025618-50aa20a7b23f
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20191102070040-890ae1879817
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20191101230432-fc40a62c56dd
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -316,9 +316,9 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81
|
|||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20191031065753-b19d8caf39be/go.mod h1:+hZ4rl5/4vOvVe96ffrVpS5wEIWwPC12pZr9iXDo7OI=
|
||||
k8s.io/apimachinery v0.0.0-20191030190112-bb31b70367b7/go.mod h1:gA1T9z4LIup7PIegBwxkF2UYXUNVKhOAPvQWWnAc34k=
|
||||
k8s.io/client-go v0.0.0-20191101230044-e9766ae82012/go.mod h1:zKWCWMOYD/TPRNgsnfAAzrtRLx3v+YGSGrWSwu7hrhE=
|
||||
k8s.io/api v0.0.0-20191102065807-b98ecd433b91/go.mod h1:o5KeABD7wGV2jASWXz27PT4gGWdB5zA9kOg3iFzXTcY=
|
||||
k8s.io/apimachinery v0.0.0-20191102025618-50aa20a7b23f/go.mod h1:gA1T9z4LIup7PIegBwxkF2UYXUNVKhOAPvQWWnAc34k=
|
||||
k8s.io/client-go v0.0.0-20191102070040-890ae1879817/go.mod h1:zYL4aicqOblDPuQcBaC9i/udq8+D/QJXPhcEWYR/tVE=
|
||||
k8s.io/component-base v0.0.0-20191101230432-fc40a62c56dd/go.mod h1:ENDlyOTf2BFTMuaSVcdNTAhiEJIZb+lQ5RKyUvR9Ixk=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
Copyright 2019 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 apihelpers
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
flowcontrol "k8s.io/api/flowcontrol/v1alpha1"
|
||||
)
|
||||
|
||||
// SetFlowSchemaCondition sets conditions.
|
||||
func SetFlowSchemaCondition(flowSchema *flowcontrol.FlowSchema, newCondition flowcontrol.FlowSchemaCondition) {
|
||||
existingCondition := GetFlowSchemaConditionByType(flowSchema, newCondition.Type)
|
||||
if existingCondition == nil {
|
||||
flowSchema.Status.Conditions = append(flowSchema.Status.Conditions, newCondition)
|
||||
return
|
||||
}
|
||||
|
||||
if existingCondition.Status != newCondition.Status {
|
||||
existingCondition.Status = newCondition.Status
|
||||
existingCondition.LastTransitionTime = newCondition.LastTransitionTime
|
||||
}
|
||||
|
||||
existingCondition.Reason = newCondition.Reason
|
||||
existingCondition.Message = newCondition.Message
|
||||
}
|
||||
|
||||
// GetFlowSchemaConditionByType gets conditions.
|
||||
func GetFlowSchemaConditionByType(flowSchema *flowcontrol.FlowSchema, conditionType flowcontrol.FlowSchemaConditionType) *flowcontrol.FlowSchemaCondition {
|
||||
for i := range flowSchema.Status.Conditions {
|
||||
if flowSchema.Status.Conditions[i].Type == conditionType {
|
||||
return &flowSchema.Status.Conditions[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPriorityLevelConfigurationCondition sets conditions.
|
||||
func SetPriorityLevelConfigurationCondition(priorityLevel *flowcontrol.PriorityLevelConfiguration, newCondition flowcontrol.PriorityLevelConfigurationCondition) {
|
||||
existingCondition := GetPriorityLevelConfigurationConditionByType(priorityLevel, newCondition.Type)
|
||||
if existingCondition == nil {
|
||||
priorityLevel.Status.Conditions = append(priorityLevel.Status.Conditions, newCondition)
|
||||
return
|
||||
}
|
||||
|
||||
if existingCondition.Status != newCondition.Status {
|
||||
existingCondition.Status = newCondition.Status
|
||||
existingCondition.LastTransitionTime = newCondition.LastTransitionTime
|
||||
}
|
||||
|
||||
existingCondition.Reason = newCondition.Reason
|
||||
existingCondition.Message = newCondition.Message
|
||||
}
|
||||
|
||||
// GetPriorityLevelConfigurationConditionByType gets conditions.
|
||||
func GetPriorityLevelConfigurationConditionByType(priorityLevel *flowcontrol.PriorityLevelConfiguration, conditionType flowcontrol.PriorityLevelConfigurationConditionType) *flowcontrol.PriorityLevelConfigurationCondition {
|
||||
for i := range priorityLevel.Status.Conditions {
|
||||
if priorityLevel.Status.Conditions[i].Type == conditionType {
|
||||
return &priorityLevel.Status.Conditions[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ sort.Interface = FlowSchemaSequence{}
|
||||
|
||||
// FlowSchemaSequence holds sorted set of pointers to FlowSchema objects.
|
||||
// FlowSchemaSequence implements `sort.Interface`
|
||||
type FlowSchemaSequence []*flowcontrol.FlowSchema
|
||||
|
||||
func (s FlowSchemaSequence) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s FlowSchemaSequence) Less(i, j int) bool {
|
||||
// the flow-schema w/ lower matching-precedence is prior
|
||||
if ip, jp := s[i].Spec.MatchingPrecedence, s[j].Spec.MatchingPrecedence; ip != jp {
|
||||
return ip < jp
|
||||
}
|
||||
// sort alphabetically
|
||||
return s[i].Name < s[j].Name
|
||||
}
|
||||
|
||||
func (s FlowSchemaSequence) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
Loading…
Reference in New Issue