profiles

package
v0.0.0-...-e0c1c8b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHAProfiles

func GetHAProfiles(
	ctx context.Context,
	prometheusAPI prometheusv1.API,
	nodeName string,
	status metrics.PtpHAProfileStatus,
) ([]string, error)

GetHAProfiles returns a list of HA profile names matching the specified status for a given node. Use metrics.HAProfileStatusActive or metrics.HAProfileStatusInactive as the status parameter.

func GetInterfacesNames

func GetInterfacesNames(interfaces []*InterfaceInfo) []iface.Name

GetInterfacesNames returns a slice of interface names for the provided slice of InterfaceInfo pointers.

func GetNodeInfoMap

func GetNodeInfoMap(client *clients.Settings) (map[string]*NodeInfo, error)

GetNodeInfoMap retrieves a map of node names to NodeInfo structs for all nodes in the cluster that have PTP profiles recommended to them. The returned map is guaranteed to be non-nil if there is no error. Each node gets its own unique ProfileInfo instances, even if the same profile is recommended to multiple nodes.

The algorithm for determining recommendations is described in the PTP operator code: https://github.com/openshift/ptp-operator/blob/main/controllers/recommend.go. It assumes that profile names are unique.

func Oc2PortDetermineActivePassiveInterfaces

func Oc2PortDetermineActivePassiveInterfaces(
	ctx context.Context,
	prometheusAPI prometheusv1.API,
	nodeName string,
	clientInterfaces []*InterfaceInfo,
) (active iface.Name, passive iface.Name, err error)

Oc2PortDetermineActivePassiveInterfaces queries Prometheus metrics to identify which interface in an OC 2-port configuration is currently active (FOLLOWER/SLAVE) and which is passive (LISTENING). It returns an error if roles cannot be determined or are unexpected.

func RemoveProfileFromConfig

func RemoveProfileFromConfig(
	client *clients.Settings,
	profileReference ProfileReference,
) error

RemoveProfileFromConfig removes a profile from a PtpConfig by deleting it from the profile array. The profile is identified by the provided ProfileReference.

func ReplaceChronydServers

func ReplaceChronydServers(
	client *clients.Settings, profileReference ProfileReference, newServer string) (*ptpv1.PtpProfile, error)

ReplaceChronydServers replaces the servers in the chronyd configuration for the provided profile with the provided new server. It will also add iburst to the new server. It returns the old profile or an error if the update fails.

The returned old profile is deep copied, so will not be modified by this function.

func ResetHoldOverTimeouts

func ResetHoldOverTimeouts(client *clients.Settings, oldHoldovers HoldOverMap) error

ResetHoldOverTimeouts resets the HoldOverTimeout for the provided profiles to the original values. The same caveats apply where any errors in pulling or updating the configs may result in a partially modified state.

func RestoreProfileToConfig

func RestoreProfileToConfig(
	client *clients.Settings, profileReference ProfileReference, profile *ptpv1.PtpProfile) (bool, error)

RestoreProfileToConfig updates the profile referenced by the provided ProfileReference with the provided profile. It returns true if the profile was changed, false otherwise. It returns an error if the restore fails.

func SavePtpConfigs

func SavePtpConfigs(client *clients.Settings) ([]*ptp.PtpConfigBuilder, error)

SavePtpConfigs returns a list of all PtpConfigs in the cluster.

func UpdateTS2PHCHoldover

func UpdateTS2PHCHoldover(
	client *clients.Settings, profile *ProfileInfo, newHoldoverSeconds uint64) (*ptpv1.PtpProfile, error)

UpdateTS2PHCHoldover updates the holdover timeout for the ts2phc process in the PTP profile. It returns the old profile or an error if the update fails.

Updates are always done through changing the command line options, since these will override any configuration in the global section of the configuration file.

The returned old profile is deep copied, so will not be modified by this function.

func WaitForHoldOverTimeouts

func WaitForHoldOverTimeouts(
	prometheusAPI prometheusv1.API,
	nodeName string,
	profiles []*ProfileInfo,
	holdoverTimeout int64,
	timeout time.Duration) error

WaitForHoldOverTimeouts waits for the HoldOverTimeout for the provided profiles to be set to the provided value. It does the assertion for all profiles at once, so the timeout applies to all of them.

func WaitForOldHoldOverTimeouts

func WaitForOldHoldOverTimeouts(
	prometheusAPI prometheusv1.API,
	nodeName string,
	oldHoldovers HoldOverMap,
	timeout time.Duration) error

WaitForOldHoldOverTimeouts waits for the HoldOverTimeout for the provided profiles to be set to the original values. It does the assertion for all profiles at once, so the timeout applies to all of them.

Types

type HoldOverMap

type HoldOverMap map[ProfileReference]*int64

HoldOverMap is a map of profile references to the old HoldOverTimeout values. The value, in seconds, is nil if there is no PtpClockThreshold in the profile.

func SetHoldOverTimeouts

func SetHoldOverTimeouts(
	client *clients.Settings, profiles []*ProfileInfo, holdoverTimeout int64) (HoldOverMap, error)

