feature

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package feature provides types and functions to enable and disable features of the Postgres Operator.

To add a new feature, export its name as a constant string and configure it in NewGate. Choose a name that is clear to end users, as they will use it to enable or disable the feature.

Stages

Each feature must be configured with a maturity called a stage. We follow the Kubernetes convention that features in the "Alpha" stage are disabled by default, while those in the "Beta" stage are enabled by default.

NOTE: Since Kubernetes 1.24, APIs (not features) in the "Beta" stage are disabled by default:

Using Features

We initialize and configure one MutableGate in main() and add it to the Context passed to Reconcilers and other Runnables. Those can then interrogate it using Enabled:

if !feature.Enabled(ctx, feature.Excellent) { return }

Tests should create and configure their own MutableGate and inject it using NewContext. For example, the following enables one feature and disables another:

gate := feature.NewGate()
assert.NilError(t, gate.SetFromMap(map[string]bool{
	feature.Excellent: true,
	feature.Uncommon: false,
}))
ctx := feature.NewContext(context.Background(), gate)

Index

Constants

View Source
const (
	// Support appending custom queries to default PGMonitor queries
	AppendCustomQueries = "AppendCustomQueries"

	// Enables automatic creation of user schema
	AutoCreateUserSchema = "AutoCreateUserSchema"

	// Support automatically growing volumes
	AutoGrowVolumes = "AutoGrowVolumes"

	BridgeIdentifiers = "BridgeIdentifiers"

	// Support custom sidecars for PostgreSQL instance Pods
	InstanceSidecars = "InstanceSidecars"

	// Support custom sidecars for pgBouncer Pods
	PGBouncerSidecars = "PGBouncerSidecars"

	// K8SPG-832: Support custom sidecars for pgbackrest repo-host Pods
	PGBackrestRepoHostSidecars = "PGBackrestSidecars"

	// Adjust PGUpgrade parallelism according to CPU resources
	PGUpgradeCPUConcurrency = "PGUpgradeCPUConcurrency"

	// Support tablespace volumes
	TablespaceVolumes = "TablespaceVolumes"

	// Support VolumeSnapshots
	VolumeSnapshots = "VolumeSnapshots"
)

Variables

This section is empty.

Functions

func Enabled

func Enabled(ctx context.Context, f Feature) bool

Enabled indicates if a Feature is enabled in the Gate contained in ctx. It returns false when there is no Gate.

func NewContext

func NewContext(ctx context.Context, gate Gate) context.Context

NewContext returns a copy of ctx containing gate. Check it using Enabled.

func ShowAssigned

func ShowAssigned(ctx context.Context) string

ShowAssigned returns the features enabled or disabled by Set and SetFromMap in the Gate contained in ctx.

func ShowEnabled

func ShowEnabled(ctx context.Context) string

ShowEnabled returns all the features enabled in the Gate contained in ctx.

Types

type Feature

type Feature = featuregate.Feature

type Gate

type Gate interface {
	Enabled(Feature) bool
}

Gate indicates what features exist and which are enabled.

type MutableGate

type MutableGate interface {
	Gate
	// Set enables or disables features by parsing a string like "feature1=true,feature2=false".
	Set(string) error
	// SetFromMap enables or disables features by boolean values.
	SetFromMap(map[string]bool) error
}

MutableGate contains features that can be enabled or disabled.

func NewGate

func NewGate() MutableGate

NewGate returns a MutableGate with the Features defined in this package.

Jump to

Keyboard shortcuts

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