pagesproject

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package pagesproject implements the Controller for PagesProject CRD. It directly manages Cloudflare Pages projects.

Index

Constants

View Source
const (
	// DefaultHealthCheckTimeout is the default timeout for health checks.
	DefaultHealthCheckTimeout = 30 * time.Second
	// HealthCheckSuccessCode is the HTTP status code considered as healthy.
	HealthCheckSuccessCode = http.StatusOK
)
View Source
const (
	// FinalizerName is the finalizer for PagesProject resources.
	FinalizerName = "pagesproject.networking.cloudflare-operator.io/finalizer"

	// ManagedByLabel identifies resources managed by PagesProject controller.
	ManagedByLabel = "networking.cloudflare-operator.io/managed-by"

	// ManagedByNameLabel stores the PagesProject name that manages this deployment.
	ManagedByNameLabel = "networking.cloudflare-operator.io/managed-by-name"

	// ManagedByUIDLabel stores the PagesProject UID to prevent conflicts after deletion.
	ManagedByUIDLabel = "networking.cloudflare-operator.io/managed-by-uid"

	// VersionLabel stores the version name from ProjectVersion.
	VersionLabel = "networking.cloudflare-operator.io/version"

	// ManagedAnnotation marks a resource as managed by PagesProject.
	ManagedAnnotation = "networking.cloudflare-operator.io/managed"

	// ManagedByValue is the value for ManagedByLabel.
	ManagedByValue = "pagesproject"
)
View Source
const DefaultExternalSyncInterval = 5 * time.Minute

DefaultExternalSyncInterval is the default interval for external version sync.

Variables

View Source
var ErrDeploymentPendingDeletion = errors.New("deployment pending deletion, will retry")

ErrDeploymentPendingDeletion is returned when a deployment is being deleted and we need to wait for it to complete before creating a new one.

Functions

func DemoteDeploymentToPreview

func DemoteDeploymentToPreview(
	ctx context.Context,
	k8sClient client.Client,
	deployment *networkingv1alpha2.PagesDeployment,
) error

DemoteDeploymentToPreview demotes a deployment from production to preview. Used when another deployment is promoted to production.

func GetDeploymentVersionName

func GetDeploymentVersionName(deployment *networkingv1alpha2.PagesDeployment) string

GetDeploymentVersionName extracts the version name from a deployment. Checks spec.versionName, status.versionName, and version label in order.

func HasCloudflareDeploymentID

func HasCloudflareDeploymentID(deployment *networkingv1alpha2.PagesDeployment) bool

HasCloudflareDeploymentID checks if a deployment has a Cloudflare deployment ID.

func IsDeploymentProduction

func IsDeploymentProduction(deployment *networkingv1alpha2.PagesDeployment) bool

IsDeploymentProduction checks if a deployment is in production environment.

func IsDeploymentSucceeded

func IsDeploymentSucceeded(deployment *networkingv1alpha2.PagesDeployment) bool

IsDeploymentSucceeded checks if a deployment has succeeded.

func PromoteDeploymentToProduction

func PromoteDeploymentToProduction(
	ctx context.Context,
	k8sClient client.Client,
	deployment *networkingv1alpha2.PagesDeployment,
) error

PromoteDeploymentToProduction promotes a deployment to production by updating its environment. This approach works for all deployments, not just those that were previously production. The PagesDeployment controller will detect the environment change and create a new deployment.

Why use environment change instead of Cloudflare Rollback API: - Rollback API only works for deployments that were PREVIOUSLY production - If a version was never deployed as production, Rollback API will fail - Environment change works for all deployments and is more reliable

func ValidateDeploymentForPromotion

func ValidateDeploymentForPromotion(deployment *networkingv1alpha2.PagesDeployment) error

ValidateDeploymentForPromotion validates that a deployment can be promoted to production. Returns an error if the deployment is not ready for promotion.

Types

type AutoPromoteReconciler

type AutoPromoteReconciler struct {
	client.Client
	Scheme     *runtime.Scheme
	Recorder   record.EventRecorder
	Log        logr.Logger
	HTTPClient *http.Client
}

AutoPromoteReconciler handles the autoPromote version management policy. It automatically promotes preview deployments to production after they succeed, with optional delay and health check.

func NewAutoPromoteReconciler

func NewAutoPromoteReconciler(
	k8sClient client.Client,
	scheme *runtime.Scheme,
	recorder record.EventRecorder,
	log logr.Logger,
) *AutoPromoteReconciler

NewAutoPromoteReconciler creates a new AutoPromoteReconciler.

func (*AutoPromoteReconciler) GetRequeueAfter

