package
2.4.1+incompatible
Repository: https://github.com/percona/percona-postgresql-operator.git
Documentation: pkg.go.dev

# README

Feature Gates

Feature gates allow users to enable or disable certain features by setting the "PGO_FEATURE_GATES" environment variable to a list similar to "feature1=true,feature2=false,..." in the PGO Deployment.

This capability leverages the relevant Kubernetes packages. Documentation and code implementation examples are given below.

Developing with Feature Gates in PGO

To add a new feature gate, a few steps are required. First, in internal/util/features.go, you will add a feature gate key name. As an example, for a new feature called 'FeatureName', you would add a new constant and comment describing what the feature gate controls at the top of the file, similar to

// Enables FeatureName in PGO
FeatureName featuregate.Feature = "FeatureName"

Next, add a new entry to the pgoFeatures map

var pgoFeatures = map[featuregate.Feature]featuregate.FeatureSpec{
    FeatureName: {Default: false, PreRelease: featuregate.Alpha},
}

where FeatureName is the constant defined previously, Default: false sets the default behavior and PreRelease: featuregate.Alpha. The possible PreRelease values are Alpha, Beta, GA and Deprecated.

By Kubernetes convention, Alpha features have almost always been disabled by default. Beta features are generally enabled by default.

Prior to Kubernetes 1.24, both Beta features and APIs were enabled by default. Starting in v1.24, new Beta APIs are generally disabled by default, while Beta features remain enabled by default.

For consistency with Kubernetes, we recommend that feature-gated features be configured as Alpha and disabled by default. Any Beta features added should stay consistent with Kubernetes practice and be enabled by default, but we should keep an eye out for changes to these standards and adjust as needed.

Once the above items are set, you can then use your feature gated value in the code base to control feature behavior using something like

if util.DefaultMutableFeatureGate.Enabled(util.FeatureName)

To test the feature gate, set the PGO_FEATURE_GATES environment variable to enable the new feature as follows

PGO_FEATURE_GATES="FeatureName=true"

Note that for more than one feature, this variable accepts a comma delimited list, e.g.

PGO_FEATURE_GATES="FeatureName=true,FeatureName2=true,FeatureName3=true"

While PGO_FEATURE_GATES does not have to be set, please note that the features must be defined before use, otherwise PGO deployment will fail with the following message panic: unable to parse and store configured feature gates. unrecognized feature gate

Also, the features must have boolean values, otherwise you will see panic: unable to parse and store configured feature gates. invalid value

When dealing with tests that do not invoke cmd/postgres-operator/main.go, keep in mind that you will need to ensure that you invoke the AddAndSetFeatureGates function. Otherwise, any test that references the undefined feature gate will fail with a panic message similar to "feature "FeatureName" is not registered in FeatureGate"

To correct for this, you simply need a line similar to

err := util.AddAndSetFeatureGates("")

# Functions

AddAndSetFeatureGates utilizes the Kubernetes feature gate packages to first add the default PGO features to the featureGate and then set the values provided via the 'PGO_FEATURE_GATES' environment variable.
GenerateAlphaNumericPassword returns a random alphanumeric string.
GenerateASCIIPassword returns a random string of printable ASCII characters.
GetRegistration returns an empty struct if registration is not required.
SemanticMajorMinorPatch function takes a version string and returns a semantically formatted version string with just major, minor, and patch.
SQLQuoteIdentifier quotes an "identifier" (e.g.
SQLQuoteLiteral quotes a 'literal' (e.g.

# Constants

Every feature gate should add a key here following this template: // Enables FeatureName..
.
Enables Kubernetes-native way to manage Crunchy Bridge managed Postgresclusters.
DefaultGeneratedPasswordLength is the default length of what a generated password should be if it's not set elsewhere.
Enables support of custom sidecars for PostgreSQL instance Pods.
Enables support of custom sidecars for pgBouncer Pods.
Enables support of tablespace volumes.

# Variables

DefaultMutableFeatureGate is a mutable, shared global FeatureGate.

# Structs

Registration is required only for OLM installations of the operator.