Skip to content

Commit

Permalink
Drop usages of k8s.io/apimachinery/pkg/util/clock (gardener#6030)
Browse files Browse the repository at this point in the history
* Use k8s.io/utils/clock instead of k8s.io/apimachinery/pkg/util/clock

* Use k8s.io/utils/clock/testing instead of k8s.io/apimachinery/pkg/util/clock

* Run `make revendor`
  • Loading branch information
shafeeqes authored and Kristiyan Gostev committed Jul 5, 2022
1 parent a0728a1 commit 0581781
Show file tree
Hide file tree
Showing 52 changed files with 105 additions and 553 deletions.
2 changes: 1 addition & 1 deletion cmd/gardenlet/app/gardenlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/clock"
kubernetesclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/record"
"k8s.io/component-base/version"
"k8s.io/component-base/version/verflag"
"k8s.io/utils/clock"
runtimelog "sigs.k8s.io/controller-runtime/pkg/log"
)

Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/controller/common/checkerwatchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)

// Watchdog manages a goroutine that regularly checks if a certain condition is true,
Expand Down
6 changes: 3 additions & 3 deletions extensions/pkg/controller/common/checkerwatchdog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/clock"
testclock "k8s.io/utils/clock/testing"

. "github.com/gardener/gardener/extensions/pkg/controller/common"
)
Expand All @@ -38,15 +38,15 @@ var _ = Describe("CheckerWatchdog", func() {
var (
ctrl *gomock.Controller
checker *fakeChecker
fakeClock *clock.FakeClock
fakeClock *testclock.FakeClock
ctx context.Context
watchdog Watchdog
)

BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
checker = &fakeChecker{called: make(chan struct{}, 2)} // we expect 2 calls in every test case
fakeClock = clock.NewFakeClock(time.Now())
fakeClock = testclock.NewFakeClock(time.Now())
ctx = context.TODO()
watchdog = NewCheckerWatchdog(checker, interval, timeout, fakeClock, logr.Discard())
})
Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/controller/common/checkerwatchdogfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/clock"
testclock "k8s.io/utils/clock/testing"
"sigs.k8s.io/controller-runtime/pkg/log"
)

Expand All @@ -46,7 +46,7 @@ var _ = Describe("CheckerWatchdogFactory", func() {
checkerFactory = mockcommon.NewMockCheckerFactory(ctrl)
checker = mockcommon.NewMockChecker(ctrl)
ctx = context.TODO()
checkerWatchdogFactory = NewCheckerWatchdogFactory(checkerFactory, interval, timeout, clock.NewFakeClock(time.Now()), log.Log.WithName("test"))
checkerWatchdogFactory = NewCheckerWatchdogFactory(checkerFactory, interval, timeout, testclock.NewFakeClock(time.Now()), log.Log.WithName("test"))
})

