Documentation
¶
Index ¶
- Constants
- func AreClusterNetworkVlanAnnotationsUnchanged(cn *networkv1.ClusterNetwork, vidstr, vidhash string) bool
- func AreEqualMTUs(MTU1, MTU2 int) bool
- func AreJobLabelsDHCPInfoUnchanged(lb map[string]string, l2netconf *NetConf, l3netconf *Layer3NetworkConf) bool
- func CheckBridgeName(brName string) error
- func EnsureSysctlValue(name, value string) error
- func FilterFirstActiveStorageNetworkNad(nads []*nadv1.NetworkAttachmentDefinition) *nadv1.NetworkAttachmentDefinition
- func GenerateBondName(prefix string) string
- func GenerateBridgeName(prefix string) string
- func GetBridgeNamePrefix(brName string) (string, error)
- func GetClusterNetworkDevicePrefix(cnName string) string
- func GetClusterNetworkFromBridgeName(brName string) (string, error)
- func GetLabelKeyOfClusterNetwork(clusterNetwork string) string
- func GetMTUFromAnnotation(annotation string) (int, error)
- func GetMTUFromVlanConfig(vc *networkv1.VlanConfig) int
- func GetNadAnnotation(nad *nadv1.NetworkAttachmentDefinition, key string) string
- func GetNadLabel(nad *nadv1.NetworkAttachmentDefinition, key string) string
- func GetNadNameFromProvider(provider string) (nadName string, nadNamespace string, err error)
- func GetProviderFromNad(nadName string, nadNamespace string) (provider string, err error)
- func HasClusterNetworkDevicePrefix(link, prefix string) bool
- func HasLabelKey(lbs map[string]string, key string, value string) bool
- func HasMgmtClusterNetworkDevicePrefix(link string) bool
- func HasMgmtClusterNetworkLabelKey(lbs map[string]string) bool
- func HasWitnessNodeLabelKey(lbs map[string]string) bool
- func IsBridgeNameValid(brName string) (bool, error)
- func IsClusterNetworkNameValid(nm string) (bool, error)
- func IsDefaultMTU(MTU int) bool
- func IsManagementClusterNetwork(cnName string) bool
- func IsNadNetworkLabelSet(nad *nadv1.NetworkAttachmentDefinition) bool
- func IsOverlayNad(nad *nadv1.NetworkAttachmentDefinition) bool
- func IsReservedSubnet(subnetName string, provider string) (bool, error)
- func IsStorageNetworkNad(nad *nadv1.NetworkAttachmentDefinition) bool
- func IsValidMTU(MTU int) bool
- func IsVlanNad(nad *nadv1.NetworkAttachmentDefinition) bool
- func Name(prefix string, s ...string) string
- func NewSelector(selector map[string]string) (labels.Selector, error)
- func OutdateLayer3NetworkConfPerMode(conf string) (string, error)
- func OutdateNadLayer3NetworkConf(nad *nadv1.NetworkAttachmentDefinition, nadConf *NetConf) (map[string]string, error)
- func OutdateNadLayer3NetworkConfWhenRouteModeChanges(oldNad, newNad *nadv1.NetworkAttachmentDefinition) (map[string]string, error)
- func SetClusterNetworkVlanAnnotations(cn *networkv1.ClusterNetwork, vidstr, vidhash string)
- func SetDHCPInfo2JobLabels(lb map[string]string, l2netconf *NetConf, l3netconf *Layer3NetworkConf)
- func SetLogLevel(level string)
- func SetMgmtClusterNetworkLabelKey(lbs map[string]string)
- func SetNadAnnotation(nad *nadv1.NetworkAttachmentDefinition, key, value string)
- func SetNadLabel(nad *nadv1.NetworkAttachmentDefinition, key, value string)
- type Connectivity
- type Layer3NetworkConf
- type Mode
- type NadGetter
- func (n *NadGetter) GetFirstActiveStorageNetworkNadOnClusterNetwork(cnName string) (*nadv1.NetworkAttachmentDefinition, error)
- func (n *NadGetter) ListNadsOnClusterNetwork(cnName string) ([]*nadv1.NetworkAttachmentDefinition, error)
- func (n *NadGetter) NadNamesOnClusterNetwork(cnName string) ([]string, error)
- type NadSelectedNetworks
- type NetConf
- func (nc *NetConf) GetClusterNetworkName() (string, error)
- func (nc *NetConf) GetNetworkType() (NetworkType, error)
- func (nc *NetConf) GetVlan() int
- func (nc *NetConf) GetVlanString() string
- func (nc *NetConf) IsBridgeCNI() bool
- func (nc *NetConf) IsKubeOVNCNI() bool
- func (nc *NetConf) IsL2VlanNetwork() bool
- func (nc *NetConf) IsL2VlanTrunkNetwork() bool
- func (nc *NetConf) IsUntaggedNetwork() bool
- func (nc *NetConf) IsVlanAccessMode() bool
- func (nc *NetConf) IsVlanConfigValid() (bool, error)
- func (nc *NetConf) IsVlanTrunkMode() bool
- func (nc *NetConf) SetNetworkInfoToLabels(label map[string]string) error
- type NetworkType
- type VMGetter
- func (v *VMGetter) VMNamesWhoUseNad(nad *nadv1.NetworkAttachmentDefinition) ([]string, error)
- func (v *VMGetter) VMNamesWhoUseNads(nads []*nadv1.NetworkAttachmentDefinition) ([]string, error)
- func (v *VMGetter) WhoUseNad(nad *nadv1.NetworkAttachmentDefinition) ([]*kubevirtv1.VirtualMachine, error)
- func (v *VMGetter) WhoUseNads(nads []*nadv1.NetworkAttachmentDefinition) ([]*kubevirtv1.VirtualMachine, error)
- type VlanIDSet
- func GeVlanIDSetFromClusterNetwork(cnName string, nadCache ctlcniv1.NetworkAttachmentDefinitionCache) (*VlanIDSet, error)
- func NewVlanIDSet() *VlanIDSet
- func NewVlanIDSetFromNadList(nads []*nadv1.NetworkAttachmentDefinition) (*VlanIDSet, error)
- func NewVlanIDSetFromSingleVID(vid int) (*VlanIDSet, error)
- func (vis *VlanIDSet) Append(other *VlanIDSet) error
- func (vis *VlanIDSet) ConvertToTrunkMode()
- func (vis *VlanIDSet) Diff(existing *VlanIDSet) (added, removed *VlanIDSet, err error)
- func (vis *VlanIDSet) GetVlanCount() uint32
- func (vis *VlanIDSet) SetUint16VID(vid uint16) error
- func (vis *VlanIDSet) SetVID(vid int) error
- func (vis *VlanIDSet) VidSetToString() string
- func (vis *VlanIDSet) VidSetToStringHash() (str, hash string)
- func (vis *VlanIDSet) WalkVIDs(name string, callback func(vid uint16) error) error
- type VlanTrunk
- type VmiGetter
- func (v *VmiGetter) VmiNamesWhoUseNad(nad *nadv1.NetworkAttachmentDefinition, filterFlag bool, ...) ([]string, error)
- func (v *VmiGetter) VmiNamesWhoUseNads(nads []*nadv1.NetworkAttachmentDefinition, filterFlag bool, ...) ([]string, error)
- func (v *VmiGetter) WhoUseNad(nad *nadv1.NetworkAttachmentDefinition, filterFlag bool, ...) ([]*kubevirtv1.VirtualMachineInstance, error)
- func (v *VmiGetter) WhoUseNads(nads []*nadv1.NetworkAttachmentDefinition, filterFlag bool, ...) ([]*kubevirtv1.VirtualMachineInstance, error)
Constants ¶
const ( BridgeSuffix = "-br" BondSuffix = "-bo" DefaultValueMiimon = 100 LenOfBridgeSuffix = 3 // length of BridgeSuffix LenOfBondSuffix = 3 // length of BondSuffix MaxDeviceNameLen = 15 VlanSubInterfaceSpliter = "." // format: e.g. mgmt-br.2025 ManagementClusterNetworkDevicePrefix = ManagementClusterNetworkName + BridgeSuffix + VlanSubInterfaceSpliter )
const ( DefaultMTU = 1500 MaxMTU = 9000 MinMTU = 576 // IPv4 does not define this explicitly; IPv6 defines 1280; Some protocol requires 576; hence 576 is used HarvesterSystemNamespaceName = "harvester-system" // don't import harvester/pkg/util to avoid loop importing, define it directly )
const ( KeyVlanLabel = network.GroupName + "/vlan-id" KeyVlanConfigLabel = network.GroupName + "/vlanconfig" KeyClusterNetworkLabel = network.GroupName + "/clusternetwork" KeyNodeLabel = network.GroupName + "/node" KeyNetworkType = network.GroupName + "/type" KeyLastNetworkType = network.GroupName + "/last-type" KeyNetworkReady = network.GroupName + "/ready" KeyNetworkRoute = network.GroupName + "/route" KeyNetworkRouteSourceVID = network.GroupName + "/route-source-vid" // the source vid of this route KeyMTUSourceVlanConfig = network.GroupName + "/mtu-source-vc" // the VC which syncs MTU to CN KeyUplinkMTU = network.GroupName + "/uplink-mtu" // configured MTU on the VC'uplink KeyMatchedNodes = network.GroupName + "/matched-nodes" KeyVlanIDSetStr = network.GroupName + "/vlan-id-set-str" // all vlan ids under current cluster network, format "1,2,3..." KeyVlanIDSetStrHash = network.GroupName + "/vlan-id-set-str-hash" // hash value of above string KeyVlanDHCPServerIP = network.GroupName + "/vlan-dhcp-server-ip" ValueTrue = "true" ValueFalse = "false" HarvesterWitnessNodeLabelKey = "node-role.harvesterhci.io/witness" HarvesterMgmtClusterNetworkLabeyKey = network.GroupName + "/" + ManagementClusterNetworkName // defined in Harvester pkg/controller/master/storagenetwork/storage_network.go // to avoid loop references, needs to wait until Harvester move this to its const and then refers to StorageNetworkAnnotation = "storage-network.settings.harvesterhci.io" StorageNetworkNetAttachDefPrefix = "storagenetwork-" )
const ( CNITypeKubeOVN = "kube-ovn" CNITypeBridge = "bridge" CNITypeDefaultEmpty = "" // potential empty type, is treated as CNITypeBridge )
const ( MaxVlanID = 4094 MinVlanID = 0 MinTrunkVlanID = 1 DefaultVlanID = 1 VlanIDCount = 4096 VlanIDStringJoinChar = "," )
const ManagementClusterNetworkName = "mgmt"
const (
MaxClusterNetworkNameLen = MaxDeviceNameLen - LenOfBridgeSuffix
)
const (
VMByNetworkIndex = "vm.harvesterhci.io/vm-by-network"
)
Variables ¶
This section is empty.
Functions ¶
func AreClusterNetworkVlanAnnotationsUnchanged ¶ added in v1.7.0
func AreClusterNetworkVlanAnnotationsUnchanged(cn *networkv1.ClusterNetwork, vidstr, vidhash string) bool
func AreEqualMTUs ¶ added in v1.6.0
func AreJobLabelsDHCPInfoUnchanged ¶ added in v1.7.0
func AreJobLabelsDHCPInfoUnchanged(lb map[string]string, l2netconf *NetConf, l3netconf *Layer3NetworkConf) bool
func CheckBridgeName ¶ added in v1.7.0
check if the bridge name is valid
func EnsureSysctlValue ¶ added in v0.3.0
func FilterFirstActiveStorageNetworkNad ¶ added in v1.6.0
func FilterFirstActiveStorageNetworkNad(nads []*nadv1.NetworkAttachmentDefinition) *nadv1.NetworkAttachmentDefinition
filter the first active storage network nad from a list of nads
func GenerateBondName ¶ added in v1.7.0
func GenerateBridgeName ¶ added in v1.7.0
func GetBridgeNamePrefix ¶ added in v1.7.0
get the bridge name exclude the suffix
func GetClusterNetworkDevicePrefix ¶ added in v1.7.0
e.g. cn2-br.2025 is a valid vlan sub interface, and the device prefix is `cn2-br.`
func GetClusterNetworkFromBridgeName ¶ added in v1.7.0
func GetLabelKeyOfClusterNetwork ¶ added in v1.7.0
func GetMTUFromAnnotation ¶ added in v1.6.0
func GetMTUFromVlanConfig ¶ added in v1.6.0
func GetMTUFromVlanConfig(vc *networkv1.VlanConfig) int
caller handlers the return value of 0 which is normally treated as the default MTU
func GetNadAnnotation ¶ added in v1.7.0
func GetNadAnnotation(nad *nadv1.NetworkAttachmentDefinition, key string) string
func GetNadLabel ¶ added in v1.7.0
func GetNadLabel(nad *nadv1.NetworkAttachmentDefinition, key string) string
func GetNadNameFromProvider ¶ added in v1.6.0
func GetProviderFromNad ¶ added in v1.6.0
func HasClusterNetworkDevicePrefix ¶ added in v1.7.0
func HasLabelKey ¶ added in v1.7.0
func HasMgmtClusterNetworkDevicePrefix ¶ added in v1.7.0
func HasMgmtClusterNetworkLabelKey ¶ added in v1.7.0
func HasWitnessNodeLabelKey ¶ added in v1.7.0
func IsBridgeNameValid ¶ added in v1.7.0
func IsClusterNetworkNameValid ¶ added in v1.7.0
func IsDefaultMTU ¶ added in v1.6.0
func IsManagementClusterNetwork ¶ added in v1.7.0
func IsNadNetworkLabelSet ¶ added in v1.7.0
func IsNadNetworkLabelSet(nad *nadv1.NetworkAttachmentDefinition) bool
func IsOverlayNad ¶ added in v1.7.0
func IsOverlayNad(nad *nadv1.NetworkAttachmentDefinition) bool
func IsReservedSubnet ¶ added in v1.6.0
func IsStorageNetworkNad ¶ added in v1.6.0
func IsStorageNetworkNad(nad *nadv1.NetworkAttachmentDefinition) bool
if this nad is a storagenetwork nad
func IsValidMTU ¶ added in v1.6.0
func IsVlanNad ¶ added in v0.3.2
func IsVlanNad(nad *nadv1.NetworkAttachmentDefinition) bool
func NewSelector ¶ added in v0.3.0
func OutdateLayer3NetworkConfPerMode ¶ added in v1.7.0
func OutdateNadLayer3NetworkConf ¶ added in v1.7.0
func OutdateNadLayer3NetworkConfWhenRouteModeChanges ¶ added in v1.7.0
func OutdateNadLayer3NetworkConfWhenRouteModeChanges(oldNad, newNad *nadv1.NetworkAttachmentDefinition) (map[string]string, error)
caller ensurs this function is only called when oldNad and newNad have same vlan id the first return is not nil only when real change happens
func SetClusterNetworkVlanAnnotations ¶ added in v1.7.0
func SetClusterNetworkVlanAnnotations(cn *networkv1.ClusterNetwork, vidstr, vidhash string)
func SetDHCPInfo2JobLabels ¶ added in v1.7.0
func SetDHCPInfo2JobLabels(lb map[string]string, l2netconf *NetConf, l3netconf *Layer3NetworkConf)
func SetLogLevel ¶ added in v1.7.0
func SetLogLevel(level string)
func SetMgmtClusterNetworkLabelKey ¶ added in v1.7.0
func SetNadAnnotation ¶ added in v1.7.0
func SetNadAnnotation(nad *nadv1.NetworkAttachmentDefinition, key, value string)
func SetNadLabel ¶ added in v1.7.0
func SetNadLabel(nad *nadv1.NetworkAttachmentDefinition, key, value string)
Types ¶
type Connectivity ¶
type Connectivity string
const ( Connectable Connectivity = "true" Unconnectable Connectivity = "false" DHCPFailed Connectivity = "DHCP failed" PingFailed Connectivity = "ping failed" )
type Layer3NetworkConf ¶
type Layer3NetworkConf struct {
Mode Mode `json:"mode,omitempty"`
CIDR string `json:"cidr,omitempty"`
Gateway string `json:"gateway,omitempty"`
ServerIPAddr string `json:"serverIPAddr,omitempty"`
Connectivity Connectivity `json:"connectivity,omitempty"`
Outdated bool `json:"outdated,omitempty"`
}
func NewLayer3NetworkConf ¶
func NewLayer3NetworkConf(conf string) (*Layer3NetworkConf, error)
func NewLayer3NetworkConfFromNad ¶ added in v1.7.0
func NewLayer3NetworkConfFromNad(nad *nadv1.NetworkAttachmentDefinition) (*Layer3NetworkConf, error)
func (*Layer3NetworkConf) GetDHCPServerIPAddr ¶ added in v1.7.0
func (c *Layer3NetworkConf) GetDHCPServerIPAddr() string
func (*Layer3NetworkConf) ToString ¶
func (c *Layer3NetworkConf) ToString() (string, error)
type NadGetter ¶ added in v1.6.0
type NadGetter struct {
// contains filtered or unexported fields
}
func NewNadGetter ¶ added in v1.6.0
func NewNadGetter(nadCache ctlcniv1.NetworkAttachmentDefinitionCache) *NadGetter
func (*NadGetter) GetFirstActiveStorageNetworkNadOnClusterNetwork ¶ added in v1.6.0
func (n *NadGetter) GetFirstActiveStorageNetworkNadOnClusterNetwork(cnName string) (*nadv1.NetworkAttachmentDefinition, error)
func (*NadGetter) ListNadsOnClusterNetwork ¶ added in v1.6.0
func (n *NadGetter) ListNadsOnClusterNetwork(cnName string) ([]*nadv1.NetworkAttachmentDefinition, error)
list all nads attached to a cluster network
type NadSelectedNetworks ¶
type NadSelectedNetworks []nadv1.NetworkSelectionElement
func NewNADSelectedNetworks ¶
func NewNADSelectedNetworks(conf string) (NadSelectedNetworks, error)
func (NadSelectedNetworks) ToString ¶
func (n NadSelectedNetworks) ToString() (string, error)
type NetConf ¶ added in v0.3.0
type NetConf struct {
cniv1.NetConf
BrName string `json:"bridge"`
IsGW bool `json:"isGateway"`
IsDefaultGW bool `json:"isDefaultGateway"`
ForceAddress bool `json:"forceAddress"`
IPMasq bool `json:"ipMasq"`
MTU int `json:"mtu"`
HairpinMode bool `json:"hairpinMode"`
PromiscMode bool `json:"promiscMode"`
Vlan int `json:"vlan"`
Provider string `json:"provider"`
VlanTrunk []*VlanTrunk `json:"vlanTrunk,omitempty"`
}
L2 mode
func DecodeNadConfigToNetConf ¶ added in v1.7.0
func DecodeNadConfigToNetConf(nad *nadv1.NetworkAttachmentDefinition) (*NetConf, error)
decode nad config string to a config struct
func (*NetConf) GetClusterNetworkName ¶ added in v1.7.0
func (*NetConf) GetNetworkType ¶ added in v1.7.0
func (nc *NetConf) GetNetworkType() (NetworkType, error)
func (*NetConf) GetVlanString ¶ added in v1.7.0
func (*NetConf) IsBridgeCNI ¶ added in v1.7.0
func (*NetConf) IsKubeOVNCNI ¶ added in v1.7.0
func (*NetConf) IsL2VlanNetwork ¶ added in v1.7.0
func (*NetConf) IsL2VlanTrunkNetwork ¶ added in v1.7.0
func (*NetConf) IsUntaggedNetwork ¶ added in v1.7.0
func (*NetConf) IsVlanAccessMode ¶ added in v1.7.0
the default mode
func (*NetConf) IsVlanConfigValid ¶ added in v1.7.0
if vlanconfig is valid
func (*NetConf) IsVlanTrunkMode ¶ added in v1.7.0
if VlanTrunk is configured
type NetworkType ¶ added in v0.3.2
type NetworkType string
const ( L2VlanNetwork NetworkType = "L2VlanNetwork" L2VlanTrunkNetwork NetworkType = "L2VlanTrunkNetwork" UntaggedNetwork NetworkType = "UntaggedNetwork" OverlayNetwork NetworkType = "OverlayNetwork" InvalidNetwork NetworkType = "InvalidNetwork" )
type VMGetter ¶ added in v1.6.0
type VMGetter struct {
// contains filtered or unexported fields
}
func NewVMGetter ¶ added in v1.6.0
func NewVMGetter(vmCache ctlkubevirtv1.VirtualMachineCache) *VMGetter
func (*VMGetter) VMNamesWhoUseNad ¶ added in v1.6.0
func (v *VMGetter) VMNamesWhoUseNad(nad *nadv1.NetworkAttachmentDefinition) ([]string, error)
Get the vm name list who uses the nad
func (*VMGetter) VMNamesWhoUseNads ¶ added in v1.6.0
func (v *VMGetter) VMNamesWhoUseNads(nads []*nadv1.NetworkAttachmentDefinition) ([]string, error)
Get the vm name list who uses a group of nads, note: duplicated names are removed
func (*VMGetter) WhoUseNad ¶ added in v1.6.0
func (v *VMGetter) WhoUseNad(nad *nadv1.NetworkAttachmentDefinition) ([]*kubevirtv1.VirtualMachine, error)
WhoUseNad requires adding network indexer to the vm cache before invoking it
func (*VMGetter) WhoUseNads ¶ added in v1.6.0
func (v *VMGetter) WhoUseNads(nads []*nadv1.NetworkAttachmentDefinition) ([]*kubevirtv1.VirtualMachine, error)
Get the vm lists who uses a group of nads, note: duplicated vmis may exist when they attache to mutli nads
type VlanIDSet ¶ added in v1.7.0
type VlanIDSet struct {
// contains filtered or unexported fields
}
func GeVlanIDSetFromClusterNetwork ¶ added in v1.7.0
func GeVlanIDSetFromClusterNetwork(cnName string, nadCache ctlcniv1.NetworkAttachmentDefinitionCache) (*VlanIDSet, error)
func NewVlanIDSetFromNadList ¶ added in v1.7.0
func NewVlanIDSetFromNadList(nads []*nadv1.NetworkAttachmentDefinition) (*VlanIDSet, error)
return vidsets from all bridge nads
func NewVlanIDSetFromSingleVID ¶ added in v1.7.0
for l2 vlan & untag, it can hold only 1 vid
func (*VlanIDSet) ConvertToTrunkMode ¶ added in v1.7.0
func (vis *VlanIDSet) ConvertToTrunkMode()
when run Append() or Diff(), if the vidset is in single mode, convert it to trunk mode first
func (*VlanIDSet) Diff ¶ added in v1.7.0
according to current and the existing vlandidset, compute the to be added and removed vidset
func (*VlanIDSet) GetVlanCount ¶ added in v1.7.0
func (*VlanIDSet) SetUint16VID ¶ added in v1.7.0
refer pkg/network/iface/vlan.go, which uses uint16 as vid
func (*VlanIDSet) VidSetToString ¶ added in v1.7.0
func (*VlanIDSet) VidSetToStringHash ¶ added in v1.7.0
type VlanTrunk ¶ added in v1.7.0
type VmiGetter ¶ added in v0.3.2
type VmiGetter struct {
VmiCache ctlkubevirtv1.VirtualMachineInstanceCache
}
func NewVmiGetter ¶ added in v1.6.0
func NewVmiGetter(vmiCache ctlkubevirtv1.VirtualMachineInstanceCache) *VmiGetter
func (*VmiGetter) VmiNamesWhoUseNad ¶ added in v1.6.0
func (v *VmiGetter) VmiNamesWhoUseNad(nad *nadv1.NetworkAttachmentDefinition, filterFlag bool, nodesFilter mapset.Set[string]) ([]string, error)
Get the vmi name list who uses the nad
func (*VmiGetter) VmiNamesWhoUseNads ¶ added in v1.6.0
func (v *VmiGetter) VmiNamesWhoUseNads(nads []*nadv1.NetworkAttachmentDefinition, filterFlag bool, nodesFilter mapset.Set[string]) ([]string, error)
Get the vmi name list who uses a group of nads, note: duplicated names are removed
func (*VmiGetter) WhoUseNad ¶ added in v0.3.2
func (v *VmiGetter) WhoUseNad(nad *nadv1.NetworkAttachmentDefinition, filterFlag bool, nodesFilter mapset.Set[string]) ([]*kubevirtv1.VirtualMachineInstance, error)
WhoUseNad requires adding network indexer to the vmi cache before invoking it when filterFlag is true, it ensures the return vmis are on the given nodesFilter
func (*VmiGetter) WhoUseNads ¶ added in v1.6.0
func (v *VmiGetter) WhoUseNads(nads []*nadv1.NetworkAttachmentDefinition, filterFlag bool, nodesFilter mapset.Set[string]) ([]*kubevirtv1.VirtualMachineInstance, error)
Get the vmi lists who uses a group of nads, note: duplicated vmis may exist when they attache to mutli nads