talos/pkg/resources/network/address_spec.go
Andrey Smirnov 6a35c8f110 feat: implement virtual IP (shared IP) network operator
Code mostly copy-pasted from the networkd implementation, but adapted to
the resource model:

* watch for etcd state to start/stop activities
* watch for kube-api-server static pod state to give up VIP when
api-server goes down

Gratuitous ARP code re-implemented to drop dependency on kube-vip (once
the old networkd code is removed).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2021-06-11 05:49:22 -07:00

85 lines
2.4 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 network
import (
"fmt"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
)
// AddressSpecType is type of AddressSpec resource.
const AddressSpecType = resource.Type("AddressSpecs.net.talos.dev")
// AddressSpec resource holds physical network link status.
type AddressSpec struct {
md resource.Metadata
spec AddressSpecSpec
}
// AddressSpecSpec describes status of rendered secrets.
type AddressSpecSpec struct {
Address netaddr.IPPrefix `yaml:"address"`
LinkName string `yaml:"linkName"`
Family nethelpers.Family `yaml:"family"`
Scope nethelpers.Scope `yaml:"scope"`
Flags nethelpers.AddressFlags `yaml:"flags"`
AnnounceWithARP bool `yaml:"announceWithARP,omitempty"`
ConfigLayer ConfigLayer `yaml:"layer"`
}
// NewAddressSpec initializes a AddressSpec resource.
func NewAddressSpec(namespace resource.Namespace, id resource.ID) *AddressSpec {
r := &AddressSpec{
md: resource.NewMetadata(namespace, AddressSpecType, id, resource.VersionUndefined),
spec: AddressSpecSpec{},
}
r.md.BumpVersion()
return r
}
// Metadata implements resource.Resource.
func (r *AddressSpec) Metadata() *resource.Metadata {
return &r.md
}
// Spec implements resource.Resource.
func (r *AddressSpec) Spec() interface{} {
return r.spec
}
func (r *AddressSpec) String() string {
return fmt.Sprintf("network.AddressSpec(%q)", r.md.ID())
}
// DeepCopy implements resource.Resource.
func (r *AddressSpec) DeepCopy() resource.Resource {
return &AddressSpec{
md: r.md,
spec: r.spec,
}
}
// ResourceDefinition implements meta.ResourceDefinitionProvider interface.
func (r *AddressSpec) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: AddressSpecType,
Aliases: []resource.Type{},
DefaultNamespace: NamespaceName,
PrintColumns: []meta.PrintColumn{},
}
}
// TypedSpec allows to access the Spec with the proper type.
func (r *AddressSpec) TypedSpec() *AddressSpecSpec {
return &r.spec
}