mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor files
This commit is contained in:
42
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/BUILD
generated
vendored
Normal file
42
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/BUILD
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["work_queue.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/util/queue",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["work_queue_test.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/util/queue",
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
67
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue.go
generated
vendored
Normal file
67
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue.go
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2015 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 queue
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
)
|
||||
|
||||
// WorkQueue allows queuing items with a timestamp. An item is
|
||||
// considered ready to process if the timestamp has expired.
|
||||
type WorkQueue interface {
|
||||
// GetWork dequeues and returns all ready items.
|
||||
GetWork() []types.UID
|
||||
// Enqueue inserts a new item or overwrites an existing item.
|
||||
Enqueue(item types.UID, delay time.Duration)
|
||||
}
|
||||
|
||||
type basicWorkQueue struct {
|
||||
clock clock.Clock
|
||||
lock sync.Mutex
|
||||
queue map[types.UID]time.Time
|
||||
}
|
||||
|
||||
var _ WorkQueue = &basicWorkQueue{}
|
||||
|
||||
func NewBasicWorkQueue(clock clock.Clock) WorkQueue {
|
||||
queue := make(map[types.UID]time.Time)
|
||||
return &basicWorkQueue{queue: queue, clock: clock}
|
||||
}
|
||||
|
||||
func (q *basicWorkQueue) GetWork() []types.UID {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
now := q.clock.Now()
|
||||
var items []types.UID
|
||||
for k, v := range q.queue {
|
||||
if v.Before(now) {
|
||||
items = append(items, k)
|
||||
delete(q.queue, k)
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (q *basicWorkQueue) Enqueue(item types.UID, delay time.Duration) {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
q.queue[item] = q.clock.Now().Add(delay)
|
||||
}
|
65
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue_test.go
generated
vendored
Normal file
65
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue_test.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2015 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 queue
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
func newTestBasicWorkQueue() (*basicWorkQueue, *clock.FakeClock) {
|
||||
fakeClock := clock.NewFakeClock(time.Now())
|
||||
wq := &basicWorkQueue{
|
||||
clock: fakeClock,
|
||||
queue: make(map[types.UID]time.Time),
|
||||
}
|
||||
return wq, fakeClock
|
||||
}
|
||||
|
||||
func compareResults(t *testing.T, expected, actual []types.UID) {
|
||||
expectedSet := sets.NewString()
|
||||
for _, u := range expected {
|
||||
expectedSet.Insert(string(u))
|
||||
}
|
||||
actualSet := sets.NewString()
|
||||
for _, u := range actual {
|
||||
actualSet.Insert(string(u))
|
||||
}
|
||||
if !expectedSet.Equal(actualSet) {
|
||||
t.Errorf("Expected %#v, got %#v", expectedSet.List(), actualSet.List())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWork(t *testing.T) {
|
||||
q, clock := newTestBasicWorkQueue()
|
||||
q.Enqueue(types.UID("foo1"), -1*time.Minute)
|
||||
q.Enqueue(types.UID("foo2"), -1*time.Minute)
|
||||
q.Enqueue(types.UID("foo3"), 1*time.Minute)
|
||||
q.Enqueue(types.UID("foo4"), 1*time.Minute)
|
||||
expected := []types.UID{types.UID("foo1"), types.UID("foo2")}
|
||||
compareResults(t, expected, q.GetWork())
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
// Dial the time to 1 hour ahead.
|
||||
clock.Step(time.Hour)
|
||||
expected = []types.UID{types.UID("foo3"), types.UID("foo4")}
|
||||
compareResults(t, expected, q.GetWork())
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
}
|
Reference in New Issue
Block a user