-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework the way Sidero Agent boots and configures networking
1. Update `PKGS` to the latest version which has kernel with modules. 2. Pull in `udevd`, kernel modules into the Sidero Agent initramfs. 3. Stop doing kernel network configuration (`ip=dhcp`). 4. Run `udevd` in `initramfs` to auto-load kernel modules based on hardware information. 5. Pass MAC address of the NIC used to PXE boot from iPXE down to Sidero Agent. 6. In the Sidero Agent, run DHCP configuration on the link passed by MAC. Slightly refactored Sidero Agent code by pulling apart `main.go` into smaller pieces. Signed-off-by: Andrey Smirnov <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,055 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"time" | ||
|
||
"github.com/siderolabs/go-retry/retry" | ||
"github.com/siderolabs/go-smbios/smbios" | ||
|
||
"github.com/siderolabs/sidero/app/sidero-controller-manager/internal/api" | ||
) | ||
|
||
func reconcileIPs(ctx context.Context, client api.AgentClient, s *smbios.SMBIOS, ips []net.IP) error { | ||
addresses := make([]*api.Address, len(ips)) | ||
for i := range addresses { | ||
addresses[i] = &api.Address{ | ||
Type: "InternalIP", | ||
Address: ips[i].String(), | ||
} | ||
} | ||
|
||
return retry.Constant(5*time.Minute, retry.WithUnits(30*time.Second)).Retry(func() error { | ||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
|
||
_, err := client.ReconcileServerAddresses(ctx, &api.ReconcileServerAddressesRequest{ | ||
Uuid: s.SystemInformation.UUID, | ||
Address: addresses, | ||
}) | ||
if err != nil { | ||
return retry.ExpectedError(err) | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
// IPAddrs finds and returns a list of non-loopback IP addresses of the | ||
// current machine. | ||
func IPAddrs() (ips []net.IP, err error) { | ||
ips = []net.IP{} | ||
|
||
addrs, err := net.InterfaceAddrs() | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, a := range addrs { | ||
if ipnet, ok := a.(*net.IPNet); ok { | ||
if ipnet.IP.IsGlobalUnicast() && !ipnet.IP.IsLinkLocalUnicast() { | ||
ips = append(ips, ipnet.IP) | ||
} | ||
} | ||
} | ||
|
||
return ips, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net" | ||
"os" | ||
"time" | ||
|
||
"github.com/siderolabs/go-blockdevice/blockdevice/util/disk" | ||
"github.com/siderolabs/go-retry/retry" | ||
"github.com/siderolabs/go-smbios/smbios" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/siderolabs/sidero/app/sidero-controller-manager/internal/api" | ||
) | ||
|
||
func create(ctx context.Context, client api.AgentClient, s *smbios.SMBIOS) (*api.CreateServerResponse, error) { | ||
disks, err := disk.List() | ||
if err != nil { | ||
log.Printf("encountered error fetching disks: %q", err) | ||
} | ||
|
||
interfaces, err := net.Interfaces() | ||
if err != nil { | ||
log.Printf("encountered error fetching network interfaces: %q", err) | ||
} | ||
|
||
req := &api.CreateServerRequest{ | ||
Hardware: MapHardwareInformation(s, disks, interfaces), | ||
Hostname: "", | ||
} | ||
|
||
hostname, err := os.Hostname() | ||
if err != nil { | ||
log.Printf("encountered error fetching hostname: %q", err) | ||
} else { | ||
req.Hostname = hostname | ||
} | ||
|
||
var resp *api.CreateServerResponse | ||
|
||
err = retry.Constant(5*time.Minute, retry.WithUnits(30*time.Second), retry.WithErrorLogging(true)).Retry(func() error { | ||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
|
||
resp, err = client.CreateServer(ctx, req) | ||
if err != nil { | ||
return retry.ExpectedError(err) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return resp, err | ||
} | ||
|
||
func wipe(ctx context.Context, client api.AgentClient, s *smbios.SMBIOS) error { | ||
return retry.Constant(5*time.Minute, retry.WithUnits(30*time.Second), retry.WithErrorLogging(true)).Retry(func() error { | ||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
|
||
_, err := client.MarkServerAsWiped(ctx, &api.MarkServerAsWipedRequest{Uuid: s.SystemInformation.UUID}) | ||
if err != nil { | ||
return retry.ExpectedError(err) | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func connect(ctx context.Context, endpoint string) (*grpc.ClientConn, error) { | ||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
|
||
return grpc.DialContext(ctx, | ||
endpoint, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
) | ||
} |
Oops, something went wrong.