Skip to content

Commit c6bb260

Browse files
committed
Ensure that Autopilot can be disabled for real
The disable component flag only guarded the CRD and RBAC application, but the actual Autopilot components were still started. Add the new field autopilotDisabled to the worker profiles config map to transport this information over to the workers. See: 9ec69a2 ("Apply Autopilot RBAC only when Autopilot is enabled") Signed-off-by: Tom Wieczorek <[email protected]>
1 parent e959ba4 commit c6bb260

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

cmd/controller/controller.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,6 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
447447
))
448448
}
449449

450-
if !slices.Contains(flags.DisableComponents, constant.AutopilotComponentName) {
451-
clusterComponents.Add(ctx, controller.NewCRD(c.K0sVars.ManifestsDir, "autopilot"))
452-
}
453-
454450
if enableK0sEndpointReconciler {
455451
clusterComponents.Add(ctx, controller.NewEndpointReconciler(
456452
nodeConfig,
@@ -512,13 +508,15 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
512508
clusterComponents.Add(ctx, metrics)
513509
}
514510

511+
disableAutopilot := slices.Contains(flags.DisableComponents, constant.AutopilotComponentName)
512+
515513
if !slices.Contains(flags.DisableComponents, constant.WorkerConfigComponentName) {
516514
// Create new dedicated leasepool for worker config reconciler
517515
leaseName := fmt.Sprintf("k0s-%s-%s", constant.WorkerConfigComponentName, constant.KubernetesMajorMinorVersion)
518516
workerConfigLeasePool := leaderelector.NewLeasePool(c.K0sVars.InvocationID, adminClientFactory, leaseName)
519517
clusterComponents.Add(ctx, workerConfigLeasePool)
520518

521-
reconciler, err := workerconfig.NewReconciler(c.K0sVars, nodeConfig.Spec, adminClientFactory, workerConfigLeasePool, enableKonnectivity)
519+
reconciler, err := workerconfig.NewReconciler(c.K0sVars, nodeConfig.Spec, adminClientFactory, workerConfigLeasePool, enableKonnectivity, disableAutopilot)
522520
if err != nil {
523521
return err
524522
}
@@ -528,7 +526,7 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
528526
if !slices.Contains(flags.DisableComponents, constant.SystemRBACComponentName) {
529527
clusterComponents.Add(ctx, &controller.SystemRBAC{
530528
Clients: adminClientFactory,
531-
ExcludeAutopilot: slices.Contains(flags.DisableComponents, constant.AutopilotComponentName),
529+
ExcludeAutopilot: disableAutopilot,
532530
})
533531
}
534532

@@ -577,13 +575,16 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
577575
logrus.Info("Telemetry is disabled")
578576
}
579577

580-
clusterComponents.Add(ctx, &controller.Autopilot{
581-
K0sVars: c.K0sVars,
582-
KubeletExtraArgs: c.KubeletExtraArgs,
583-
KubeAPIPort: nodeConfig.Spec.API.Port,
584-
AdminClientFactory: adminClientFactory,
585-
Workloads: controllerMode.WorkloadsEnabled(),
586-
})
578+
if !disableAutopilot {
579+
clusterComponents.Add(ctx, controller.NewCRD(c.K0sVars.ManifestsDir, "autopilot"))
580+
clusterComponents.Add(ctx, &controller.Autopilot{
581+
K0sVars: c.K0sVars,
582+
KubeletExtraArgs: c.KubeletExtraArgs,
583+
KubeAPIPort: nodeConfig.Spec.API.Port,
584+
AdminClientFactory: adminClientFactory,
585+
Workloads: controllerMode.WorkloadsEnabled(),
586+
})
587+
}
587588

588589
if !slices.Contains(flags.DisableComponents, constant.UpdateProberComponentName) {
589590
clusterComponents.Add(ctx, controller.NewUpdateProber(

cmd/worker/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (c *Command) Start(ctx context.Context, nodeName apitypes.NodeName, kubelet
296296

297297
certManager := worker.NewCertificateManager(kubeletKubeconfigPath)
298298

299-
addPlatformSpecificComponents(ctx, componentManager, c.K0sVars, controller, certManager)
299+
addPlatformSpecificComponents(ctx, componentManager, c.K0sVars, workerConfig, controller, certManager)
300300

301301
// extract needed components
302302
if err := componentManager.Init(ctx); err != nil {

cmd/worker/worker_unix.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
"github.com/k0sproject/k0s/pkg/component/prober"
1515
"github.com/k0sproject/k0s/pkg/component/status"
1616
"github.com/k0sproject/k0s/pkg/component/worker"
17+
workerconfig "github.com/k0sproject/k0s/pkg/component/worker/config"
1718
"github.com/k0sproject/k0s/pkg/config"
1819
)
1920

2021
func initLogging(context.Context, string) error { return nil }
2122

22-
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, controller EmbeddingController, certManager *worker.CertificateManager) {
23+
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, workerConfig *workerconfig.Profile, controller EmbeddingController, certManager *worker.CertificateManager) {
2324
// if running inside a controller, status component is already running
2425
if controller == nil {
2526
m.Add(ctx, &status.Status{
@@ -41,8 +42,10 @@ func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sV
4142
})
4243
}
4344

44-
m.Add(ctx, &worker.Autopilot{
45-
K0sVars: k0sVars,
46-
CertManager: certManager,
47-
})
45+
if !workerConfig.AutopilotDisabled {
46+
m.Add(ctx, &worker.Autopilot{
47+
K0sVars: k0sVars,
48+
CertManager: certManager,
49+
})
50+
}
4851
}

cmd/worker/worker_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/k0sproject/k0s/internal/pkg/log"
1515
"github.com/k0sproject/k0s/pkg/component/manager"
1616
"github.com/k0sproject/k0s/pkg/component/worker"
17+
workerconfig "github.com/k0sproject/k0s/pkg/component/worker/config"
1718
"github.com/k0sproject/k0s/pkg/config"
1819
"github.com/k0sproject/k0s/pkg/constant"
1920
"github.com/k0sproject/k0s/pkg/k0scontext"
@@ -45,6 +46,6 @@ func initLogging(ctx context.Context, logDir string) error {
4546
return nil
4647
}
4748

48-
func addPlatformSpecificComponents(context.Context, *manager.Manager, *config.CfgVars, EmbeddingController, *worker.CertificateManager) {
49+
func addPlatformSpecificComponents(context.Context, *manager.Manager, *config.CfgVars, *workerconfig.Profile, EmbeddingController, *worker.CertificateManager) {
4950
// no-op
5051
}

pkg/component/controller/workerconfig/reconciler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Reconciler struct {
5454
clientFactory kubeutil.ClientFactoryInterface
5555
leaderElector leaderelector.Interface
5656
konnectivityEnabled bool
57+
autopilotDisabled bool
5758

5859
mu sync.Mutex
5960
state reconcilerState
@@ -82,7 +83,7 @@ var (
8283
)
8384

8485
// NewReconciler creates a new reconciler for worker configurations.
85-
func NewReconciler(k0sVars *config.CfgVars, nodeSpec *v1beta1.ClusterSpec, clientFactory kubeutil.ClientFactoryInterface, leaderElector leaderelector.Interface, konnectivityEnabled bool) (*Reconciler, error) {
86+
func NewReconciler(k0sVars *config.CfgVars, nodeSpec *v1beta1.ClusterSpec, clientFactory kubeutil.ClientFactoryInterface, leaderElector leaderelector.Interface, konnectivityEnabled, autopilotDisabled bool) (*Reconciler, error) {
8687
log := logrus.WithFields(logrus.Fields{"component": "workerconfig.Reconciler"})
8788

8889
clusterDNSIPString, err := nodeSpec.Network.DNSAddress()
@@ -102,6 +103,7 @@ func NewReconciler(k0sVars *config.CfgVars, nodeSpec *v1beta1.ClusterSpec, clien
102103
clientFactory: clientFactory,
103104
leaderElector: leaderElector,
104105
konnectivityEnabled: konnectivityEnabled,
106+
autopilotDisabled: autopilotDisabled,
105107

106108
state: reconcilerCreated,
107109
}
@@ -602,7 +604,8 @@ func (r *Reconciler) buildProfile(snapshot *snapshot) *workerconfig.Profile {
602604
Enabled: r.konnectivityEnabled,
603605
AgentPort: snapshot.konnectivityAgentPort,
604606
},
605-
DualStackEnabled: snapshot.dualStackEnabled,
607+
DualStackEnabled: snapshot.dualStackEnabled,
608+
AutopilotDisabled: r.autopilotDisabled,
606609
}
607610

608611
if workerProfile.NodeLocalLoadBalancing != nil &&

pkg/component/controller/workerconfig/reconciler_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestReconciler_Lifecycle(t *testing.T) {
5959
clients,
6060
&leaderelector.Dummy{Leader: true},
6161
true,
62+
false,
6263
)
6364
require.NoError(t, err)
6465
underTest.log = newTestLogger(t)
@@ -314,6 +315,7 @@ func TestReconciler_ResourceGeneration(t *testing.T) {
314315
clients,
315316
&leaderelector.Dummy{Leader: true},
316317
true,
318+
false,
317319
)
318320
require.NoError(t, err)
319321
underTest.log = newTestLogger(t)
@@ -497,6 +499,7 @@ func TestReconciler_ReconcilesOnChangesOnly(t *testing.T) {
497499
clients,
498500
&leaderelector.Dummy{Leader: true},
499501
true,
502+
false,
500503
)
501504
require.NoError(t, err)
502505
underTest.log = newTestLogger(t)
@@ -647,6 +650,7 @@ func TestReconciler_LeaderElection(t *testing.T) {
647650
clients,
648651
&le,
649652
true,
653+
false,
650654
)
651655
require.NoError(t, err)
652656

pkg/component/worker/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Profile struct {
2727
Konnectivity Konnectivity
2828
PauseImage *v1beta1.ImageSpec
2929
DualStackEnabled bool
30+
AutopilotDisabled bool
3031
}
3132

3233
func (p *Profile) DeepCopy() *Profile {
@@ -143,6 +144,7 @@ func forEachConfigMapEntry(profile *Profile, f func(fieldName string, ptr any))
143144
"konnectivity": &profile.Konnectivity,
144145
"pauseImage": &profile.PauseImage,
145146
"dualStackEnabled": &profile.DualStackEnabled,
147+
"autopilotDisabled": &profile.AutopilotDisabled,
146148
} {
147149
f(fieldName, ptr)
148150
}

0 commit comments

Comments
 (0)