Skip to content

Commit d90766e

Browse files
authored
Merge pull request #6738 from twz123/disable-autopilot
Ensure that Autopilot can be disabled for real
2 parents 0dbc883 + aaea09d commit d90766e

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
@@ -448,10 +448,6 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
448448
))
449449
}
450450

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

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

525-
reconciler, err := workerconfig.NewReconciler(c.K0sVars, nodeConfig.Spec, adminClientFactory, workerConfigLeasePool, enableKonnectivity)
523+
reconciler, err := workerconfig.NewReconciler(c.K0sVars, nodeConfig.Spec, adminClientFactory, workerConfigLeasePool, enableKonnectivity, disableAutopilot)
526524
if err != nil {
527525
return err
528526
}
@@ -532,7 +530,7 @@ func (c *command) start(ctx context.Context, flags *config.ControllerOptions, de
532530
if !slices.Contains(flags.DisableComponents, constant.SystemRBACComponentName) {
533531
clusterComponents.Add(ctx, &controller.SystemRBAC{
534532
Clients: adminClientFactory,
535-
ExcludeAutopilot: slices.Contains(flags.DisableComponents, constant.AutopilotComponentName),
533+
ExcludeAutopilot: disableAutopilot,
536534
})
537535
}
538536

@@ -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
@@ -298,7 +298,7 @@ func (c *Command) Start(ctx context.Context, nodeName apitypes.NodeName, kubelet
298298

299299
certManager := worker.NewCertificateManager(kubeletKubeconfigPath)
300300

301-
addPlatformSpecificComponents(ctx, componentManager, c.K0sVars, controller, certManager)
301+
addPlatformSpecificComponents(ctx, componentManager, c.K0sVars, workerConfig, controller, certManager)
302302

303303
if controller == nil {
304304
// if running inside a controller, status component is already running

cmd/worker/worker_unix.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import (
1010

1111
"github.com/k0sproject/k0s/pkg/component/manager"
1212
"github.com/k0sproject/k0s/pkg/component/worker"
13+
workerconfig "github.com/k0sproject/k0s/pkg/component/worker/config"
1314
"github.com/k0sproject/k0s/pkg/config"
1415
)
1516

1617
func initLogging(context.Context, string) error { return nil }
1718

18-
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, controller EmbeddingController, certManager *worker.CertificateManager) {
19-
m.Add(ctx, &worker.Autopilot{
20-
K0sVars: k0sVars,
21-
CertManager: certManager,
22-
})
19+
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, workerConfig *workerconfig.Profile, controller EmbeddingController, certManager *worker.CertificateManager) {
20+
if !workerConfig.AutopilotDisabled {
21+
m.Add(ctx, &worker.Autopilot{
22+
K0sVars: k0sVars,
23+
CertManager: certManager,
24+
})
25+
}
2326
}

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(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, controller EmbeddingController, certManager *worker.CertificateManager) {
49+
func addPlatformSpecificComponents(ctx context.Context, m *manager.Manager, k0sVars *config.CfgVars, workerConfig *workerconfig.Profile, controller EmbeddingController, certManager *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)