Skip to content

Commit 10c593b

Browse files
author
Vadim Rutkovsky
committed
certrotationcontroller: use minutes instead of days when FeatureShortCertRotation is enabled
1 parent f7c5ae4 commit 10c593b

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

pkg/cmd/certregenerationcontroller/cmd.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/spf13/cobra"
9+
"k8s.io/klog/v2"
910

1011
"k8s.io/client-go/kubernetes"
1112
"k8s.io/utils/clock"
@@ -14,8 +15,9 @@ import (
1415
configeversionedclient "github.com/openshift/client-go/config/clientset/versioned"
1516
configexternalinformers "github.com/openshift/client-go/config/informers/externalversions"
1617
"github.com/openshift/library-go/pkg/controller/controllercmd"
17-
"github.com/openshift/library-go/pkg/operator/certrotation"
18+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1819
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
20+
"github.com/openshift/library-go/pkg/operator/status"
1921
"github.com/openshift/library-go/pkg/operator/v1helpers"
2022

2123
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator"
@@ -85,8 +87,6 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
8587
return fmt.Errorf("failed to create config client: %w", err)
8688
}
8789

88-
configInformers := configexternalinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
89-
9090
kubeAPIServerInformersForNamespaces := v1helpers.NewKubeInformersForNamespaces(
9191
kubeClient,
9292
operatorclient.GlobalMachineSpecifiedConfigNamespace,
@@ -95,6 +95,8 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
9595
operatorclient.TargetNamespace,
9696
)
9797

98+
configInformers := configexternalinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
99+
98100
operatorClient, dynamicInformers, err := genericoperatorclient.NewStaticPodOperatorClient(
99101
clock,
100102
o.controllerContext.KubeConfig,
@@ -107,9 +109,30 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
107109
return err
108110
}
109111