SetHoldOverTimeouts sets the HoldOverTimeout for the provided profiles to the provided value. It returns a map of profile references to the old HoldOverTimeout values. Note that any errors in pulling or updating the configs may result in a partially modified state.

Each profile provided must be unique, otherwise the function may return the wrong original HoldOverTimeout values.

The returned map will have a key for each profile provided, with the value being nil if there is no PtpClockThreshold in the profile. Assuming it is not nil, the value will be the original HoldOverTimeout value.

func (HoldOverMap) String

func (h HoldOverMap) String() string

type InterfaceInfo

type InterfaceInfo struct {
	Name               iface.Name
	ClockType          PtpClockType
	PortIdentity       string
	ParentPortIdentity string
	// Parent is a pointer to the InterfaceInfo whose PortIdentity matches this interface's ParentPortIdentity, if any.
	// This will typically be nil because the parent is often a network switch rather than another interface on the node.
	//
	// Note: For some grandmaster configurations, ParentPortIdentity may be set to the clock identity derived from
	// PortIdentity (i.e., the same identity with a "-0" suffix). In those cases, Parent should remain nil rather than
	// becoming self-referential.
	Parent  *InterfaceInfo
	Profile *ProfileInfo
}

InterfaceInfo contains information about the PTP clock type of an interface, its parent profile, and port identity metadata. In the future, it may also contain information about which interface it is connected to.

func (*InterfaceInfo) Clone

func (interfaceInfo *InterfaceInfo) Clone() *InterfaceInfo

Clone creates a deep copy of the InterfaceInfo instance. The Profile pointer is only shallow copied, however, since it forms a circular reference.

type NodeInfo

type NodeInfo struct {
	// Name is the name of the node resource this struct is associated to.
	Name string
	// Counts records the number of each profile type recommended to this node. It will never be nil when this
	// struct is returned from a function in this package.
	Counts ProfileCounts
	// Profiles contains a list of information structs corresponding to each profile that is recommended to this
	// node. Elements should never be nil.
	Profiles []*ProfileInfo
}

NodeInfo contains all the PtpConfig-related information for a single node. Common operations are provided as methods on this type to avoid the need to aggregate and query nested data.

func (*NodeInfo) GetInterfacesByClockType

func (nodeInfo *NodeInfo) GetInterfacesByClockType(clockType PtpClockType) []*InterfaceInfo

GetInterfacesByClockType returns a slice of InterfaceInfo pointers for each interface across all profiles on this node matching the provided clockType. Elements are guaranteed not to be nil.

func (*NodeInfo) GetProfileByConfigPath

func (nodeInfo *NodeInfo) GetProfileByConfigPath(
	client *clients.Settings, nodeName string, path string) (*ProfileInfo, error)

GetProfileByConfigPath returns the ProfileInfo for the profile with the provided config path. The config path will be relative to /var/run, so it should be something like ptp4l.0.config. This function makes the assumption that the first line of the file contains the profile name.

func (*NodeInfo) GetProfileByName

func (nodeInfo *NodeInfo) GetProfileByName(name string) *ProfileInfo

GetProfileByName returns the ProfileInfo for the profile with the provided name. It returns nil if no profile is found.

func (*NodeInfo) GetProfilesByTypes

func (nodeInfo *NodeInfo) GetProfilesByTypes(profileTypes ...PtpProfileType) []*ProfileInfo

GetProfilesByTypes returns a slice of ProfileInfo pointers for each profile on this node matching any of the provided profileTypes. Returned elements are guaranteed not to be nil.

func (*NodeInfo) LinkInterfacesByPortIdentities

func (nodeInfo *NodeInfo) LinkInterfacesByPortIdentities()

LinkInterfacesByPortIdentities attempts to link interfaces on the node together based on port identity metadata. It will first clear any existing linkage to ensure the result reflects the current identities.

For each interface on the node, this method checks whether its ParentPortIdentity matches the PortIdentity of any other interface on the node. If so, it sets the interface's Parent pointer.

This is a best-effort linkage:

  • If no match is found (common when the parent is a switch), Parent is left nil.
  • It is guaranteed that no self-referential links will be created.

func (*NodeInfo) SetConfigIndices

func (nodeInfo *NodeInfo) SetConfigIndices(client *clients.Settings) error

SetConfigIndices sets the ConfigIndex for each profile on the node by inspecting the config files present in the linuxptp-daemon pod. It relies on the first line of each config file containing the profile name and maps profile names to the index embedded in the file name (e.g. ptp4l.0.config).

func (nodeInfo *NodeInfo) SetPortIdentitiesAndLink(client *clients.Settings) error

SetPortIdentitiesAndLink sets the PortIdentity and ParentPortIdentity for all interfaces across all profiles on this node by querying the linuxptp-daemon pod using pmc, then links interfaces together based on their port identities. This method will call [SetConfigIndices] to set the ConfigIndex for each profile on the node, so config indices can be unset when calling this method.

type Oc2PortInfo

type Oc2PortInfo struct {
	Interfaces       []*InterfaceInfo
	IfaceGroup       iface.NICName
	ActiveInterface  iface.Name
	PassiveInterface iface.Name
}

