diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 10e3cf3c8a9..313b0b9bed6 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -13834,11 +13834,11 @@ "description": "FlowSchema defines the schema of a group of flows. Note that a flow is made up of a set of inbound API requests with similar attributes and is identified by a pair of strings: the name of the FlowSchema and a \"flow distinguisher\".", "properties": { "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources", + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", "type": "string" }, "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds", + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", "type": "string" }, "metadata": { @@ -13893,7 +13893,7 @@ "description": "FlowSchemaList is a list of FlowSchema objects.", "properties": { "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources", + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", "type": "string" }, "items": { @@ -13904,7 +13904,7 @@ "type": "array" }, "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds", + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", "type": "string" }, "metadata": { @@ -14027,11 +14027,11 @@ "description": "PriorityLevelConfiguration represents the configuration of a priority level.", "properties": { "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources", + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", "type": "string" }, "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds", + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", "type": "string" }, "metadata": { @@ -14086,7 +14086,7 @@ "description": "PriorityLevelConfigurationList is a list of PriorityLevelConfiguration objects.", "properties": { "apiVersion": { - "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources", + "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", "type": "string" }, "items": { @@ -14097,7 +14097,7 @@ "type": "array" }, "kind": { - "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds", + "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", "type": "string" }, "metadata": { @@ -87653,7 +87653,8 @@ "consumes": [ "application/json-patch+json", "application/merge-patch+json", - "application/strategic-merge-patch+json" + "application/strategic-merge-patch+json", + "application/apply-patch+yaml" ], "description": "partially update the specified FlowSchema", "operationId": "patchFlowcontrolApiserverV1alpha1FlowSchema", @@ -87840,7 +87841,8 @@ "consumes": [ "application/json-patch+json", "application/merge-patch+json", - "application/strategic-merge-patch+json" + "application/strategic-merge-patch+json", + "application/apply-patch+yaml" ], "description": "partially update status of the specified FlowSchema", "operationId": "patchFlowcontrolApiserverV1alpha1FlowSchemaStatus", @@ -88426,7 +88428,8 @@ "consumes": [ "application/json-patch+json", "application/merge-patch+json", - "application/strategic-merge-patch+json" + "application/strategic-merge-patch+json", + "application/apply-patch+yaml" ], "description": "partially update the specified PriorityLevelConfiguration", "operationId": "patchFlowcontrolApiserverV1alpha1PriorityLevelConfiguration", @@ -88613,7 +88616,8 @@ "consumes": [ "application/json-patch+json", "application/merge-patch+json", - "application/strategic-merge-patch+json" + "application/strategic-merge-patch+json", + "application/apply-patch+yaml" ], "description": "partially update status of the specified PriorityLevelConfiguration", "operationId": "patchFlowcontrolApiserverV1alpha1PriorityLevelConfigurationStatus", diff --git a/pkg/printers/internalversion/BUILD b/pkg/printers/internalversion/BUILD index c1cf97ab921..63191ae296d 100644 --- a/pkg/printers/internalversion/BUILD +++ b/pkg/printers/internalversion/BUILD @@ -73,6 +73,7 @@ go_library( "//pkg/apis/events/install:go_default_library", "//pkg/apis/extensions/install:go_default_library", "//pkg/apis/flowcontrol:go_default_library", + "//pkg/apis/flowcontrol/install:go_default_library", "//pkg/apis/networking:go_default_library", "//pkg/apis/node:go_default_library", "//pkg/apis/policy:go_default_library", diff --git a/pkg/printers/internalversion/import_known_versions.go b/pkg/printers/internalversion/import_known_versions.go index 47a379762bd..97b667e7a57 100644 --- a/pkg/printers/internalversion/import_known_versions.go +++ b/pkg/printers/internalversion/import_known_versions.go @@ -29,6 +29,7 @@ import ( _ "k8s.io/kubernetes/pkg/apis/core/install" _ "k8s.io/kubernetes/pkg/apis/events/install" _ "k8s.io/kubernetes/pkg/apis/extensions/install" + _ "k8s.io/kubernetes/pkg/apis/flowcontrol/install" _ "k8s.io/kubernetes/pkg/apis/policy/install" _ "k8s.io/kubernetes/pkg/apis/rbac/install" _ "k8s.io/kubernetes/pkg/apis/scheduling/install" diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index 3b42e8006d6..7e81cf3b2ee 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -2120,7 +2120,7 @@ func printVolumeAttachmentList(list *storage.VolumeAttachmentList, options print return rows, nil } -func printFlowSchema(obj *flowcontrol.FlowSchema, options printers.PrintOptions) ([]metav1beta1.TableRow, error) { +func printFlowSchema(obj *flowcontrol.FlowSchema, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) { row := metav1beta1.TableRow{ Object: runtime.RawExtension{Object: obj}, } @@ -2136,7 +2136,7 @@ func printFlowSchema(obj *flowcontrol.FlowSchema, options printers.PrintOptions) return []metav1beta1.TableRow{row}, nil } -func printFlowSchemaList(list *flowcontrol.FlowSchemaList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) { +func printFlowSchemaList(list *flowcontrol.FlowSchemaList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) { rows := make([]metav1beta1.TableRow, 0, len(list.Items)) fsSeq := make(flowcontrol.FlowSchemaSequence, len(list.Items)) for i := range list.Items { @@ -2153,7 +2153,7 @@ func printFlowSchemaList(list *flowcontrol.FlowSchemaList, options printers.Prin return rows, nil } -func printPriorityLevelConfiguration(obj *flowcontrol.PriorityLevelConfiguration, options printers.PrintOptions) ([]metav1beta1.TableRow, error) { +func printPriorityLevelConfiguration(obj *flowcontrol.PriorityLevelConfiguration, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) { row := metav1beta1.TableRow{ Object: runtime.RawExtension{Object: obj}, } @@ -2168,7 +2168,7 @@ func printPriorityLevelConfiguration(obj *flowcontrol.PriorityLevelConfiguration return []metav1beta1.TableRow{row}, nil } -func printPriorityLevelConfigurationList(list *flowcontrol.PriorityLevelConfigurationList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) { +func printPriorityLevelConfigurationList(list *flowcontrol.PriorityLevelConfigurationList, options printers.GenerateOptions) ([]metav1beta1.TableRow, error) { rows := make([]metav1beta1.TableRow, 0, len(list.Items)) for i := range list.Items { r, err := printPriorityLevelConfiguration(&list.Items[i], options) diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/bootstrap/default-objects.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/bootstrap/default-objects.go index d8cdae58a4f..eee3350f1ba 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/bootstrap/default-objects.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/bootstrap/default-objects.go @@ -17,8 +17,6 @@ limitations under the License. package bootstrap import ( - "math" - rmv1a1 "k8s.io/api/flowcontrol/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apiserver/pkg/authentication/user" @@ -75,7 +73,7 @@ var ( DefaultFlowSchemaDefault = fs( "default", "default", - math.MaxInt32, rmv1a1.FlowDistinguisherMethodByUserType, + 10000, rmv1a1.FlowDistinguisherMethodByUserType, rmv1a1.PolicyRuleWithSubjects{ Subjects: groups(user.AllUnauthenticated, user.AllAuthenticated), Rule: resourceRule( diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock.go index f98114e3163..e1db8f9ce83 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock.go @@ -20,7 +20,6 @@ import ( "container/heap" "math/rand" "sync" - "testing" "time" "k8s.io/apimachinery/pkg/util/clock" @@ -33,17 +32,20 @@ import ( // no other work is left to be completed in goroutines. type EventFunc func(time.Time) +// SettablePassiveClock allows setting current time of a passive clock type SettablePassiveClock interface { clock.PassiveClock SetTime(time.Time) } +// EventClock fires event on time type EventClock interface { clock.PassiveClock EventAfterDuration(f EventFunc, d time.Duration) EventAfterTime(f EventFunc, t time.Time) } +// RealEventClock fires event on real world time type RealEventClock struct { clock.RealClock } @@ -76,7 +78,8 @@ type FakeEventClock struct { clock.FakePassiveClock // waiters is a heap of waiting work, sorted by time - waiters eventWaiterHeap + waiters eventWaiterHeap + waitersLock sync.RWMutex // clientWG may be nil and if not supplies constraints on time // passing in Run. The Run method will not pick a new time until @@ -125,6 +128,8 @@ func NewFakeEventClock(t time.Time, clientWG *sync.WaitGroup, fuzz time.Duration // GetNextTime returns the next time at which there is work scheduled, // and a bool indicating whether there is any such time func (fec *FakeEventClock) GetNextTime() (time.Time, bool) { + fec.waitersLock.RLock() + defer fec.waitersLock.RUnlock() if len(fec.waiters) > 0 { return fec.waiters[0].targetTime, true } @@ -154,28 +159,34 @@ func (fec *FakeEventClock) Run(limit *time.Time) { func (fec *FakeEventClock) SetTime(t time.Time) { fec.FakePassiveClock.SetTime(t) for { - // This loop is because events run at a given time may schedule more - // events to run at that or an earlier time. - // Events should not advance the clock. But just in case they do... - now := fec.Now() - var wg sync.WaitGroup foundSome := false - for len(fec.waiters) > 0 && !now.Before(fec.waiters[0].targetTime) { - ew := heap.Pop(&fec.waiters).(eventWaiter) - wg.Add(1) - go func(f EventFunc) { f(now); wg.Done() }(ew.f) - foundSome = true - } + func() { + fec.waitersLock.Lock() + defer fec.waitersLock.Unlock() + // This loop is because events run at a given time may schedule more + // events to run at that or an earlier time. + // Events should not advance the clock. But just in case they do... + now := fec.Now() + var wg sync.WaitGroup + for len(fec.waiters) > 0 && !now.Before(fec.waiters[0].targetTime) { + ew := heap.Pop(&fec.waiters).(eventWaiter) + wg.Add(1) + go func(f EventFunc) { f(now); wg.Done() }(ew.f) + foundSome = true + } + wg.Wait() + }() if !foundSome { break } - wg.Wait() } } // EventAfterDuration schedules the given function to be invoked once // the given duration has passed. func (fec *FakeEventClock) EventAfterDuration(f EventFunc, d time.Duration) { + fec.waitersLock.Lock() + defer fec.waitersLock.Unlock() now := fec.Now() fd := time.Duration(float32(fec.fuzz) * fec.rand.Float32()) heap.Push(&fec.waiters, eventWaiter{targetTime: now.Add(d + fd), f: f}) @@ -184,6 +195,8 @@ func (fec *FakeEventClock) EventAfterDuration(f EventFunc, d time.Duration) { // EventAfterTime schedules the given function to be invoked once // the given time has arrived. func (fec *FakeEventClock) EventAfterTime(f EventFunc, t time.Time) { + fec.waitersLock.Lock() + defer fec.waitersLock.Unlock() fd := time.Duration(float32(fec.fuzz) * fec.rand.Float32()) heap.Push(&fec.waiters, eventWaiter{targetTime: t.Add(fd), f: f}) } @@ -205,26 +218,3 @@ func (ewh *eventWaiterHeap) Pop() interface{} { *ewh = old[:n-1] return x } - -func exercisePassiveClock(t *testing.T, pc SettablePassiveClock) { - t1 := time.Now() - t2 := t1.Add(time.Hour) - pc.SetTime(t1) - tx := pc.Now() - if tx != t1 { - t.Errorf("SetTime(%#+v); Now() => %#+v", t1, tx) - } - dx := pc.Since(t1) - if dx != 0 { - t.Errorf("Since() => %v", dx) - } - pc.SetTime(t2) - dx = pc.Since(t1) - if dx != time.Hour { - t.Errorf("Since() => %v", dx) - } - tx = pc.Now() - if tx != t2 { - t.Errorf("Now() => %#+v", tx) - } -} diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock_test.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock_test.go index a35173a3b08..3d2db004499 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock_test.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/event_clock_test.go @@ -96,6 +96,29 @@ func exerciseTestableEventClock(t *testing.T, ec TestableEventClock, fuzz time.D } } +func exercisePassiveClock(t *testing.T, pc SettablePassiveClock) { + t1 := time.Now() + t2 := t1.Add(time.Hour) + pc.SetTime(t1) + tx := pc.Now() + if tx != t1 { + t.Errorf("SetTime(%#+v); Now() => %#+v", t1, tx) + } + dx := pc.Since(t1) + if dx != 0 { + t.Errorf("Since() => %v", dx) + } + pc.SetTime(t2) + dx = pc.Since(t1) + if dx != time.Hour { + t.Errorf("Since() => %v", dx) + } + tx = pc.Now() + if tx != t2 { + t.Errorf("Now() => %#+v", tx) + } +} + func TestFakeEventClock(t *testing.T) { startTime := time.Now() fec := NewFakeEventClock(startTime, nil, 0, nil) diff --git a/test/integration/apiserver/BUILD b/test/integration/apiserver/BUILD index 022d23c13f1..c51a171c83d 100644 --- a/test/integration/apiserver/BUILD +++ b/test/integration/apiserver/BUILD @@ -35,6 +35,7 @@ go_test( "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/discovery/v1alpha1:go_default_library", "//staging/src/k8s.io/api/extensions/v1beta1:go_default_library", + "//staging/src/k8s.io/api/flowcontrol/v1alpha1:go_default_library", "//staging/src/k8s.io/api/node/v1alpha1:go_default_library", "//staging/src/k8s.io/api/rbac/v1alpha1:go_default_library", "//staging/src/k8s.io/api/scheduling/v1:go_default_library", diff --git a/test/integration/apiserver/print_test.go b/test/integration/apiserver/print_test.go index da6eb25027b..deb23c42061 100644 --- a/test/integration/apiserver/print_test.go +++ b/test/integration/apiserver/print_test.go @@ -32,6 +32,7 @@ import ( batchv2alpha1 "k8s.io/api/batch/v2alpha1" discoveryv1alpha1 "k8s.io/api/discovery/v1alpha1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" + flowcontrolv1alpha1 "k8s.io/api/flowcontrol/v1alpha1" nodev1alpha1 "k8s.io/api/node/v1alpha1" rbacv1alpha1 "k8s.io/api/rbac/v1alpha1" schedulerapi "k8s.io/api/scheduling/v1" @@ -138,8 +139,6 @@ var missingHanlders = sets.NewString( "AuditSink", "CSINode", "CSIDriver", - "FlowSchema", - "PriorityLevelConfiguration", ) func TestServerSidePrint(t *testing.T) { @@ -157,7 +156,7 @@ func TestServerSidePrint(t *testing.T) { appsv1beta2.SchemeGroupVersion, extensionsv1beta1.SchemeGroupVersion, nodev1alpha1.SchemeGroupVersion, - //flowcontrolv1alph1.SchemeGroupVersion, + flowcontrolv1alpha1.SchemeGroupVersion, }, []schema.GroupVersionResource{ extensionsv1beta1.SchemeGroupVersion.WithResource("daemonsets"), diff --git a/vendor/modules.txt b/vendor/modules.txt index ed570a39adc..314521eb955 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1367,7 +1367,6 @@ k8s.io/apiserver/pkg/storage/value/encrypt/envelope k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1 k8s.io/apiserver/pkg/storage/value/encrypt/identity k8s.io/apiserver/pkg/storage/value/encrypt/secretbox -k8s.io/apiserver/pkg/util/clock k8s.io/apiserver/pkg/util/dryrun k8s.io/apiserver/pkg/util/feature k8s.io/apiserver/pkg/util/flowcontrol