110-
certRotationScale, err := certrotation.GetCertRotationScale(ctx, kubeClient, operatorclient.GlobalUserSpecifiedConfigNamespace)
111-
if err != nil {
112-
return err
112+
// We can't start informers until after the resources have been requested. Now is the time.
113+
kubeAPIServerInformersForNamespaces.Start(ctx.Done())
114+
dynamicInformers.Start(ctx.Done())
115+
configInformers.Start(ctx.Done())
116+
117+
desiredVersion := status.VersionForOperatorFromEnv()
118+
missingVersion := "0.0.1-snapshot"
119+
featureGateAccessor := featuregates.NewFeatureGateAccess(
120+
desiredVersion, missingVersion,
121+
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
122+
o.controllerContext.EventRecorder,
123+
)
124+
125+
go func() {
126+
featureGateAccessor.Run(ctx)
127+
}()
128+
129+
select {
130+
case <-featureGateAccessor.InitialFeatureGatesObserved():
131+
featureGates, _ := featureGateAccessor.CurrentFeatureGates()
132+
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
133+
case <-time.After(1 * time.Minute):
134+
klog.Errorf("timed out waiting for FeatureGate detection")
135+
return fmt.Errorf("timed out waiting for FeatureGate detection")
113136
}
114137

115138
kubeAPIServerCertRotationController, err := certrotationcontroller.NewCertRotationControllerOnlyWhenExpired(
@@ -118,7 +141,7 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
118141
configInformers,
119142
kubeAPIServerInformersForNamespaces,
120143
o.controllerContext.EventRecorder,
121-
certRotationScale,
144+
featureGateAccessor,
122145
)
123146
if err != nil {
124147
return err
@@ -133,11 +156,6 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
133156
return err
134157
}
135158

136-
// We can't start informers until after the resources have been requested. Now is the time.
137-
configInformers.Start(ctx.Done())
138-
kubeAPIServerInformersForNamespaces.Start(ctx.Done())
139-
dynamicInformers.Start(ctx.Done())
140-
141159
// FIXME: These are missing a wait group to track goroutines and handle graceful termination
142160
// (@deads2k wants time to think it through)
143161

pkg/operator/certrotationcontroller/certrotationcontroller.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
"k8s.io/client-go/util/workqueue"
1515
"k8s.io/klog/v2"
1616

17+
features "github.com/openshift/api/features"
1718
configinformers "github.com/openshift/client-go/config/informers/externalversions"
1819
configlisterv1 "github.com/openshift/client-go/config/listers/config/v1"
1920
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/operatorclient"
20-
"github.com/openshift/library-go/pkg/controller/factory"
2121

22+
"github.com/openshift/library-go/pkg/controller/factory"
2223
"github.com/openshift/library-go/pkg/operator/certrotation"
24+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
2325
"github.com/openshift/library-go/pkg/operator/events"
2426
"github.com/openshift/library-go/pkg/operator/v1helpers"
2527
)
@@ -53,15 +55,15 @@ func NewCertRotationController(
5355
configInformer configinformers.SharedInformerFactory,
5456
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
5557
eventRecorder events.Recorder,
56-
day time.Duration,
58+
featureGateAccessor featuregates.FeatureGateAccess,
5759
) (*CertRotationController, error) {
5860
return newCertRotationController(
5961
kubeClient,
6062
operatorClient,
6163
configInformer,
6264
kubeInformersForNamespaces,
6365
eventRecorder,
64-
day,
66+
featureGateAccessor,
6567
false,
6668
)
6769
}
@@ -72,15 +74,15 @@ func NewCertRotationControllerOnlyWhenExpired(
7274
configInformer configinformers.SharedInformerFactory,
7375
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
7476
eventRecorder events.Recorder,
75-
day time.Duration,
77+
featureGateAccessor featuregates.FeatureGateAccess,
7678
) (*CertRotationController, error) {
7779
return newCertRotationController(
7880
kubeClient,
7981
operatorClient,
8082
configInformer,
8183
kubeInformersForNamespaces,
8284
eventRecorder,
83-
day,
85+
featureGateAccessor,
8486
true,
8587
)
8688
}
@@ -91,7 +93,7 @@ func newCertRotationController(
9193
configInformer configinformers.SharedInformerFactory,
9294
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
9395
eventRecorder events.Recorder,
94-
day time.Duration,
96+
featureGateAccessor featuregates.FeatureGateAccess,
9597
refreshOnlyWhenExpired bool,
9698
) (*CertRotationController, error) {
9799
ret := &CertRotationController{
@@ -118,14 +120,18 @@ func newCertRotationController(
118120
configInformer.Config().V1().Infrastructures().Informer().AddEventHandler(ret.externalLoadBalancerHostnameEventHandler())
119121

120122
rotationDay := defaultRotationDay
121-
if day != time.Duration(0) {
122-
rotationDay = day
123-
klog.Warningf("!!! UNSUPPORTED VALUE SET !!!")
124-
klog.Warningf("Certificate rotation base set to %q", rotationDay)
125-
} else {
126-
// for the development cycle, make the rotation 60 times faster (every twelve hours or so).
127-
// This must be reverted before we ship
128-
rotationDay = rotationDay / 60
123+
// for the development cycle, make the rotation 60 times faster (every twelve hours or so).
124+
// This must be reverted before we ship
125+
rotationDay = rotationDay / 60
126+
127+
// Set custom rotation duration when FeatureShortCertRotation is enabled
128+
featureGates, err := featureGateAccessor.CurrentFeatureGates()
129+
if err != nil {
130+
return nil, fmt.Errorf("unable to get FeatureGates: %w", err)
131+
}
132+
133+
if featureGates.Enabled(features.FeatureShortCertRotation) {
134+
rotationDay = time.Minute
129135
}
130136

131137
certRotator := certrotation.NewCertRotationController(

pkg/operator/starter.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/webhooksupportabilitycontroller"
4545
"github.com/openshift/library-go/pkg/controller/controllercmd"
4646
"github.com/openshift/library-go/pkg/operator/apiserver/controller/auditpolicy"
47-
"github.com/openshift/library-go/pkg/operator/certrotation"
4847
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
4948
"github.com/openshift/library-go/pkg/operator/encryption"
5049
"github.com/openshift/library-go/pkg/operator/encryption/controllers/migrators"
@@ -356,18 +355,13 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
356355
controllerContext.Clock,
357356
)
358357

359-
certRotationScale, err := certrotation.GetCertRotationScale(ctx, kubeClient, operatorclient.GlobalUserSpecifiedConfigNamespace)
360-
if err != nil {
361-
return err
362-
}
363-
364358
certRotationController, err := certrotationcontroller.NewCertRotationController(
365359
kubeClient,
366360
operatorClient,
367361
configInformers,
368362
kubeInformersForNamespaces,
369363
controllerContext.EventRecorder.WithComponentSuffix("cert-rotation-controller"),
370-
certRotationScale,
364+
featureGateAccessor,
371365
)
372366
if err != nil {
373367
return err

0 commit comments

Comments
 (0)