dns

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dns provides the DNSService for managing Cloudflare DNS record configuration. Unlike TunnelConfigService which aggregates multiple sources, DNSService manages individual DNS records with a 1:1 mapping between K8s DNSRecord and Cloudflare DNS record.

Package dns provides types and service for DNS record configuration management.

Index

Constants

View Source
const (
	// ResourceType is the SyncState resource type for DNS records
	ResourceType = v1alpha2.SyncResourceDNSRecord

	// PriorityDNSRecord is the default priority for DNS record configuration
	PriorityDNSRecord = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DNSRecordConfig

type DNSRecordConfig struct {
	// Name is the DNS record name (e.g., "api.example.com")
	Name string `json:"name"`
	// Type is the DNS record type (A, AAAA, CNAME, TXT, MX, etc.)
	Type string `json:"type"`
	// Content is the DNS record content (e.g., IP address, CNAME target)
	Content string `json:"content"`
	// TTL is the time-to-live in seconds (1 = automatic)
	TTL int `json:"ttl,omitempty"`
	// Proxied indicates if the record is proxied through Cloudflare
	Proxied bool `json:"proxied,omitempty"`
	// Priority is used for MX and SRV records
	Priority *int `json:"priority,omitempty"`
	// Comment is a user-provided comment for the DNS record
	Comment string `json:"comment,omitempty"`
	// Tags are user-provided tags for the DNS record (Enterprise only)
	Tags []string `json:"tags,omitempty"`
	// Data contains additional record-type-specific data (SRV, CAA, etc.)
	Data *DNSRecordData `json:"data,omitempty"`
}

DNSRecordConfig represents a single DNS record configuration. Each DNSRecord K8s resource contributes one DNSRecordConfig to its SyncState.

type DNSRecordData

type DNSRecordData struct {
	// SRV record data
	Service string `json:"service,omitempty"`
	Proto   string `json:"proto,omitempty"`
	Weight  int    `json:"weight,omitempty"`
	Port    int    `json:"port,omitempty"`
	Target  string `json:"target,omitempty"`

	// CAA record data
	Flags int    `json:"flags,omitempty"`
	Tag   string `json:"tag,omitempty"`
	Value string `json:"value,omitempty"`

	// CERT/SSHFP/TLSA record data
	Algorithm    int    `json:"algorithm,omitempty"`
	Certificate  string `json:"certificate,omitempty"`
	KeyTag       int    `json:"keyTag,omitempty"`
	Usage        int    `json:"usage,omitempty"`
	Selector     int    `json:"selector,omitempty"`
	MatchingType int    `json:"matchingType,omitempty"`

	// LOC record data
	LatDegrees    int    `json:"latDegrees,omitempty"`
	LatMinutes    int    `json:"latMinutes,omitempty"`
	LatSeconds    string `json:"latSeconds,omitempty"`
	LatDirection  string `json:"latDirection,omitempty"`
	LongDegrees   int    `json:"longDegrees,omitempty"`
	LongMinutes   int    `json:"longMinutes,omitempty"`
	LongSeconds   string `json:"longSeconds,omitempty"`
	LongDirection string `json:"longDirection,omitempty"`
	Altitude      string `json:"altitude,omitempty"`
	Size          string `json:"size,omitempty"`
	PrecisionHorz string `json:"precisionHorz,omitempty"`
	PrecisionVert string `json:"precisionVert,omitempty"`

	// URI record data
	ContentURI string `json:"content,omitempty"`
}

DNSRecordData contains record-type-specific data fields. These match the API types for simplicity.

type RegisterOptions

type RegisterOptions struct {
	// ZoneID is the Cloudflare Zone ID
	ZoneID string
	// AccountID is the Cloudflare Account ID
	AccountID string
	// RecordID is the Cloudflare DNS record ID (if already created)
	// Used as the CloudflareID in SyncState for existing records
	// For new records, a placeholder is used until the record is created
	RecordID string
	// Source identifies the K8s resource contributing this configuration
	Source service.Source
	// Config contains the DNS record configuration
	Config DNSRecordConfig
	// CredentialsRef references the CloudflareCredentials to use
	CredentialsRef v1alpha2.CredentialsReference
}

RegisterOptions contains options for registering a DNS record configuration.

type Service

type Service struct {
	*service.BaseService
}

Service handles DNS record configuration registration. It implements the ConfigService interface for DNS record resources.

func NewService

func NewService(c client.Client) *Service

NewService creates a new DNSService

func (*Service) GetSyncStatus

func (s *Service) GetSyncStatus(ctx context.Context, source service.Source, knownRecordID string) (*SyncStatus, error)

GetSyncStatus returns the sync status for a DNS record. It checks the SyncState to determine if the record has been synced to Cloudflare.

func (*Service) Register

func (s *Service) Register(ctx context.Context, opts RegisterOptions) error

Register registers a DNS record configuration to SyncState. Each DNSRecord K8s resource has its own SyncState, keyed by a generated ID (namespace/name) until the Cloudflare record ID is known.

func (*Service) Unregister

func (s *Service) Unregister(ctx context.Context, recordID string, source service.Source) error

Unregister removes a DNS record's configuration from the SyncState. This is called when the DNSRecord K8s resource is deleted.

func (*Service) UpdateRecordID

func (s *Service) UpdateRecordID(ctx context.Context, source service.Source, newRecordID string) error

UpdateRecordID updates the SyncState to use the actual Cloudflare record ID after the record is created. This migrates from the pending placeholder.

type SyncResult

type SyncResult struct {
	// RecordID is the Cloudflare DNS record ID after sync
	RecordID string
	// ZoneID is the Cloudflare Zone ID
	ZoneID string
	// FQDN is the fully-qualified domain name
	FQDN string
}

SyncResult contains the result of a successful DNS record sync operation.

type SyncStatus

type SyncStatus struct {
	IsSynced    bool
	RecordID    string
	ZoneID      string
	SyncStateID string
}

SyncStatus represents the sync status of a DNS record

Jump to

Keyboard shortcuts

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