@@ -25,10 +25,10 @@ import (
25
25
apcli "github.com/k0sproject/k0s/pkg/autopilot/client"
26
26
apconst "github.com/k0sproject/k0s/pkg/autopilot/constant"
27
27
apdel "github.com/k0sproject/k0s/pkg/autopilot/controller/delegate"
28
- applan "github.com/k0sproject/k0s/pkg/autopilot/controller/plans"
28
+ "github.com/k0sproject/k0s/pkg/autopilot/controller/plans"
29
29
aproot "github.com/k0sproject/k0s/pkg/autopilot/controller/root"
30
- apsig "github.com/k0sproject/k0s/pkg/autopilot/controller/signal"
31
- apupdate "github.com/k0sproject/k0s/pkg/autopilot/controller/updates"
30
+ "github.com/k0sproject/k0s/pkg/autopilot/controller/signal"
31
+ "github.com/k0sproject/k0s/pkg/autopilot/controller/updates"
32
32
"github.com/k0sproject/k0s/pkg/kubernetes"
33
33
34
34
"github.com/sirupsen/logrus"
@@ -60,6 +60,8 @@ type rootController struct {
60
60
stopSubHandler subControllerStopFunc
61
61
leaseWatcherCreator leaseWatcherCreatorFunc
62
62
setupHandler setupFunc
63
+
64
+ initialized bool
63
65
}
64
66
65
67
var _ aproot.Root = (* rootController )(nil )
@@ -153,15 +155,14 @@ func (c *rootController) startSubControllerRoutine(ctx context.Context, logger *
153
155
managerOpts := crman.Options {
154
156
Scheme : scheme ,
155
157
Controller : crconfig.Controller {
156
- // Controller-runtime maintains a global checklist of controller
157
- // names and does not currently provide a way to unregister the
158
- // controller names used by discarded managers. The autopilot
159
- // controller and worker components accidentally share some
160
- // controller names. So it's necessary to suppress the global name
161
- // check because the order in which components are started is not
162
- // fully guaranteed for k0s controller nodes running an embedded
163
- // worker.
164
- SkipNameValidation : ptr .To (true ),
158
+ // If this controller is already initialized, this means that all
159
+ // controller-runtime controllers have already been successfully
160
+ // registered to another manager. However, controller-runtime
161
+ // maintains a global checklist of controller names and doesn't
162
+ // currently provide a way to unregister names from discarded
163
+ // managers. So it's necessary to suppress the global name check
164
+ // whenever things are restarted for reconfiguration.
165
+ SkipNameValidation : ptr .To (c .initialized ),
165
166
},
166
167
WebhookServer : crwebhook .NewServer (crwebhook.Options {
167
168
Port : c .cfg .ManagerPort ,
@@ -222,21 +223,24 @@ func (c *rootController) startSubControllerRoutine(ctx context.Context, logger *
222
223
}
223
224
clusterID := string (ns .UID )
224
225
225
- if err := apsig .RegisterControllers (ctx , logger , mgr , delegateMap [apdel .ControllerDelegateController ], c .cfg .K0sDataDir , clusterID ); err != nil {
226
- logger .WithError (err ).Error ("unable to register ' signal' controllers" )
226
+ if err := signal .RegisterControllers (ctx , logger , mgr , delegateMap [apdel .ControllerDelegateController ], c .cfg .K0sDataDir , clusterID ); err != nil {
227
+ logger .WithError (err ).Error ("unable to register signal controllers" )
227
228
return err
228
229
}
229
230
230
- if err := applan .RegisterControllers (ctx , logger , mgr , c .kubeClientFactory , leaderMode , delegateMap , c .cfg .ExcludeFromPlans ); err != nil {
231
- logger .WithError (err ).Error ("unable to register ' plans' controllers" )
231
+ if err := plans .RegisterControllers (ctx , logger , mgr , c .kubeClientFactory , leaderMode , delegateMap , c .cfg .ExcludeFromPlans ); err != nil {
232
+ logger .WithError (err ).Error ("unable to register plans controllers" )
232
233
return err
233
234
}
234
235
235
- if err := apupdate .RegisterControllers (ctx , logger , mgr , c .autopilotClientFactory , leaderMode , clusterID ); err != nil {
236
- logger .WithError (err ).Error ("unable to register 'update' controllers" )
236
+ if err := updates .RegisterControllers (ctx , logger , mgr , c .autopilotClientFactory , leaderMode , clusterID ); err != nil {
237
+ logger .WithError (err ).Error ("unable to register updates controllers" )
237
238
return err
238
239
}
239
240
241
+ // All the controller-runtime controllers have been registered.
242
+ c .initialized = true
243
+
240
244
// The controller-runtime start blocks until the context is cancelled.
241
245
if err := mgr .Start (ctx ); err != nil {
242
246
logger .WithError (err ).Error ("unable to run controller-runtime manager" )
0 commit comments