ntp

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ntp provides NTP server management via chrony.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Servers []string `json:"servers"`
}

Config represents an NTP server configuration to deploy.

type CreateResult

type CreateResult struct {
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

CreateResult represents the outcome of an NTP config create operation.

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as chrony NTP management is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) Create

func (d *Darwin) Create(
	_ context.Context,
	_ Config,
) (*CreateResult, error)

Create returns ErrUnsupported on Darwin.

func (*Darwin) Delete

func (d *Darwin) Delete(
	_ context.Context,
) (*DeleteResult, error)

Delete returns ErrUnsupported on Darwin.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
) (*Status, error)

Get returns ErrUnsupported on Darwin.

func (*Darwin) Update

func (d *Darwin) Update(
	_ context.Context,
	_ Config,
) (*UpdateResult, error)

Update returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems using chrony for NTP management.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	execManager exec.Manager,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) Create

func (d *Debian) Create(
	_ context.Context,
	config Config,
) (*CreateResult, error)

Create deploys a managed NTP server configuration via a chrony drop-in file. Idempotent: returns Changed: false if already managed.

func (*Debian) Delete

func (d *Debian) Delete(
	_ context.Context,
) (*DeleteResult, error)

Delete removes the managed NTP server configuration. Fails if the config file does not exist.

func (*Debian) Get

func (d *Debian) Get(
	_ context.Context,
) (*Status, error)

Get returns current NTP sync status and configured servers by running chronyc tracking and chronyc sources -c.

func (*Debian) Update

func (d *Debian) Update(
	_ context.Context,
	config Config,
) (*UpdateResult, error)

Update replaces the managed NTP server configuration. Fails if the config file does not exist. Idempotent: returns Changed false when the content SHA matches.

type DeleteResult

type DeleteResult struct {
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

DeleteResult represents the outcome of an NTP config delete operation.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported as this is a generic Linux stub.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) Create

func (l *Linux) Create(
	_ context.Context,
	_ Config,
) (*CreateResult, error)

Create returns ErrUnsupported on generic Linux.

func (*Linux) Delete

func (l *Linux) Delete(
	_ context.Context,
) (*DeleteResult, error)

Delete returns ErrUnsupported on generic Linux.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
) (*Status, error)

Get returns ErrUnsupported on generic Linux.

func (*Linux) Update

func (l *Linux) Update(
	_ context.Context,
	_ Config,
) (*UpdateResult, error)

Update returns ErrUnsupported on generic Linux.

type Provider

type Provider interface {
	// Get returns current NTP sync status and configured servers.
	Get(ctx context.Context) (*Status, error)
	// Create deploys a managed NTP server configuration. Idempotent: returns Changed: false if already managed.
	Create(ctx context.Context, config Config) (*CreateResult, error)
	// Update replaces the managed NTP server configuration. Fails if not managed.
	Update(ctx context.Context, config Config) (*UpdateResult, error)
	// Delete removes the managed NTP server configuration.
	Delete(ctx context.Context) (*DeleteResult, error)
}

Provider implements the methods to manage NTP configuration.

type Status

type Status struct {
	Synchronized  bool     `json:"synchronized"`
	Stratum       int      `json:"stratum,omitempty"`
	Offset        string   `json:"offset,omitempty"`
	CurrentSource string   `json:"current_source,omitempty"`
	Servers       []string `json:"servers,omitempty"`
}

Status represents the current NTP sync state and configured servers.

type UpdateResult

type UpdateResult struct {
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

UpdateResult represents the outcome of an NTP config update operation.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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