Skip to content

Commit d9c372b

Browse files
committed
certrotation: adapt by passing clock through API
Signed-off-by: Alex Kalenyuk <[email protected]>
1 parent f065c32 commit d9c372b

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

pkg/operator/controller/BUILD.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ go_library(
6666
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
6767
"//vendor/k8s.io/client-go/tools/record:go_default_library",
6868
"//vendor/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1:go_default_library",
69+
"//vendor/k8s.io/utils/clock:go_default_library",
6970
"//vendor/k8s.io/utils/ptr:go_default_library",
7071
"//vendor/kubevirt.io/controller-lifecycle-operator-sdk/api:go_default_library",
7172
"//vendor/kubevirt.io/controller-lifecycle-operator-sdk/pkg/sdk:go_default_library",
@@ -122,6 +123,7 @@ go_test(
122123
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
123124
"//vendor/k8s.io/client-go/tools/record:go_default_library",
124125
"//vendor/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1:go_default_library",
126+
"//vendor/k8s.io/utils/clock/testing:go_default_library",
125127
"//vendor/kubevirt.io/controller-lifecycle-operator-sdk/api:go_default_library",
126128
"//vendor/kubevirt.io/controller-lifecycle-operator-sdk/pkg/sdk/callbacks:go_default_library",
127129
"//vendor/kubevirt.io/controller-lifecycle-operator-sdk/pkg/sdk/reconciler:go_default_library",

pkg/operator/controller/certrotation.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"k8s.io/client-go/kubernetes"
3636
listerscorev1 "k8s.io/client-go/listers/core/v1"
3737
toolscache "k8s.io/client-go/tools/cache"
38+
"k8s.io/utils/clock"
3839

3940
"sigs.k8s.io/controller-runtime/pkg/manager"
4041

@@ -76,7 +77,7 @@ func NewCertManager(mgr manager.Manager, installNamespace string, additionalName
7677
return nil, err
7778
}
7879

79-
cm := newCertManager(k8sClient, installNamespace, additionalNamespaces...)
80+
cm := newCertManager(k8sClient, installNamespace, clock.RealClock{}, additionalNamespaces...)
8081

8182
// so we can start caches
8283
if err = mgr.Add(cm); err != nil {
@@ -86,7 +87,7 @@ func NewCertManager(mgr manager.Manager, installNamespace string, additionalName
8687
return cm, nil
8788
}
8889

89-
func newCertManager(client kubernetes.Interface, installNamespace string, additionalNamespaces ...string) *certManager {
90+
func newCertManager(client kubernetes.Interface, installNamespace string, clock clock.PassiveClock, additionalNamespaces ...string) *certManager {
9091
namespaces := append(additionalNamespaces, installNamespace)
9192
informers := v1helpers.NewKubeInformersForNamespaces(client, namespaces...)
9293

@@ -95,7 +96,7 @@ func newCertManager(client kubernetes.Interface, installNamespace string, additi
9596
log.Info("Unable to get controller reference, using namespace")
9697
}
9798

98-
eventRecorder := events.NewRecorder(client.CoreV1().Events(installNamespace), installNamespace, controllerRef)
99+
eventRecorder := events.NewRecorder(client.CoreV1().Events(installNamespace), installNamespace, controllerRef, clock)
99100

100101
return &certManager{
101102
namespaces: namespaces,

pkg/operator/controller/certrotation_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/client-go/kubernetes"
1717
"k8s.io/client-go/kubernetes/fake"
18+
clocktesting "k8s.io/utils/clock/testing"
1819

1920
"sigs.k8s.io/controller-runtime/pkg/client"
2021

@@ -48,7 +49,7 @@ func newFakeCertManager(crClient client.Client, namespace string) CertManager {
4849
}
4950

5051
func newCertManagerForTest(client kubernetes.Interface, namespace string) CertManager {
51-
return newCertManager(client, namespace)
52+
return newCertManager(client, namespace, clocktesting.NewFakePassiveClock(time.Now()))
5253
}
5354

5455
func toSerializedCertConfig(l, r time.Duration) string {

0 commit comments

Comments
 (0)