diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 70ffd6c7..dd0c9058 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -879,9 +879,12 @@ "Rev": "3cfe88295d20b6299bd935131fc0fd17316405ad" }, { - "ImportPath": "k8s.io/apimachinery/pkg/util/clock", - "Comment": "kubernetes-1.9.0-alpha.1-65-g18a564b", - "Rev": "18a564baac720819100827c16fdebcadb05b2d0d" + "ImportPath": "k8s.io/utils/clock", + "Rev": "aedf551cdb8b0119df3a19c65fde413a13b34997" + }, + { + "ImportPath": "k8s.io/utils/clock/testing", + "Rev": "aedf551cdb8b0119df3a19c65fde413a13b34997" } ] } diff --git a/manager/container.go b/manager/container.go index 5dd1191e..1c3194bb 100644 --- a/manager/container.go +++ b/manager/container.go @@ -40,8 +40,7 @@ import ( units "github.com/docker/go-units" "github.com/golang/glog" - - "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/utils/clock" ) // Housekeeping interval. diff --git a/manager/container_test.go b/manager/container_test.go index abad92c3..e1f3203b 100644 --- a/manager/container_test.go +++ b/manager/container_test.go @@ -34,8 +34,7 @@ import ( "github.com/mindprince/gonvml" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "k8s.io/apimachinery/pkg/util/clock" + clock "k8s.io/utils/clock/testing" ) const ( diff --git a/manager/manager.go b/manager/manager.go index 01482022..69c59b68 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -50,7 +50,7 @@ import ( "github.com/golang/glog" "github.com/opencontainers/runc/libcontainer/cgroups" - "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/utils/clock" ) var globalHousekeepingInterval = flag.Duration("global_housekeeping_interval", 1*time.Minute, "Interval between global housekeepings") diff --git a/manager/manager_test.go b/manager/manager_test.go index 82482e15..5268dd4c 100644 --- a/manager/manager_test.go +++ b/manager/manager_test.go @@ -34,8 +34,9 @@ import ( itest "github.com/google/cadvisor/info/v1/test" "github.com/google/cadvisor/info/v2" "github.com/google/cadvisor/utils/sysfs/fakesysfs" + "github.com/stretchr/testify/assert" - "k8s.io/apimachinery/pkg/util/clock" + clock "k8s.io/utils/clock/testing" ) // TODO(vmarmol): Refactor these tests. diff --git a/vendor/k8s.io/apimachinery/pkg/util/clock/BUILD b/vendor/k8s.io/apimachinery/pkg/util/clock/BUILD deleted file mode 100644 index 62ad5a87..00000000 --- a/vendor/k8s.io/apimachinery/pkg/util/clock/BUILD +++ /dev/null @@ -1,33 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "@io_bazel_rules_go//go:def.bzl", - "go_library", - "go_test", -) - -go_test( - name = "go_default_test", - srcs = ["clock_test.go"], - importpath = "k8s.io/apimachinery/pkg/util/clock", - library = ":go_default_library", -) - -go_library( - name = "go_default_library", - srcs = ["clock.go"], - importpath = "k8s.io/apimachinery/pkg/util/clock", -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], -) diff --git a/vendor/k8s.io/apimachinery/LICENSE b/vendor/k8s.io/utils/LICENSE similarity index 100% rename from vendor/k8s.io/apimachinery/LICENSE rename to vendor/k8s.io/utils/LICENSE diff --git a/vendor/k8s.io/utils/clock/clock.go b/vendor/k8s.io/utils/clock/clock.go new file mode 100644 index 00000000..3d53c62b --- /dev/null +++ b/vendor/k8s.io/utils/clock/clock.go @@ -0,0 +1,94 @@ +/* +Copyright 2014 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 clock + +import "time" + +// Clock allows for injecting fake or real clocks into code that +// needs to do arbitrary things based on time. +type Clock interface { + Now() time.Time + Since(time.Time) time.Duration + After(d time.Duration) <-chan time.Time + NewTimer(d time.Duration) Timer + Sleep(d time.Duration) + Tick(d time.Duration) <-chan time.Time +} + +var _ = Clock(RealClock{}) + +// RealClock really calls time.Now() +type RealClock struct{} + +// Now returns the current time. +func (RealClock) Now() time.Time { + return time.Now() +} + +// Since returns time since the specified timestamp. +func (RealClock) Since(ts time.Time) time.Duration { + return time.Since(ts) +} + +// Same as time.After(d). +func (RealClock) After(d time.Duration) <-chan time.Time { + return time.After(d) +} + +func (RealClock) NewTimer(d time.Duration) Timer { + return &realTimer{ + timer: time.NewTimer(d), + } +} + +func (RealClock) Tick(d time.Duration) <-chan time.Time { + return time.Tick(d) +} + +func (RealClock) Sleep(d time.Duration) { + time.Sleep(d) +} + +// Timer allows for injecting fake or real timers into code that +// needs to do arbitrary things based on time. +type Timer interface { + C() <-chan time.Time + Stop() bool + Reset(d time.Duration) bool +} + +var _ = Timer(&realTimer{}) + +// realTimer is backed by an actual time.Timer. +type realTimer struct { + timer *time.Timer +} + +// C returns the underlying timer's channel. +func (r *realTimer) C() <-chan time.Time { + return r.timer.C +} + +// Stop calls Stop() on the underlying timer. +func (r *realTimer) Stop() bool { + return r.timer.Stop() +} + +// Reset calls Reset() on the underlying timer. +func (r *realTimer) Reset(d time.Duration) bool { + return r.timer.Reset(d) +} diff --git a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go b/vendor/k8s.io/utils/clock/testing/fake_clock.go similarity index 72% rename from vendor/k8s.io/apimachinery/pkg/util/clock/clock.go rename to vendor/k8s.io/utils/clock/testing/fake_clock.go index c303a212..2ee48b73 100644 --- a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go +++ b/vendor/k8s.io/utils/clock/testing/fake_clock.go @@ -14,63 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -package clock +package testing import ( "sync" "time" -) -// Clock allows for injecting fake or real clocks into code that -// needs to do arbitrary things based on time. -type Clock interface { - Now() time.Time - Since(time.Time) time.Duration - After(d time.Duration) <-chan time.Time - NewTimer(d time.Duration) Timer - Sleep(d time.Duration) - Tick(d time.Duration) <-chan time.Time -} + "k8s.io/utils/clock" +) var ( - _ = Clock(RealClock{}) - _ = Clock(&FakeClock{}) - _ = Clock(&IntervalClock{}) + _ = clock.Clock(&FakeClock{}) + _ = clock.Clock(&IntervalClock{}) ) -// RealClock really calls time.Now() -type RealClock struct{} - -// Now returns the current time. -func (RealClock) Now() time.Time { - return time.Now() -} - -// Since returns time since the specified timestamp. -func (RealClock) Since(ts time.Time) time.Duration { - return time.Since(ts) -} - -// Same as time.After(d). -func (RealClock) After(d time.Duration) <-chan time.Time { - return time.After(d) -} - -func (RealClock) NewTimer(d time.Duration) Timer { - return &realTimer{ - timer: time.NewTimer(d), - } -} - -func (RealClock) Tick(d time.Duration) <-chan time.Time { - return time.Tick(d) -} - -func (RealClock) Sleep(d time.Duration) { - time.Sleep(d) -} - -// FakeClock implements Clock, but returns an arbitrary time. +// FakeClock implements clock.Clock, but returns an arbitrary time. type FakeClock struct { lock sync.RWMutex time time.Time @@ -121,7 +79,7 @@ func (f *FakeClock) After(d time.Duration) <-chan time.Time { } // Fake version of time.NewTimer(d). -func (f *FakeClock) NewTimer(d time.Duration) Timer { +func (f *FakeClock) NewTimer(d time.Duration) clock.Timer { f.lock.Lock() defer f.lock.Unlock() stopTime := f.time.Add(d) @@ -211,7 +169,7 @@ func (f *FakeClock) Sleep(d time.Duration) { f.Step(d) } -// IntervalClock implements Clock, but each invocation of Now steps the clock forward the specified duration +// IntervalClock implements clock.Clock, but each invocation of Now steps the clock forward the specified duration type IntervalClock struct { Time time.Time Duration time.Duration @@ -236,7 +194,7 @@ func (*IntervalClock) After(d time.Duration) <-chan time.Time { // Unimplemented, will panic. // TODO: make interval clock use FakeClock so this can be implemented. -func (*IntervalClock) NewTimer(d time.Duration) Timer { +func (*IntervalClock) NewTimer(d time.Duration) clock.Timer { panic("IntervalClock doesn't implement NewTimer") } @@ -250,40 +208,9 @@ func (*IntervalClock) Sleep(d time.Duration) { panic("IntervalClock doesn't implement Sleep") } -// Timer allows for injecting fake or real timers into code that -// needs to do arbitrary things based on time. -type Timer interface { - C() <-chan time.Time - Stop() bool - Reset(d time.Duration) bool -} +var _ = clock.Timer(&fakeTimer{}) -var ( - _ = Timer(&realTimer{}) - _ = Timer(&fakeTimer{}) -) - -// realTimer is backed by an actual time.Timer. -type realTimer struct { - timer *time.Timer -} - -// C returns the underlying timer's channel. -func (r *realTimer) C() <-chan time.Time { - return r.timer.C -} - -// Stop calls Stop() on the underlying timer. -func (r *realTimer) Stop() bool { - return r.timer.Stop() -} - -// Reset calls Reset() on the underlying timer. -func (r *realTimer) Reset(d time.Duration) bool { - return r.timer.Reset(d) -} - -// fakeTimer implements Timer based on a FakeClock. +// fakeTimer implements clock.Timer based on a FakeClock. type fakeTimer struct { fakeClock *FakeClock waiter fakeClockWaiter