func (*AutoPromoteReconciler) GetRequeueAfter() time.Duration

GetRequeueAfter returns the recommended requeue duration for autoPromote mode.

func (*AutoPromoteReconciler) Reconcile

func (r *AutoPromoteReconciler) Reconcile(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) (requeueAfter time.Duration, err error)

Reconcile handles the autoPromote version management workflow.

type ExternalReconciler

type ExternalReconciler struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder record.EventRecorder
	Log      logr.Logger
}

ExternalReconciler handles the external version management policy. It allows external systems to control versioning by updating the External config fields.

func NewExternalReconciler

func NewExternalReconciler(
	k8sClient client.Client,
	scheme *runtime.Scheme,
	recorder record.EventRecorder,
	log logr.Logger,
) *ExternalReconciler

NewExternalReconciler creates a new ExternalReconciler.

func (*ExternalReconciler) GetSyncInterval

GetSyncInterval returns the configured or default sync interval.

func (*ExternalReconciler) Reconcile

func (r *ExternalReconciler) Reconcile(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) (requeueAfter time.Duration, err error)

Reconcile handles the external version management workflow. External systems update spec.versionManagement.external.currentVersion and productionVersion. This reconciler ensures the corresponding deployments exist and production is promoted.

type GitOpsReconciler

type GitOpsReconciler struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder record.EventRecorder
	Log      logr.Logger
}

GitOpsReconciler handles the gitops version management policy. It manages preview and production deployments based on version names.

func NewGitOpsReconciler

func NewGitOpsReconciler(k8sClient client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, log logr.Logger) *GitOpsReconciler

NewGitOpsReconciler creates a new GitOpsReconciler.

func (*GitOpsReconciler) Reconcile

func (r *GitOpsReconciler) Reconcile(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) error

Reconcile handles the GitOps version management workflow.

func (*GitOpsReconciler) UpdatePreviewDeploymentStatus

func (r *GitOpsReconciler) UpdatePreviewDeploymentStatus(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	deployment *networkingv1alpha2.PagesDeployment,
) error

UpdatePreviewDeploymentStatus updates the preview deployment info in project status.

func (*GitOpsReconciler) UpdateVersionMapping

func (r *GitOpsReconciler) UpdateVersionMapping(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
) error

UpdateVersionMapping updates the version mapping in project status.

type LatestPreviewReconciler

type LatestPreviewReconciler struct {
	client.Client
	Scheme   *runtime.Scheme
	Recorder record.EventRecorder
	Log      logr.Logger
}

LatestPreviewReconciler handles the latestPreview version management policy. It automatically tracks the latest successful preview deployment and optionally auto-promotes.

func NewLatestPreviewReconciler

func NewLatestPreviewReconciler(
	k8sClient client.Client,
	scheme *runtime.Scheme,
	recorder record.EventRecorder,
	log logr.Logger,
) *LatestPreviewReconciler

NewLatestPreviewReconciler creates a new LatestPreviewReconciler.

func (*LatestPreviewReconciler) GetRequeueAfter

func (*LatestPreviewReconciler) GetRequeueAfter() time.Duration

GetRequeueAfter returns the recommended requeue duration for latestPreview mode.

func (*LatestPreviewReconciler) Reconcile

func (r *LatestPreviewReconciler) Reconcile(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) error

Reconcile handles the latestPreview version management workflow.

type PagesProjectReconciler

type PagesProjectReconciler struct {
	client.Client
	Scheme     *runtime.Scheme
	Recorder   record.EventRecorder
	APIFactory *common.APIClientFactory
	// contains filtered or unexported fields
}

PagesProjectReconciler reconciles a PagesProject object. It directly calls Cloudflare API and writes status back to the CRD.

func (*PagesProjectReconciler) Reconcile