AfterEach(func() {
Expand Down
6 changes: 3 additions & 3 deletions extensions/pkg/controller/common/watchdogmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -81,7 +81,7 @@ var (
)

// NewWatchdogManager creates a new WatchdogManager using the given watchdog factory, ttl, and logger.
func NewWatchdogManager(watchdogFactory WatchdogFactory, ttl time.Duration, clk clock.Clock, logger logr.Logger) WatchdogManager {
func NewWatchdogManager(watchdogFactory WatchdogFactory, ttl time.Duration, clk clock.WithTickerAndDelayedExecution, logger logr.Logger) WatchdogManager {
return &watchdogManager{
watchdogFactory: watchdogFactory,
ttl: ttl,
Expand All @@ -95,7 +95,7 @@ func NewWatchdogManager(watchdogFactory WatchdogFactory, ttl time.Duration, clk
type watchdogManager struct {
watchdogFactory WatchdogFactory
ttl time.Duration
clock clock.Clock
clock clock.WithTickerAndDelayedExecution
logger logr.Logger
watchdogs map[string]Watchdog
watchdogsMutex sync.Mutex
Expand Down
6 changes: 3 additions & 3 deletions extensions/pkg/controller/common/watchdogmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/clock"
testclock "k8s.io/utils/clock/testing"
"sigs.k8s.io/controller-runtime/pkg/log"
)

Expand All @@ -40,7 +40,7 @@ var _ = Describe("WatchdogManager", func() {
c *mockclient.MockClient
watchdogFactory *mockcommon.MockWatchdogFactory
watchdog *mockcommon.MockWatchdog
fakeClock *clock.FakeClock
fakeClock *testclock.FakeClock
ctx context.Context
watchdogManager WatchdogManager
)
Expand All @@ -50,7 +50,7 @@ var _ = Describe("WatchdogManager", func() {
c = mockclient.NewMockClient(ctrl)
watchdogFactory = mockcommon.NewMockWatchdogFactory(ctrl)
watchdog = mockcommon.NewMockWatchdog(ctrl)
fakeClock = clock.NewFakeClock(time.Now())
fakeClock = testclock.NewFakeClock(time.Now())
ctx = context.TODO()
watchdogManager = NewWatchdogManager(watchdogFactory, ttl, fakeClock, log.Log.WithName("test"))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import (
networkingv1 "k8s.io/api/networking/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/rest"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import (
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
mockchartrenderer "github.com/gardener/gardener/pkg/chartrenderer/mock"
mockkubernetes "github.com/gardener/gardener/pkg/client/kubernetes/mock"
mockclient "github.com/gardener/gardener/pkg/mock/controller-runtime/client"
"github.com/gardener/gardener/pkg/utils/chart"
mockchartutil "github.com/gardener/gardener/pkg/utils/chart/mocks"
gutil "github.com/gardener/gardener/pkg/utils/gardener"
"github.com/gardener/gardener/pkg/utils/imagevector"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
secretutils "github.com/gardener/gardener/pkg/utils/secrets"
secretsmanager "github.com/gardener/gardener/pkg/utils/secrets/manager"
Expand All @@ -56,15 +58,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/clock"
testclock "k8s.io/utils/clock/testing"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"

resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
"github.com/gardener/gardener/pkg/utils/imagevector"
)

const (
Expand All @@ -85,7 +85,7 @@ var (
vFalse, vTrue = false, true
pFalse, pTrue = &vFalse, &vTrue

fakeClock *clock.FakeClock
fakeClock *testclock.FakeClock
)

func TestControlPlane(t *testing.T) {
Expand Down Expand Up @@ -291,7 +291,7 @@ var _ = Describe("Actuator", func() {
}

deterministicReader := strings.NewReader(strings.Repeat("-", 10000))
fakeClock = clock.NewFakeClock(time.Unix(1649848746, 0))
fakeClock = testclock.NewFakeClock(time.Unix(1649848746, 0))

DeferCleanup(test.WithVars(
&rand.Reader, deterministicReader,
Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/util/secret/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
Expand Down
6 changes: 3 additions & 3 deletions extensions/pkg/util/secret/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
gomegatypes "github.com/onsi/gomega/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
testclock "k8s.io/utils/clock/testing"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
)
Expand All @@ -53,7 +53,7 @@ var _ = Describe("SecretsManager Extension Utils", func() {
var (
ctx = context.Background()
now metav1.Time
fakeClock *clock.FakeClock
fakeClock *testclock.FakeClock
fakeClient client.Client

caConfigs, secretConfigs []SecretConfigWithOptions
Expand All @@ -65,7 +65,7 @@ var _ = Describe("SecretsManager Extension Utils", func() {

BeforeEach(func() {
now = metav1.NewTime(time.Unix(1649825730, 0))
fakeClock = clock.NewFakeClock(now.Time)
fakeClock = testclock.NewFakeClock(now.Time)
fakeClient = fakeclient.NewClientBuilder().Build()

deterministicReader := strings.NewReader(strings.Repeat("-", 10000))
Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/webhook/certificates/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/webhook/certificates/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/webhook/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/gardener/gardener/pkg/utils/flow"
"github.com/spf13/pflag"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/rest"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/go-logr/logr"
"golang.org/x/time/rate"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"

"github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/gardener/gardener/pkg/client/kubernetes/clientmap"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/version"
testclock "k8s.io/utils/clock/testing"

"github.com/gardener/gardener/pkg/client/kubernetes/clientmap"
"github.com/gardener/gardener/pkg/client/kubernetes/clientmap/internal"
Expand Down Expand Up @@ -55,7 +55,7 @@ var _ = Describe("GenericClientMap", func() {

origMaxRefreshInterval time.Duration

fakeClock *clock.FakeClock
fakeClock *testclock.FakeClock
)

BeforeEach(func() {
Expand All @@ -65,7 +65,7 @@ var _ = Describe("GenericClientMap", func() {
csVersion = &version.Info{GitVersion: "1.18.0"}
cs.EXPECT().Version().Return(csVersion.GitVersion).AnyTimes()

fakeClock = clock.NewFakeClock(time.Now())
fakeClock = testclock.NewFakeClock(time.Now())
cm = internal.NewGenericClientMap(factory, logr.Discard(), fakeClock)

origMaxRefreshInterval = internal.MaxRefreshInterval
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/kubernetes/clientmap/internal/plant_clientmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
"sigs.k8s.io/controller-runtime/pkg/client"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/gardener/gardener/pkg/client/kubernetes/clientmap"
"github.com/gardener/gardener/pkg/utils"

corev1 "k8s.io/api/core/v1"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// plantClientMap is a ClientMap for requesting and storing clients for Plant clusters.
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/kubernetes/clientmap/internal/seed_clientmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

corev1 "k8s.io/api/core/v1"
eventsv1 "k8s.io/api/events/v1"
"k8s.io/apimachinery/pkg/util/clock"
baseconfig "k8s.io/component-base/config"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/gardener/gardener/pkg/client/kubernetes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
clientcmdv1 "k8s.io/client-go/tools/clientcmd/api/v1"
baseconfig "k8s.io/component-base/config"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllermanager/controller/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ import (
"github.com/gardener/gardener/pkg/operation/garden"
secretsmanager "github.com/gardener/gardener/pkg/utils/secrets/manager"

"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/controllermanager/controller/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ import (
"sync"
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/wait"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gardener/gardener/pkg/client/kubernetes/clientmap"
"github.com/gardener/gardener/pkg/client/kubernetes/clientmap/keys"
"github.com/gardener/gardener/pkg/controllermanager/apis/config"
"github.com/gardener/gardener/pkg/controllerutils"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down

0 comments on commit 0581781

Please sign in to comment.