mirror of
				https://github.com/siderolabs/talos.git
				synced 2025-10-31 08:21:25 +01:00 
			
		
		
		
	This is next part of networkd rewrite. This implements three new resource types coupled with controllers which process the default configuration, merges and applying changes. TimeSync was set up to watch the time servers resource. This is a no-op for now, but once DHCP is implemented, this would enable time server configuration coming from DHCP. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
		
			
				
	
	
		
			97 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			2.7 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"
 | |
| )
 | |
| 
 | |
| // AddressStatusType is type of AddressStatus resource.
 | |
| const AddressStatusType = resource.Type("AddressStatuses.net.talos.dev")
 | |
| 
 | |
| // AddressStatus resource holds physical network link status.
 | |
| type AddressStatus struct {
 | |
| 	md   resource.Metadata
 | |
| 	spec AddressStatusSpec
 | |
| }
 | |
| 
 | |
| // AddressStatusSpec describes status of rendered secrets.
 | |
| type AddressStatusSpec struct {
 | |
| 	Address   netaddr.IPPrefix        `yaml:"address"`
 | |
| 	Local     netaddr.IP              `yaml:"local,omitempty"`
 | |
| 	Broadcast netaddr.IP              `yaml:"broadcast,omitempty"`
 | |
| 	Anycast   netaddr.IP              `yaml:"anycast,omitempty"`
 | |
| 	Multicast netaddr.IP              `yaml:"multicast,omitempty"`
 | |
| 	LinkIndex uint32                  `yaml:"linkIndex"`
 | |
| 	LinkName  string                  `yaml:"linkName"`
 | |
| 	Family    nethelpers.Family       `yaml:"family"`
 | |
| 	Scope     nethelpers.Scope        `yaml:"scope"`
 | |
| 	Flags     nethelpers.AddressFlags `yaml:"flags"`
 | |
| }
 | |
| 
 | |
| // NewAddressStatus initializes a AddressStatus resource.
 | |
| func NewAddressStatus(namespace resource.Namespace, id resource.ID) *AddressStatus {
 | |
| 	r := &AddressStatus{
 | |
| 		md:   resource.NewMetadata(namespace, AddressStatusType, id, resource.VersionUndefined),
 | |
| 		spec: AddressStatusSpec{},
 | |
| 	}
 | |
| 
 | |
| 	r.md.BumpVersion()
 | |
| 
 | |
| 	return r
 | |
| }
 | |
| 
 | |
| // Metadata implements resource.Resource.
 | |
| func (r *AddressStatus) Metadata() *resource.Metadata {
 | |
| 	return &r.md
 | |
| }
 | |
| 
 | |
| // Spec implements resource.Resource.
 | |
| func (r *AddressStatus) Spec() interface{} {
 | |
| 	return r.spec
 | |
| }
 | |
| 
 | |
| func (r *AddressStatus) String() string {
 | |
| 	return fmt.Sprintf("network.AddressStatus(%q)", r.md.ID())
 | |
| }
 | |
| 
 | |
| // DeepCopy implements resource.Resource.
 | |
| func (r *AddressStatus) DeepCopy() resource.Resource {
 | |
| 	return &AddressStatus{
 | |
| 		md:   r.md,
 | |
| 		spec: r.spec,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // ResourceDefinition implements meta.ResourceDefinitionProvider interface.
 | |
| func (r *AddressStatus) ResourceDefinition() meta.ResourceDefinitionSpec {
 | |
| 	return meta.ResourceDefinitionSpec{
 | |
| 		Type:             AddressStatusType,
 | |
| 		Aliases:          []resource.Type{"address", "addresses"},
 | |
| 		DefaultNamespace: NamespaceName,
 | |
| 		PrintColumns: []meta.PrintColumn{
 | |
| 			{
 | |
| 				Name:     "Address",
 | |
| 				JSONPath: `{.address}`,
 | |
| 			},
 | |
| 			{
 | |
| 				Name:     "Link",
 | |
| 				JSONPath: `{.linkName}`,
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // TypedSpec allows to access the Spec with the proper type.
 | |
| func (r *AddressStatus) TypedSpec() *AddressStatusSpec {
 | |
| 	return &r.spec
 | |
| }
 |