func (r *PagesProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

func (*PagesProjectReconciler) SetupWithManager

func (r *PagesProjectReconciler) SetupWithManager(mgr ctrl.Manager) error

type ResolvedVersions

type ResolvedVersions struct {
	Versions         []networkingv1alpha2.ProjectVersion
	ProductionTarget string
	// PreviewVersion is the version to deploy as preview (GitOps mode)
	PreviewVersion string
	// ProductionVersion is the version to deploy as production (GitOps mode)
	ProductionVersion string
	// Policy is the active version management policy
	Policy networkingv1alpha2.VersionPolicy
}

ResolvedVersions contains the resolved versions and production target.

type TemplateData

type TemplateData struct {
	Version string
}

TemplateData contains data for template execution.

type VersionIndex

type VersionIndex struct {
	client.Client
}

VersionIndex maintains a mapping of versionName -> deploymentId. This allows efficient lookup of deployments by version name.

func NewVersionIndex

func NewVersionIndex(k8sClient client.Client) *VersionIndex

NewVersionIndex creates a new VersionIndex.

func (*VersionIndex) BuildIndex

func (idx *VersionIndex) BuildIndex(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
) (map[string]string, error)

BuildIndex builds a version index for the given project. Returns a map of versionName -> deploymentId.

func (*VersionIndex) FindDeploymentByID

func (idx *VersionIndex) FindDeploymentByID(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	deploymentID string,
) (*networkingv1alpha2.PagesDeployment, error)

FindDeploymentByID finds a PagesDeployment by Cloudflare deployment ID.

func (*VersionIndex) FindDeploymentByVersion

func (idx *VersionIndex) FindDeploymentByVersion(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	versionName string,
) (*networkingv1alpha2.PagesDeployment, error)

FindDeploymentByVersion finds a PagesDeployment by version name.

func (*VersionIndex) GetDeploymentID

func (idx *VersionIndex) GetDeploymentID(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	versionName string,
) (string, error)

GetDeploymentID returns the deployment ID for a version name.

func (*VersionIndex) ListVersions

func (idx *VersionIndex) ListVersions(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
) ([]string, error)

ListVersions returns a list of all version names for a project.

func (*VersionIndex) ListVersionsWithInfo

func (idx *VersionIndex) ListVersionsWithInfo(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
) ([]VersionInfo, error)

ListVersionsWithInfo returns detailed information about all versions.

type VersionInfo

type VersionInfo struct {
	// Name is the version name
	Name string
	// DeploymentID is the Cloudflare deployment ID
	DeploymentID string
	// DeploymentName is the K8s PagesDeployment name
	DeploymentName string
	// State is the deployment state
	State networkingv1alpha2.PagesDeploymentState
	// Environment is the deployment environment
	Environment string
	// IsProduction indicates if this is the current production deployment
	IsProduction bool
}

VersionInfo contains information about a version.

type VersionManager

type VersionManager struct {
	client.Client
	Scheme *runtime.Scheme
	// contains filtered or unexported fields
}

VersionManager manages declarative versions for PagesProject.

func NewVersionManager

func NewVersionManager(k8sClient client.Client, scheme *runtime.Scheme, log logr.Logger) *VersionManager

NewVersionManager creates a new VersionManager.

func (*VersionManager) GetPolicy

GetPolicy returns the effective version management policy.

func (*VersionManager) HasVersions

func (*VersionManager) HasVersions(project *networkingv1alpha2.PagesProject) bool

HasVersions checks if the project has any versions configured.

func (*VersionManager) IsGitOpsMode

func (*VersionManager) IsGitOpsMode(project *networkingv1alpha2.PagesProject) bool

IsGitOpsMode checks if the project is using GitOps version management.

func (*VersionManager) Reconcile

func (vm *VersionManager) Reconcile(ctx context.Context, project *networkingv1alpha2.PagesProject) error

Reconcile synchronizes the desired versions with actual PagesDeployment resources.

func (*VersionManager) ResolveVersions

func (vm *VersionManager) ResolveVersions(project *networkingv1alpha2.PagesProject) (*ResolvedVersions, error)

ResolveVersions resolves versions based on the version management configuration. Supports 8 modes: none, targetVersion, declarativeVersions, fullVersions, gitops, latestPreview, autoPromote, external.

type WebAnalyticsReconciler

type WebAnalyticsReconciler struct {
	client.Client
	Recorder record.EventRecorder
	Log      logr.Logger
}

WebAnalyticsReconciler handles Web Analytics (RUM) configuration for PagesProject.

func NewWebAnalyticsReconciler

func NewWebAnalyticsReconciler(k8sClient client.Client, recorder record.EventRecorder, log logr.Logger) *WebAnalyticsReconciler

NewWebAnalyticsReconciler creates a new WebAnalyticsReconciler.

func (*WebAnalyticsReconciler) Cleanup

func (r *WebAnalyticsReconciler) Cleanup(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) error

Cleanup removes Web Analytics when the project is being deleted.

func (*WebAnalyticsReconciler) Reconcile

func (r *WebAnalyticsReconciler) Reconcile(
	ctx context.Context,
	project *networkingv1alpha2.PagesProject,
	apiClient *cf.API,
) error

Reconcile ensures Web Analytics is configured for all hostnames according to spec. It should be called after the project is successfully synced and subdomain is available.

Jump to

Keyboard shortcuts

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