service

package
v0.23.1 Latest Latest
Warning

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

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

Documentation

Overview

Package service provides the Core Service layer for the unified sync architecture. Core Services are responsible for: - Receiving configuration from Resource Controllers - Validating business rules - Creating/updating CloudflareSyncState CRDs - Handling resource dependencies

Index

Constants

View Source
const (
	// PriorityTunnel is the priority for Tunnel/ClusterTunnel settings (highest)
	PriorityTunnel = 10
	// PriorityBinding is the priority for TunnelBinding rules
	PriorityBinding = 50
	// PriorityDefault is the default priority for other sources
	PriorityDefault = 100
)

Priority constants for different source types

View Source
const (
	// StateReady indicates the resource is synced and ready.
	StateReady = "Ready"
)

Common status state constants used across services.

Variables

This section is empty.

Functions

func SyncStateName

func SyncStateName(resourceType v1alpha2.SyncResourceType, cloudflareID string) string

SyncStateName generates a consistent name for CloudflareSyncState resources. Format: {resource-type}-{cloudflare-id}

Types

type BaseService

type BaseService struct {
	Client client.Client
}

BaseService provides common functionality for all Core Services. It handles CloudflareSyncState CRD operations including: - Creating new SyncState resources - Adding/updating/removing configuration sources - Handling optimistic locking conflicts

func NewBaseService

func NewBaseService(c client.Client) *BaseService

NewBaseService creates a new BaseService

func (*BaseService) GetOrCreateSyncState

func (s *BaseService) GetOrCreateSyncState(
	ctx context.Context,
	resourceType v1alpha2.SyncResourceType,
	cloudflareID, accountID, zoneID string,
	credRef v1alpha2.CredentialsReference,
) (*v1alpha2.CloudflareSyncState, error)

GetOrCreateSyncState retrieves an existing CloudflareSyncState or creates a new one. The SyncState is uniquely identified by resourceType and cloudflareID.

func (*BaseService) GetSyncState

func (s *BaseService) GetSyncState(
	ctx context.Context,
	resourceType v1alpha2.SyncResourceType,
	cloudflareID string,
) (*v1alpha2.CloudflareSyncState, error)

GetSyncState retrieves a CloudflareSyncState by resourceType and cloudflareID. Returns nil if not found (not an error).

func (*BaseService) RemoveSource

func (s *BaseService) RemoveSource(
	ctx context.Context,
	syncState *v1alpha2.CloudflareSyncState,
	source Source,
) error

RemoveSource removes a source from the SyncState. If no sources remain after removal, the SyncState is deleted.

func (*BaseService) UpdateSource

func (s *BaseService) UpdateSource(
	ctx context.Context,
	syncState *v1alpha2.CloudflareSyncState,
	source Source,
	config interface{},
	priority int,
) error

UpdateSource adds or updates a source's configuration in the SyncState. This uses optimistic locking via resourceVersion to handle concurrent updates.

type ConfigService

type ConfigService interface {
	// Register adds or updates configuration from a source.
	// This creates or updates the corresponding CloudflareSyncState CRD.
	Register(ctx context.Context, opts RegisterOptions) error

	// Unregister removes configuration from a source.
	// If no sources remain, the CloudflareSyncState CRD is deleted.
	Unregister(ctx context.Context, opts UnregisterOptions) error
}

ConfigService is the interface that all Core Services must implement. Each service type (Tunnel, DNS, Access, etc.) implements this interface to handle configuration registration and unregistration.

type RegisterOptions

type RegisterOptions struct {
	// ResourceType is the type of Cloudflare resource
	ResourceType v1alpha2.SyncResourceType
	// CloudflareID is the Cloudflare resource identifier
	CloudflareID string
	// AccountID is the Cloudflare account ID
	AccountID string
	// ZoneID is the Cloudflare zone ID (optional)
	ZoneID string
	// Source identifies the contributing K8s resource
	Source Source
	// Config is the configuration to register (will be JSON serialized)
	Config interface{}
	// Priority determines conflict resolution (lower = higher priority)
	Priority int
	// CredentialsRef references the CloudflareCredentials to use
	CredentialsRef v1alpha2.CredentialsReference
}

RegisterOptions contains options for registering configuration to a SyncState

type Source

type Source struct {
	// Kind is the resource kind (e.g., "Tunnel", "Ingress", "TunnelBinding")
	Kind string `json:"kind"`
	// Namespace is the resource namespace (empty for cluster-scoped resources)
	Namespace string `json:"namespace,omitempty"`
	// Name is the resource name
	Name string `json:"name"`
}

Source identifies the Kubernetes resource that contributes configuration. This is used to track ownership and enable proper cleanup when resources are deleted.

func FromReference

func FromReference(ref v1alpha2.SourceReference) Source

FromReference creates a Source from v1alpha2.SourceReference

func (Source) String

func (s Source) String() string

String returns a string representation of the source in the format "Kind/[Namespace/]Name"

func (Source) ToReference

func (s Source) ToReference() v1alpha2.SourceReference

ToReference converts Source to v1alpha2.SourceReference

type UnregisterOptions

type UnregisterOptions struct {
	// ResourceType is the type of Cloudflare resource
	ResourceType v1alpha2.SyncResourceType
	// CloudflareID is the Cloudflare resource identifier
	CloudflareID string
	// Source identifies the K8s resource to unregister
	Source Source
}

UnregisterOptions contains options for unregistering configuration from a SyncState

Directories

Path Synopsis
Package access provides the AccessService for managing Cloudflare Access resource configurations.
Package access provides the AccessService for managing Cloudflare Access resource configurations.
Package device provides services for managing Cloudflare Device configurations.
Package device provides services for managing Cloudflare Device configurations.
Package dns provides the DNSService for managing Cloudflare DNS record configuration.
Package dns provides the DNSService for managing Cloudflare DNS record configuration.
Package domain provides services for managing Cloudflare Domain configurations.
Package domain provides services for managing Cloudflare Domain configurations.
Package gateway provides services for managing Cloudflare Gateway configurations.
Package gateway provides services for managing Cloudflare Gateway configurations.
Package networkroute provides the NetworkRouteService for managing Cloudflare NetworkRoute configuration.
Package networkroute provides the NetworkRouteService for managing Cloudflare NetworkRoute configuration.
Package privateservice provides the PrivateServiceService for managing Cloudflare PrivateService configuration.
Package privateservice provides the PrivateServiceService for managing Cloudflare PrivateService configuration.
Package r2 provides services for managing Cloudflare R2 resource configurations.
Package r2 provides services for managing Cloudflare R2 resource configurations.
Package ruleset provides services for managing Cloudflare Ruleset configurations.
Package ruleset provides services for managing Cloudflare Ruleset configurations.
Package tunnel provides the TunnelConfigService for managing Cloudflare Tunnel configuration.
Package tunnel provides the TunnelConfigService for managing Cloudflare Tunnel configuration.
Package virtualnetwork provides the VirtualNetworkService for managing Cloudflare VirtualNetwork configuration.
Package virtualnetwork provides the VirtualNetworkService for managing Cloudflare VirtualNetwork configuration.

Jump to

Keyboard shortcuts

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