Oc2PortInfo stores derived OC 2-port profile and interface details.

type ProfileCounts

type ProfileCounts map[PtpProfileType]uint

ProfileCounts records the number of profiles of each type. It is provided as a map rather than a struct to allow indexing using the profile type.

type ProfileInfo

type ProfileInfo struct {
	ProfileType PtpProfileType
	Reference   ProfileReference
	// Interfaces is a map of interface names to a struct holding more detailed information. Values should never be
	// nil.
	Interfaces map[iface.Name]*InterfaceInfo
	// ConfigIndex is the number in the config file for the ptp4l corresponding to this profile. Profiles should
	// have a ptp4l process unless they are HA.
	ConfigIndex *uint
}

ProfileInfo contains information about a PTP profile. Since profiles can be readily retrieved from the cluster, it only contains information that must be parsed and a reference to the profile on the cluster.

func (*ProfileInfo) Clone

func (profileInfo *ProfileInfo) Clone() *ProfileInfo

Clone creates a deep copy of the ProfileInfo instance, including all nested InterfaceInfo structs. This ensures that modifications to the cloned ProfileInfo do not affect the original.

func (*ProfileInfo) GetInterfacesByClockType

func (profileInfo *ProfileInfo) GetInterfacesByClockType(clockType PtpClockType) []*InterfaceInfo

GetInterfacesByClockType returns a slice of InterfaceInfo pointers for each interface in the profile matching the provided clockType. Elements are guaranteed not to be nil.

func (*ProfileInfo) PullProfile

func (profileInfo *ProfileInfo) PullProfile(client *clients.Settings) (*ptpv1.PtpProfile, error)

PullProfile pulls the PTP profile for the profile referenced by this struct. If error is nil, the profile is guaranteed to not be nil.

func (*ProfileInfo) SetPortIdentities

func (profileInfo *ProfileInfo) SetPortIdentities(client *clients.Settings, nodeName string) error

SetPortIdentities sets the PortIdentity and ParentPortIdentity for each interface in the profile by querying the linuxptp-daemon pod using pmc. The ConfigIndex must be set before calling this method.

type ProfileReference

type ProfileReference struct {
	// ConfigReference is the reference to the PtpConfig object that contains the profile.
	ConfigReference runtimeclient.ObjectKey
	// ProfileIndex is the index of the profile in the PtpConfig object.
	ProfileIndex int
	// ProfileName is the name of the profile. It is not necessary to get the profile directly, but is used as a key
	// when recommending profiles to nodes.
	ProfileName string
}

ProfileReference contains the information needed to identify a profile on a cluster.

func RestorePtpConfigs

func RestorePtpConfigs(client *clients.Settings, ptpConfigList []*ptp.PtpConfigBuilder) ([]*ProfileReference, error)

RestorePtpConfigs restores the PtpConfigs from the list to the cluster. It first checks if the PtpConfig has changed using reflect.DeepEqual on the spec then updating if necessary. It collects all the errors and returns them as a single error. It returns a list of profile references that were changed.

func (*ProfileReference) PullPtpConfig

func (reference *ProfileReference) PullPtpConfig(client *clients.Settings) (*ptp.PtpConfigBuilder, error)

PullPtpConfig pulls the PtpConfig for the profile referenced by this struct.

type PtpClockType

type PtpClockType int

PtpClockType enumerates the roles of each interface. It is different from the roles in metrics, which include extra runtime values not represented in the profile. The zero value is a client and only serverOnly (or masterOnly) values of 1 indicate a server.

const (
	// ClockTypeClient indicates an interface is acting as a follower of time signals. Formerly slave.
	ClockTypeClient PtpClockType = iota
	// ClockTypeServer indicates an interface is acting as a leader of time signals. Formerly master.
	ClockTypeServer
)

type PtpProfileType

type PtpProfileType int

PtpProfileType enumerates the supported types of profiles.

const (
	// ProfileTypeOC refers to a PTP profile with a single interface set to client only. It is an ordinary clock
	// profile.
	ProfileTypeOC PtpProfileType = iota
	// ProfileTypeTwoPortOC refers to a PTP profile with two interfaces set to client only. Only one of these
	// interfaces will be active at a time.
	ProfileTypeTwoPortOC
	// ProfileTypeBC refers to a PTP profile in a boundary clock configuration, i.e., one client interface and one
	// server interface.
	ProfileTypeBC
	// ProfileTypeHA refers to a PTP profile that does not correspond to individual interfaces but indicates other
	// profiles are in a highly available configuration.
	ProfileTypeHA
	// ProfileTypeGM refers to a PTP profile for one NIC with all interfaces set to server only.
	ProfileTypeGM
	// ProfileTypeMultiNICGM refers to a PTP profile for multiple NICs where all interfaces are set to server only.
	// SMA cables are used to synchronize the NICs so they can all act as grand masters.
	ProfileTypeMultiNICGM
	// ProfileTypeNTPFallback refers to a PTP profile that is configured to fall back to NTP when GNSS sync is lost.
	// This is the same as a GM profile but with chronyd configured.
	ProfileTypeNTPFallback
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL