Andrey Smirnov aa14993539
feat: introduce network probes
Network probes are configured with the specs, and provide their output
as a status.

At the moment only platform code can configure network probes.

If any network probes are configured, they affect network.Status
'Connectivity' flag.

Example, create the probe:

```
talosctl -n 172.20.0.3 meta write 0xa '{"probes": [{"interval": "1s", "tcp": {"endpoint": "google.com:80", "timeout": "10s"}}]}'
```

Watch probe status:

```
$ talosctl -n 172.20.0.3 get probe
NODE         NAMESPACE   TYPE          ID                  VERSION   SUCCESS
172.20.0.3   network     ProbeStatus   tcp:google.com:80   5         true
```

With failing probes:

```
$ talosctl -n 172.20.0.3 get probe
NODE         NAMESPACE   TYPE          ID                  VERSION   SUCCESS
172.20.0.3   network     ProbeStatus   tcp:google.com:80   4         true
172.20.0.3   network     ProbeStatus   tcp:google.com:81   1         false
$ talosctl -n 172.20.0.3 get networkstatus
NODE         NAMESPACE   TYPE            ID       VERSION   ADDRESS   CONNECTIVITY   HOSTNAME   ETC
172.20.0.3   network     NetworkStatus   status   5         true      true           true       true

```

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2023-03-31 15:20:21 +04:00

64 lines
2.3 KiB
Go

// 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 runtime
import (
"context"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-procfs/procfs"
"github.com/siderolabs/talos/pkg/machinery/resources/network"
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
)
// Platform defines the requirements for a platform.
type Platform interface {
// Name returns platform name.
Name() string
// Mode returns platform mode (metal, cloud or container).
Mode() Mode
// Configuration fetches the machine configuration from platform-specific location.
//
// On cloud-like platform it is user-data in metadata service.
// For metal platform that is either `talos.config=` URL or mounted ISO image.
Configuration(context.Context, state.State) ([]byte, error)
// KernelArgs returns additional kernel arguments which should be injected for the kernel boot.
KernelArgs() procfs.Parameters
// NetworkConfiguration fetches network configuration from the platform metadata.
//
// Controller will run this in function a separate goroutine, restarting it
// on error. Platform is expected to deliver network configuration over the channel,
// including updates to the configuration over time.
NetworkConfiguration(context.Context, state.State, chan<- *PlatformNetworkConfig) error
}
// PlatformNetworkConfig describes the network configuration produced by the platform.
//
// This structure is marshaled to STATE partition to persist cached network configuration across
// reboots.
type PlatformNetworkConfig struct {
Addresses []network.AddressSpecSpec `yaml:"addresses"`
Links []network.LinkSpecSpec `yaml:"links"`
Routes []network.RouteSpecSpec `yaml:"routes"`
Hostnames []network.HostnameSpecSpec `yaml:"hostnames"`
Resolvers []network.ResolverSpecSpec `yaml:"resolvers"`
TimeServers []network.TimeServerSpecSpec `yaml:"timeServers"`
Operators []network.OperatorSpecSpec `yaml:"operators"`
ExternalIPs []netip.Addr `yaml:"externalIPs"`
Probes []network.ProbeSpecSpec `yaml:"probes,omitempty"`
Metadata *runtime.PlatformMetadataSpec `yaml:"metadata,omitempty"`
}