Skip to content

Commit

Permalink
feat: allow setting some url params for api endpoint
Browse files Browse the repository at this point in the history
This lets the operator define url params for the api endpoint. For example https://<endpoint>/?grpc_tunnel=true. Instead of only appending the jointoken, we are parsing the url and adding it using Query.Set.

Signed-off-by: Simon-Boyer <[email protected]>
Co-authored-by: Artem Chernyshev <[email protected]>
Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Simon-Boyer and Unix4ever committed May 8, 2024
1 parent 041a436 commit 16108a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/omni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func init() {
config.Config.SiderolinkWireguardAdvertisedAddress,
"advertised wireguard address which is passed down to the nodes.")
rootCmd.Flags().StringVar(&config.Config.SiderolinkWireguardBindAddress, "siderolink-wireguard-bind-addr", config.Config.SiderolinkWireguardBindAddress, "Siderolink wireguard bind address.")
rootCmd.Flags().BoolVar(&config.Config.SiderolinkUseGRPCTunnel, "siderolink-use-grpc-tunnel", false, "use gRPC tunnel to wrap wireguard traffic instead of UDP")

rootCmd.Flags().StringVar(&config.Config.MachineAPIBindAddress, "siderolink-api-bind-addr", config.Config.MachineAPIBindAddress, "SideroLink provision bind address.")
rootCmd.Flags().StringVar(&config.Config.MachineAPICertFile, "siderolink-api-cert", config.Config.MachineAPICertFile, "SideroLink TLS cert file path.")
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Params struct {
SiderolinkWireguardBindAddress string `yaml:"siderolinkWireguardBindAddress"`
SiderolinkWireguardAdvertisedAddress string `yaml:"siderolinkWireguardAdvertisedAddress"`
SiderolinkDisableLastEndpoint bool `yaml:"siderolinkDisableLastEndpoint"`
SiderolinkUseGRPCTunnel bool `yaml:"siderolinkUseGRPCTunnel"`

EventSinkPort int `yaml:"eventSinkPort"`
SideroLinkAPIURL string `yaml:"siderolinkAPIURL"`
Expand Down
18 changes: 15 additions & 3 deletions internal/pkg/siderolink/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"net"
"net/netip"
"net/url"
"os"
"strconv"
"syscall"
Expand Down Expand Up @@ -624,10 +625,21 @@ func (manager *Manager) updateConnectionParams(ctx context.Context, siderolinkCo
spec.JoinToken = siderolinkConfig.TypedSpec().Value.JoinToken
spec.WireguardEndpoint = siderolinkConfig.TypedSpec().Value.AdvertisedEndpoint

spec.Args = fmt.Sprintf("%s=%s?jointoken=%s %s=%s %s=tcp://%s",
var url *url.URL

url, err = url.Parse(spec.ApiEndpoint)
if err != nil {
return err
}

query := url.Query()
query.Set("jointoken", siderolinkConfig.TypedSpec().Value.JoinToken)
query.Set("grpc_tunnel", fmt.Sprintf("%t", config.Config.SiderolinkUseGRPCTunnel))
url.RawQuery = query.Encode()

spec.Args = fmt.Sprintf("%s=%s %s=%s %s=tcp://%s",
talosconstants.KernelParamSideroLink,
spec.ApiEndpoint,
siderolinkConfig.TypedSpec().Value.JoinToken,
url.String(),
talosconstants.KernelParamEventsSink,
net.JoinHostPort(
siderolinkConfig.TypedSpec().Value.ServerAddress,
Expand Down

0 comments on commit 16108a9

Please sign in to comment.