Skip to content

Commit

Permalink
feat: provide machine configuration for KubeSpan and cluster discovery
Browse files Browse the repository at this point in the history
Fixes #4131

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Aug 26, 2021
1 parent a81e30c commit 761ccaf
Show file tree
Hide file tree
Showing 11 changed files with 754 additions and 46 deletions.
30 changes: 30 additions & 0 deletions pkg/machinery/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type MachineNetwork interface {
Resolvers() []string
Devices() []Device
ExtraHosts() []ExtraHost
KubeSpan() KubeSpan
}

// ExtraHost represents a host entry in /etc/hosts.
Expand Down Expand Up @@ -207,6 +208,11 @@ type Route interface {
Metric() uint32
}

// KubeSpan configures KubeSpan feature.
type KubeSpan interface {
Enabled() bool
}

// Time defines the requirements for a config that pertains to time related
// options.
type Time interface {
Expand Down Expand Up @@ -288,6 +294,7 @@ type ClusterConfig interface {
InlineManifests() []InlineManifest
AdminKubeconfig() AdminKubeconfig
ScheduleOnMasters() bool
Discovery() Discovery
}

// ClusterNetwork defines the requirements for a config that pertains to cluster
Expand Down Expand Up @@ -432,3 +439,26 @@ type InlineManifest interface {
Name() string
Contents() string
}

// Discovery describes cluster membership discovery.
type Discovery interface {
Enabled() bool
Registries() DiscoveryRegistries
}

// DiscoveryRegistries describes discovery methods.
type DiscoveryRegistries interface {
Kubernetes() KubernetesRegistry
Service() ServiceRegistry
}

// KubernetesRegistry describes Kubernetes discovery registry.
type KubernetesRegistry interface {
Enabled() bool
}

// ServiceRegistry describes external service discovery registry.
type ServiceRegistry interface {
Enabled() bool
Endpoint() string
}
5 changes: 5 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func (c *ClusterConfig) DNSServiceIPs() ([]net.IP, error) {
return talosnet.NthIPInCIDRSet(serviceCIDRs, 10)
}

// Discovery implements the config.Cluster interface.
func (c *ClusterConfig) Discovery() config.Discovery {
return c.ClusterDiscoveryConfig
}

type clusterToken string

// ID implements the config.Token interface.
Expand Down
49 changes: 49 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_discoveryconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 v1alpha1

import (
"github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/constants"
)

// Enabled implements the config.ClusterDiscovery interface.
func (c ClusterDiscoveryConfig) Enabled() bool {
return c.DiscoveryEnabled
}

// Registries implements the config.ClusterDiscovery interface.
func (c ClusterDiscoveryConfig) Registries() config.DiscoveryRegistries {
return c.DiscoveryRegistries
}

// Kubernetes implements the config.DiscoveryRegistries interface.
func (c DiscoveryRegistriesConfig) Kubernetes() config.KubernetesRegistry {
return c.RegistryKubernetes
}

// Service implements the config.DiscoveryRegistries interface.
func (c DiscoveryRegistriesConfig) Service() config.ServiceRegistry {
return c.RegistryService
}

// Enabled implements the config.KubernetesRegistry interface.
func (c RegistryKubernetesConfig) Enabled() bool {
return !c.RegistryDisabled
}

// Enabled implements the config.ServiceRegistry interface.
func (c RegistryServiceConfig) Enabled() bool {
return !c.RegistryDisabled
}

// Endpoint implements the config.ServiceRegistry interface.
func (c RegistryServiceConfig) Endpoint() string {
if c.RegistryEndpoint == "" {
return constants.DefaultDiscoveryServiceEndpoint
}

return c.RegistryEndpoint
}
10 changes: 10 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func (n *NetworkConfig) ExtraHosts() []config.ExtraHost {
return hosts
}

// KubeSpan implements the config.Provider interface.
func (n *NetworkConfig) KubeSpan() config.KubeSpan {
return n.NetworkKubeSpan
}

// IP implements the MachineNetwork interface.
func (e *ExtraHost) IP() string {
return e.HostIP
Expand Down Expand Up @@ -872,6 +877,11 @@ func (v *Vlan) ID() uint16 {
return v.VlanID
}

// Enabled implements KubeSpan interface.
func (k NetworkKubeSpan) Enabled() bool {
return k.KubeSpanEnabled
}

// Disabled implements the config.Provider interface.
func (t *TimeConfig) Disabled() bool {
return t.TimeDisabled
Expand Down
72 changes: 72 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ metadata:
`),
},
}

networkKubeSpanExample = NetworkKubeSpan{
KubeSpanEnabled: true,
}

clusterDiscoveryExample = ClusterDiscoveryConfig{
DiscoveryEnabled: true,
DiscoveryRegistries: DiscoveryRegistriesConfig{
RegistryService: RegistryServiceConfig{
RegistryEndpoint: constants.DefaultDiscoveryServiceEndpoint,
},
},
}
)

// Config defines the v1alpha1 configuration file.
Expand Down Expand Up @@ -707,6 +720,11 @@ type ClusterConfig struct {
// - value: clusterSchedulerExample
SchedulerConfig *SchedulerConfig `yaml:"scheduler,omitempty"`
// description: |
// Configures cluster member discovery.
// examples:
// - value: clusterDiscoveryExample
ClusterDiscoveryConfig ClusterDiscoveryConfig `yaml:"discovery,omitempty"`
// description: |
// Etcd specific configuration options.
// examples:
// - value: clusterEtcdExample
Expand Down Expand Up @@ -843,6 +861,11 @@ type NetworkConfig struct {
// examples:
// - value: networkConfigExtraHostsExample
ExtraHostEntries []*ExtraHost `yaml:"extraHostEntries,omitempty"`
// description: |
// Configures KubeSpan feature.
// examples:
// - value: networkKubeSpanExample
NetworkKubeSpan NetworkKubeSpan `yaml:"kubespan,omitempty"`
}

// InstallConfig represents the installation options for preparing a node.
Expand Down Expand Up @@ -1877,3 +1900,52 @@ type ClusterInlineManifest struct {
// - value: '"/etc/kubernetes/auth"'
InlineManifestContents string `yaml:"contents"`
}

// NetworkKubeSpan struct describes KubeSpan configuration.
type NetworkKubeSpan struct {
// description: |
// Enable the KubeSpan feature.
// Cluster discovery should be enabled with .cluster.discovery.enabled for KubeSpan to be enabled.
KubeSpanEnabled bool `yaml:"enabled"`
}

// ClusterDiscoveryConfig struct configures cluster membership discovery.
type ClusterDiscoveryConfig struct {
// description: |
// Enable the cluster membership discovery feature.
// Cluster discovery is based on individual registries which are configured under the registries field.
DiscoveryEnabled bool `yaml:"enabled"`
// description: |
// Configure registries used for cluster member discovery.
DiscoveryRegistries DiscoveryRegistriesConfig `yaml:"registries"`
}

// DiscoveryRegistriesConfig struct configures cluster membership discovery.
type DiscoveryRegistriesConfig struct {
// description: |
// Kubernetes registry uses Kubernetes API server to discover cluster members and stores additional information
// as annotations on the Node resources.
RegistryKubernetes RegistryKubernetesConfig `yaml:"kubernetes"`
// description: |
// Service registry is using an external service to push and pull information about cluster members.
RegistryService RegistryServiceConfig `yaml:"service"`
}

// RegistryKubernetesConfig struct configures Kubernetes discovery registry.
type RegistryKubernetesConfig struct {
// description: |
// Disable Kubernetes discovery registry.
RegistryDisabled bool `yaml:"disabled,omitempty"`
}

// RegistryServiceConfig struct configures Kubernetes discovery registry.
type RegistryServiceConfig struct {
// description: |
// Disable external service discovery registry.
RegistryDisabled bool `yaml:"disabled,omitempty"`
// description: |
// External service endpoint.
// examples:
// - value: 'constants.DefaultDiscoveryServiceEndpoint'
RegistryEndpoint string `yaml:"endpoint,omitempty"`
}

0 comments on commit 761ccaf

Please sign in to comment.