forked from siderolabs/talos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: import siderolink as
siderolink-launch
subcommand
This PR ensures that we can test our siderolink communication using embedded siderolink-agent. If `--with-siderolink` provided during `talos cluster create` talosctl will embed proper kernel string and setup `siderolink-agent` as a separate process. It should be used with combination of `--skip-injecting-config` and `--with-apply-config` (the latter will use newly generated IPv6 siderolink addresses which talosctl passes to the agent as a "pre-bind"). Fixes siderolabs#8392 Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
- Loading branch information
Showing
19 changed files
with
450 additions
and
25 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,32 @@ | ||
// 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/. | ||
|
||
//go:build linux | ||
|
||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
"net/netip" | ||
|
||
"github.com/siderolabs/gen/value" | ||
"github.com/siderolabs/siderolink/pkg/wireguard" | ||
) | ||
|
||
type nodeAddrGenerator struct { | ||
prefix netip.Prefix | ||
} | ||
|
||
func (ng *nodeAddrGenerator) GenerateRandomNodeAddr() (netip.Addr, error) { | ||
if value.IsZero(ng.prefix) { | ||
ng.prefix = wireguard.NetworkPrefix("") | ||
} | ||
|
||
result, err := wireguard.GenerateRandomNodeAddr(ng.prefix) | ||
if err != nil { | ||
return netip.Addr{}, fmt.Errorf("failed to generate random node address: %w", err) | ||
} | ||
|
||
return result.Addr(), 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,18 @@ | ||
// 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/. | ||
|
||
//go:build !linux | ||
|
||
package cluster | ||
|
||
import ( | ||
"errors" | ||
"net/netip" | ||
) | ||
|
||
type nodeAddrGenerator struct{} | ||
|
||
func (ng *nodeAddrGenerator) GenerateRandomNodeAddr() (netip.Addr, error) { | ||
return netip.Addr{}, errors.New("unsupported platform") | ||
} |
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,61 @@ | ||
// 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 siderolink provides the talosctl siderolink-launch command implementation. | ||
package siderolink | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var siderolinkFlags struct { | ||
joinToken string | ||
wireguardEndpoint string | ||
sinkEndpoint string | ||
apiEndpoint string | ||
logEndpoint string | ||
predefinedPairs []string | ||
} | ||
|
||
var siderolinkCmd = &cobra.Command{ | ||
Use: "siderolink-launch", | ||
Short: "Internal command used by cluster create to launch siderolink agent", | ||
Long: ``, | ||
Args: cobra.NoArgs, | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, cancel := signal.NotifyContext(cmd.Context(), os.Interrupt) | ||
defer cancel() | ||
|
||
return run(ctx) | ||
}, | ||
} | ||
|
||
func init() { | ||
siderolinkCmd.PersistentFlags().StringVar(&siderolinkFlags.joinToken, "sidero-link-join-token", "", "join token for the cluster") | ||
siderolinkCmd.PersistentFlags().StringVar(&siderolinkFlags.wireguardEndpoint, "sidero-link-wireguard-endpoint", "", "advertised Wireguard endpoint") | ||
siderolinkCmd.PersistentFlags().StringVar(&siderolinkFlags.sinkEndpoint, "event-sink-endpoint", "", "gRPC API endpoint for the Event Sink") | ||
siderolinkCmd.PersistentFlags().StringVar(&siderolinkFlags.apiEndpoint, "sidero-link-api-endpoint", "", "gRPC API endpoint for the SideroLink") | ||
siderolinkCmd.PersistentFlags().StringVar(&siderolinkFlags.logEndpoint, "log-receiver-endpoint", "", "TCP log receiver endpoint") | ||
siderolinkCmd.PersistentFlags().StringArrayVar(&siderolinkFlags.predefinedPairs, "predefined-pair", nil, "predefined pairs of UUID=IPv6 addrs for the nodes") | ||
|
||
for _, names := range []string{ | ||
"sidero-link-join-token", | ||
"sidero-link-wireguard-endpoint", | ||
"predefined-pair", | ||
"event-sink-endpoint", | ||
"sidero-link-api-endpoint", | ||
"log-receiver-endpoint", | ||
} { | ||
err := siderolinkCmd.PersistentFlags().MarkHidden(names) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
addCommand(siderolinkCmd) | ||
} |
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,16 @@ | ||
// 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 siderolink | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Commands is a list of commands published by the package. | ||
var Commands []*cobra.Command | ||
|
||
func addCommand(cmd *cobra.Command) { | ||
Commands = append(Commands, cmd) | ||
} |
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,61 @@ | ||
// 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/. | ||
|
||
//go:build linux | ||
|
||
package siderolink | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/siderolabs/siderolink/pkg/agent" | ||
"github.com/siderolabs/siderolink/pkg/wireguard" | ||
"go.uber.org/zap" | ||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" | ||
) | ||
|
||
func run(ctx context.Context) error { | ||
logger, err := zap.NewDevelopment() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.Info("starting embedded siderolink agent") | ||
defer logger.Info("stopping embedded siderolink agent") | ||
|
||
err = agent.Run( | ||
ctx, | ||
agent.Config{ | ||
WireguardEndpoint: siderolinkFlags.wireguardEndpoint, | ||
APIEndpoint: siderolinkFlags.apiEndpoint, | ||
JoinToken: siderolinkFlags.joinToken, | ||
ForceUserspace: true, | ||
SinkEndpoint: siderolinkFlags.sinkEndpoint, | ||
LogEndpoint: siderolinkFlags.logEndpoint, | ||
UUIDIPv6Pairs: siderolinkFlags.predefinedPairs, | ||
}, | ||
&handler{l: logger}, | ||
logger, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to run siderolink agent: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type handler struct { | ||
l *zap.Logger | ||
} | ||
|
||
func (h *handler) HandlePeerAdded(event wireguard.PeerEvent) error { | ||
h.l.Info("talos agent sees peer added", zap.String("address", event.Address.String())) | ||
|
||
return nil | ||
} | ||
|
||
func (h *handler) HandlePeerRemoved(wgtypes.Key) error { | ||
return 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,16 @@ | ||
// 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/. | ||
|
||
//go:build !linux | ||
|
||
package siderolink | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
func run(context.Context) error { | ||
return errors.New("unsupported platform") | ||
} |
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
Oops, something went wrong.