Skip to content

Commit b898a16

Browse files
authored
Merge pull request #4230 from twz123/remove-machine-id
Replace the Machine ID usage with an "Invocation ID"
2 parents 97c8ead + 968357e commit b898a16

27 files changed

+49
-240
lines changed

cmd/controller/controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (c *command) start(ctx context.Context) error {
216216
nodeComponents.Add(ctx, storageBackend)
217217

218218
controllerLeaseCounter := &controller.K0sControllersLeaseCounter{
219+
InvocationID: c.K0sVars.InvocationID,
219220
ClusterConfig: nodeConfig,
220221
KubeClientFactory: adminClientFactory,
221222
}
@@ -265,7 +266,7 @@ func (c *command) start(ctx context.Context) error {
265266

266267
// One leader elector per controller
267268
if !c.SingleNode {
268-
leaderElector = leaderelector.NewLeasePool(adminClientFactory)
269+
leaderElector = leaderelector.NewLeasePool(c.K0sVars.InvocationID, adminClientFactory)
269270
} else {
270271
leaderElector = &leaderelector.Dummy{Leader: true}
271272
}

docker-entrypoint.sh

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
set -eu
44

5-
# Ensure we have some semi-random machine-id
6-
if [ ! -f /etc/machine-id ]; then
7-
head -c16 /dev/urandom | hexdump -v -e '16/1 "%02x""\n"' >/etc/machine-id
8-
fi
9-
105
# DNS fixup adapted from kind
116
# https://github.com/kubernetes-sigs/kind/blob/7568bf728147c1253e651f25edfd0e0a75534b8a/images/base/files/usr/local/bin/entrypoint#L447-L487
127

docs/external-runtime-deps.md

-17
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ available on Linux):
1515
k0s sysinfo
1616
```
1717

18-
## A unique machine ID for multi-node setups
19-
20-
Whenever k0s is run in a multi-node setup (i.e. the `--single` command line flag
21-
isn't used), k0s requires a [machine ID]: a unique host identifier that is
22-
somewhat stable across reboots. For Linux, this ID is read from the files
23-
`/var/lib/dbus/machine-id` or `/etc/machine-id`. For Windows, it's taken from
24-
the registry key `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid`.
25-
If neither of the OS specific sources yield a result, k0s will fallback to use a
26-
machine ID based on the hostname.
27-
28-
When running k0s on top of virtualized or containerized environments, you need
29-
to [ensure][ensure-unique-id] that hosts get their own unique IDs, even if they
30-
have been created from the same image.
31-
32-
[machine ID]: https://github.com/denisbrodbeck/machineid/blob/v1.0.1/README.md#what-you-get
33-
[ensure-unique-id]: https://github.com/denisbrodbeck/machineid/blob/v1.0.1/README.md#unique-key-reliability
34-
3518
## Linux specific
3619
<!--
3720
This piece of documentation is best-effort and considered to be augmented and

docs/raspberry-pi4.md

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ setup, you can invoke `k0s sysinfo`:
151151
152152
```console
153153
ubuntu@ubuntu:~$ k0s sysinfo
154-
Machine ID: "d84cde1f38844d1425dc04c454c5aa95e41fb11115bbb141c016f4cd3dea4f51" (from machine) (pass)
155154
Total memory: 3.7 GiB (pass)
156155
Disk space available for /var/lib/k0s: 24.3 GiB (pass)
157156
Operating system: Linux (pass)

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require (
1818
github.com/cloudflare/cfssl v1.6.4
1919
github.com/containerd/cgroups/v3 v3.0.3
2020
github.com/containerd/containerd v1.7.14
21-
github.com/denisbrodbeck/machineid v1.0.1
2221
github.com/evanphx/json-patch v5.7.0+incompatible
2322
github.com/fsnotify/fsnotify v1.7.0
2423
github.com/go-logr/logr v1.4.1

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
143143
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
144144
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
145145
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
146-
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
147-
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
148146
github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 h1:aBfCb7iqHmDEIp6fBvC/hQUddQfg+3qdYjwzaiP9Hnc=
149147
github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2/go.mod h1:WHNsWjnIn2V1LYOrME7e8KxSeKunYHsxEm4am0BUtcI=
150148
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=

hack/ostests/modules/os/os_alpine_3_17_userdata.tftpl

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env sh
22

33
truncate -s0 /etc/motd
4-
rc-update add machine-id boot
5-
/etc/init.d/machine-id start
64

75
%{if worker}
86
rc-update add cgroups boot

hack/ostests/modules/os/os_centos_7.tf

-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ locals {
3434
default = {
3535
ami_id = one(data.aws_ami.centos_7.*.id)
3636

37-
user_data = format("#cloud-config\n%s", jsonencode({
38-
bootcmd = [
39-
"rm /etc/machine-id",
40-
"systemd-machine-id-setup",
41-
]
42-
})),
43-
4437
connection = {
4538
type = "ssh"
4639
username = "centos"

internal/pkg/sysinfo/machineid/machineid.go

-69
This file was deleted.

internal/pkg/sysinfo/machineid/machineid_test.go

-35
This file was deleted.

internal/pkg/sysinfo/probes/machineid.go

-33
This file was deleted.

internal/pkg/sysinfo/sysinfo.go

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ func (s *K0sSysinfoSpec) RunPreFlightChecks(lenient bool) error {
5555
func (s *K0sSysinfoSpec) NewSysinfoProbes() probes.Probes {
5656
p := probes.NewRootProbes()
5757

58-
// https://docs.k0sproject.io/main/external-runtime-deps/#a-unique-machine-id-for-multi-node-setups
59-
probes.RequireMachineID(p)
60-
6158
// https://docs.k0sproject.io/main/system-requirements/#minimum-memory-and-cpu-requirements
6259
if s.ControllerRoleEnabled {
6360
probes.AssertTotalMemory(p, 1*probes.Gi)

inttest/bootloose-alpine/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ RUN apk add --no-cache \
2424
inotify-tools
2525
# enable syslog and sshd
2626
RUN rc-update add syslog boot
27-
RUN rc-update add machine-id boot
2827
RUN rc-update add sshd default
2928
RUN rc-update add local default
3029
RUN rc-update add nginx default

inttest/cli/cli_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func (s *CliSuite) TestK0sCliKubectlAndResetCommand() {
6363
out, err := ssh.ExecWithOutput(s.Context(), fmt.Sprintf("%s sysinfo", s.K0sFullPath))
6464
assert.NoError(t, err, "k0s sysinfo has non-zero exit code")
6565
t.Logf(out)
66-
assert.Regexp(t, "^Machine ID: ", out)
6766
assert.Regexp(t, "\nOperating system: Linux \\(pass\\)\n", out)
6867
assert.Regexp(t, "\n Linux kernel release: ", out)
6968
assert.Regexp(t, "\n CONFIG_CGROUPS: ", out)

pkg/autopilot/controller/leases.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434

3535
// LeaseWatcher outlines the lease operations for the autopilot configuration.
3636
type LeaseWatcher interface {
37-
StartWatcher(ctx context.Context, namespace string, name string) (<-chan LeaseEventStatus, <-chan error)
37+
StartWatcher(ctx context.Context, namespace string, name, identity string) (<-chan LeaseEventStatus, <-chan error)
3838
}
3939

4040
// NewLeaseWatcher creates a new `LeaseWatcher` using the appropriate clientset
@@ -57,7 +57,7 @@ type leaseWatcher struct {
5757

5858
var _ LeaseWatcher = (*leaseWatcher)(nil)
5959

60-
func (lw *leaseWatcher) StartWatcher(ctx context.Context, namespace string, name string) (<-chan LeaseEventStatus, <-chan error) {
60+
func (lw *leaseWatcher) StartWatcher(ctx context.Context, namespace string, name, identity string) (<-chan LeaseEventStatus, <-chan error) {
6161
leaseEventStatusCh := make(chan LeaseEventStatus, 10)
6262
errorCh := make(chan error, 10)
6363

@@ -83,7 +83,7 @@ func (lw *leaseWatcher) StartWatcher(ctx context.Context, namespace string, name
8383
leaderelection.WithNamespace(namespace),
8484
}
8585

86-
leasePool, err := leaderelection.NewLeasePool(ctx, lw.client, name, leasePoolOpts...)
86+
leasePool, err := leaderelection.NewLeasePool(ctx, lw.client, name, identity, leasePoolOpts...)
8787
if err != nil {
8888
errorCh <- fmt.Errorf("failed to create lease pool: %w", err)
8989
cancel()

pkg/autopilot/controller/leases_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestLeasesInitialPending(t *testing.T) {
4040
leaseWatcher, err := NewLeaseWatcher(logger, clientFactory)
4141
assert.NoError(t, err)
4242

43-
leaseEventStatusCh, errorCh := leaseWatcher.StartWatcher(ctx, constant.AutopilotNamespace, fmt.Sprintf("%s-lease", constant.AutopilotNamespace))
43+
leaseEventStatusCh, errorCh := leaseWatcher.StartWatcher(ctx, constant.AutopilotNamespace, fmt.Sprintf("%s-lease", constant.AutopilotNamespace), t.Name())
4444
assert.NotNil(t, errorCh)
4545
assert.NotNil(t, leaseEventStatusCh)
4646

pkg/autopilot/controller/root/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
// TODO: decide on renaming root.RootConfig -> root.Config
2222
// nolint:revive
2323
type RootConfig struct {
24+
InvocationID string
2425
KubeConfig string
2526
K0sDataDir string
2627
Mode string

pkg/autopilot/controller/root_controller.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func (c *rootController) Run(ctx context.Context) error {
9797
return fmt.Errorf("unable to setup lease watcher: %w", err)
9898
}
9999

100-
leaseEventStatusCh, errorCh := leaseWatcher.StartWatcher(ctx, apconst.AutopilotNamespace, fmt.Sprintf("%s-controller", apconst.AutopilotNamespace))
100+
leaseName := fmt.Sprintf("%s-controller", apconst.AutopilotNamespace)
101+
leaseIdentity := c.cfg.InvocationID
102+
103+
leaseEventStatusCh, errorCh := leaseWatcher.StartWatcher(ctx, apconst.AutopilotNamespace, leaseName, leaseIdentity)
101104

102105
var lastLeaseEventStatus LeaseEventStatus
103106
var subControllerCancel context.CancelFunc

pkg/autopilot/controller/root_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewFakeLeaseWatcher() (LeaseWatcher, chan LeaseEventStatus) {
4949
}
5050

5151
// StartWatcher for the fake LeaseWatcher just propagates the premade lease event channel
52-
func (lw *fakeLeaseWatcher) StartWatcher(ctx context.Context, namespace string, name string) (<-chan LeaseEventStatus, <-chan error) {
52+
func (lw *fakeLeaseWatcher) StartWatcher(ctx context.Context, namespace string, name, identity string) (<-chan LeaseEventStatus, <-chan error) {
5353
return lw.leaseEventStatusCh, lw.errorsCh
5454
}
5555

pkg/component/controller/autopilot.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (a *Autopilot) Start(ctx context.Context) error {
5151
}
5252

5353
autopilotRoot, err := apcont.NewRootController(aproot.RootConfig{
54+
InvocationID: a.K0sVars.InvocationID,
5455
KubeConfig: a.K0sVars.AdminKubeConfigPath,
5556
K0sDataDir: a.K0sVars.DataDir,
5657
Mode: "controller",

pkg/component/controller/controllersleasecounter.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
// K0sControllersLeaseCounter implements a component that manages a lease per controller.
3434
// The per-controller leases are used to determine the amount of currently running controllers
3535
type K0sControllersLeaseCounter struct {
36+
InvocationID string
3637
ClusterConfig *v1beta1.ClusterConfig
3738
KubeClientFactory kubeutil.ClientFactoryInterface
3839

@@ -62,13 +63,13 @@ func (l *K0sControllersLeaseCounter) Start(ctx context.Context) error {
6263

6364
// hostname used to make the lease names be clear to which controller they belong to
6465
// follow kubelet convention for naming so we e.g. use lowercase hostname etc.
65-
holderIdentity, err := node.GetNodename("")
66+
nodeName, err := node.GetNodename("")
6667
if err != nil {
6768
return nil
6869
}
69-
leaseID := fmt.Sprintf("k0s-ctrl-%s", holderIdentity)
70+
leaseName := fmt.Sprintf("k0s-ctrl-%s", nodeName)
7071

71-
leasePool, err := leaderelection.NewLeasePool(ctx, client, leaseID,
72+
leasePool, err := leaderelection.NewLeasePool(ctx, client, leaseName, l.InvocationID,
7273
leaderelection.WithLogger(log),
7374
leaderelection.WithContext(ctx))
7475
if err != nil {

0 commit comments

Comments
 (0)