operator

package
v0.0.0-...-06015ec Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TestDBName            = "testdb"
	Namespace             = "cockroach-ns"
	LabelSelector         = "app=cockroachdb"
	OperatorLabelSelector = "app=cockroach-operator"
)
View Source
const (
	DefaultEncryptionSecret        = "cmek-key-secret"
	DefaultRotatedEncryptionSecret = "cmek-key-secret-new"
)

Variables

View Source
var (
	Clusters      = []string{"chart-testing-cluster-0", "chart-testing-cluster-1"}
	CustomDomains = map[int]string{
		0: "cluster1.local",
		1: "cluster2.local",
	}

	ReleaseName            = "cockroachdb"
	CockroachContainerName = "cockroachdb"
)

Functions

func ExecSQL

func ExecSQL(
	t *testing.T, kubectlOpts *k8s.KubectlOptions, pod string, sql string,
) (string, error)

ExecSQL runs a SQL statement in the cockroachdb container using certs-dir authentication.

func HelmChartPaths

func HelmChartPaths() (helmChartPath string, operatorChartPath string)

func InstallCockroachDBOperator

func InstallCockroachDBOperator(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, cloudRegion string,
)

func InstallCockroachDBOperatorChart

func InstallCockroachDBOperatorChart(
	t *testing.T,
	kubectlOptions *k8s.KubectlOptions,
	chart, version string,
	setValues map[string]string,
)

func InstallCockroachDBOperatorScoped

func InstallCockroachDBOperatorScoped(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, watchNamespaces, cloudRegion string,
)

func InstallCockroachDBOperatorScopedForMigration

func InstallCockroachDBOperatorScopedForMigration(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, watchNamespaces, cloudRegion string,
)

func MustMarshalJSON

func MustMarshalJSON(value interface{}) string

func PatchHelmValues

func PatchHelmValues(inputValues map[string]string) map[string]string

PatchHelmValues adds and overrides few default values for the helm charts for testing purposes. It sets the persistent storage size to 1Gi, terminationGracePeriod to 30s and rolling restart delay to 30s.

func TestOperatorHelmValues

func TestOperatorHelmValues() map[string]string

func UninstallCockroachDBOperator

func UninstallCockroachDBOperator(t *testing.T, kubectlOptions *k8s.KubectlOptions)

func UpgradeCockroachDBOperatorChart

func UpgradeCockroachDBOperatorChart(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, chart string, setValues map[string]string,
)

func VerifyInitCommandInOperatorLogs

func VerifyInitCommandInOperatorLogs(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, expected string,
)

VerifyInitCommandInOperatorLogs verifies that the operator logs contain the expected init command.

Types

type AdvancedInstallConfig

type AdvancedInstallConfig struct {
	// WAL Failover configuration
	WALFailoverEnabled bool
	WALFailoverSize    string

	EncryptionEnabled bool

	// Virtual Cluster configuration (for PCR)
	VirtualClusterMode string // "primary", "standby", or ""

	// Custom helm values to merge
	CustomValues map[string]string

	// Custom regions configuration (for encryption)
	CustomRegions []map[string]interface{}

	// Skip operator installation (for second virtual cluster)
	SkipOperatorInstall bool
}

AdvancedInstallConfig holds configuration for advanced feature installations.

type AdvancedValidationConfig

type AdvancedValidationConfig struct {
	WALFailover      WALFailoverValidation
	EncryptionAtRest EncryptionAtRestValidation
	PCR              PCRValidation
}

AdvancedValidationConfig aggregates validation knobs for advanced feature assertions.

func DefaultAdvancedValidationConfig

func DefaultAdvancedValidationConfig() AdvancedValidationConfig

DefaultAdvancedValidationConfig returns default validation values used when a test does not override them.

type EncryptionAtRestValidation

type EncryptionAtRestValidation struct {
	SecretName string
	// OldKeyExpected is the substring expected in the --enterprise-encryption old-key field.
	// Defaults to "old-key=plain" (initial encryption setup). For key rotation use "old-key=/etc/cockroach-key/".
	OldKeyExpected string
}

EncryptionAtRestValidation captures encryption validation expectations.

type PCRValidation

type PCRValidation struct {
	Cluster          string
	PrimaryNamespace string
	StandbyNamespace string
	// PrimaryClusterDomain overrides the cluster domain for the primary connection URI.
	PrimaryClusterDomain string
}

PCRValidation captures virtual cluster replication validation inputs.

type Region

type Region struct {
	// IsCertManager is true if the cockroachdb cluster is using cert-manager.
	IsCertManager bool
	// NodeCount is the desired CockroachDB nodes in the region.
	NodeCount int
	// Namespace stores mapping between cluster name and namespace.
	Namespace    map[string]string
	ReusingInfra bool
	// Clients store the k8s client for each cluster
	// needed for performing k8s operations on k8s objects.
	Clients               map[string]client.Client
	Clusters              []string
	CorednsClusterOptions map[string]coredns.CoreDNSClusterOption
	Provider              string
	RegionCodes           []string

	VirtualClusterModeStandby bool
	IsOperatorInstalled       bool

	// OperatorNamespace tracks the namespace in which the operator was installed,
	// keyed by cluster name.
	OperatorNamespace map[string]string
	// contains filtered or unexported fields
}

func (*Region) AssignRandomNamespace

func (r *Region) AssignRandomNamespace(cluster string) string

AssignRandomNamespace assigns a randomized namespace for the given cluster using the default prefix.

func (*Region) AssignRandomNamespaceWithPrefix

func (r *Region) AssignRandomNamespaceWithPrefix(cluster string, prefix string) string

AssignRandomNamespaceWithPrefix assigns a randomized namespace for the given cluster using the provided prefix.

func (*Region) AssignRandomNamespacesWithPrefix

func (r *Region) AssignRandomNamespacesWithPrefix(prefix string)

AssignRandomNamespacesWithPrefix assigns randomized namespaces for all tracked clusters.

func (*Region) BaseRegionConfig

func (r *Region) BaseRegionConfig(cluster string, index int) map[string]interface{}

BaseRegionConfig returns a baseline region configuration map for the provided cluster and index.

func (*Region) BuildEncryptionRegions

func (r *Region) BuildEncryptionRegions(
	cluster string, index int, encryptionOverrides map[string]interface{},
) []map[string]interface{}

BuildEncryptionRegions creates a slice containing a single region entry with encryption settings applied.

func (*Region) CleanUpCACertificate

func (r *Region) CleanUpCACertificate(t *testing.T)

func (*Region) CleanupEncryptionInfra

func (r *Region) CleanupEncryptionInfra()

func (*Region) CleanupResources

func (r *Region) CleanupResources(t *testing.T)

CleanupResources will clean the resources installed by Operator, CockroachDB charts and deletes the namespace. Any failure in doing so might cause issues in other tests as some of the cluster resources are tied to the namespace.

func (*Region) CreateCACertificate

func (r *Region) CreateCACertificate(t *testing.T) error

CreateCACertificate creates CA cert and key at the same path.

func (*Region) CreateEncryptionKeySecret

func (r *Region) CreateEncryptionKeySecret(
	t *testing.T, kubectlOptions *k8s.KubectlOptions, secretName string, clusterRegion string,
) error

func (*Region) EncryptionAtRestConfig

func (r *Region) EncryptionAtRestConfig(
	secretName string, overrides map[string]interface{},
) map[string]interface{}

EncryptionAtRestConfig returns a reusable encryption configuration map with optional overrides. When an override value is nil or empty string, the key is omitted from the config entirely. This matters because the operator uses *string with omitempty — a nil/absent keySecretName is interpreted as "plain" (unencrypted), while an empty string is not the same as nil.

func (*Region) EncryptionOverridesFromProvider

func (r *Region) EncryptionOverridesFromProvider() map[string]interface{}

func (*Region) EnsureKubeConfigPath

func (r *Region) EnsureKubeConfigPath() (string, error)

EnsureKubeConfigPath ensures that the kubeconfig file exists and returns its path.

func (*Region) ExtendOperatorWatchNamespace

func (r *Region) ExtendOperatorWatchNamespace(
	t *testing.T, cluster, operatorNamespace, newNamespace string,
)

ExtendOperatorWatchNamespace patches the operator deployment in operatorNamespace to also watch newNamespace.

func (*Region) GetCurrentContext

func (r *Region) GetCurrentContext(t *testing.T) (string, api.Config)

GetCurrentContext gets the current cluster context from KubeConfig.

func (*Region) InstallCharts

func (r *Region) InstallCharts(t *testing.T, cluster string, index int)

InstallCharts Installs both Operator and CockroachDB charts by providing custom CA secret which is generated through cockroach binary, It also verifies whether relevant services are up and running.

func (*Region) InstallChartsWithAdvancedConfig

func (r *Region) InstallChartsWithAdvancedConfig(
	t *testing.T, cluster string, index int, config AdvancedInstallConfig,
)

InstallChartsWithAdvancedConfig installs CockroachDB with advanced features configuration

func (*Region) OperatorRegions

func (r *Region) OperatorRegions(index int, nodes int) []map[string]interface{}

OperatorRegions returns the regions config based on the index which is referring to cluster index.

func (*Region) RequireCACertificate

func (r *Region) RequireCACertificate(t *testing.T) func()

RequireCACertificate creates a CA certificate for the current test and returns a cleanup closure. It cleans up any stale CA files from previous runs before creating new ones.

func (*Region) SetEncryptionProvider

func (r *Region) SetEncryptionProvider(p encryption.Provider)

func (*Region) SetupMultiClusterWithCA

func (r *Region) SetupMultiClusterWithCA(t *testing.T) func()

SetupMultiClusterWithCA prepares all clusters for advanced tests and returns a cleanup closure.

func (*Region) SetupSingleClusterWithCA

func (r *Region) SetupSingleClusterWithCA(t *testing.T, cluster string) func()

SetupSingleClusterWithCA prepares a single cluster for advanced tests and returns a cleanup closure.

func (*Region) ValidateCRDB

func (r *Region) ValidateCRDB(t *testing.T, cluster string)

ValidateCRDB validates the CockroachDB cluster by performing basic operations on db.

func (*Region) ValidateCRDBContainerResources

func (r *Region) ValidateCRDBContainerResources(t *testing.T, kubectlOptions *k8s.KubectlOptions)

func (*Region) ValidateEncryptionAtRest

func (r *Region) ValidateEncryptionAtRest(
	t *testing.T, cluster string, cfg *AdvancedValidationConfig,
)

ValidateEncryptionAtRest verifies that encryption at rest is properly configured by checking flags and encryption status. Pass nil config to rely on defaults or provide overrides via AdvancedValidationConfig.EncryptionAtRest.

func (*Region) ValidateMultiRegionSetup

func (r *Region) ValidateMultiRegionSetup(t *testing.T)

ValidateMultiRegionSetup validates the multi-region setup.

func (*Region) ValidatePCR

func (r *Region) ValidatePCR(t *testing.T, cfg *AdvancedValidationConfig)

ValidatePCR validates PCR by verifying virtual cluster configuration and testing failover/failback connections. Provide the cluster and namespaces through AdvancedValidationConfig.PCR.

func (*Region) ValidateWALFailover

func (r *Region) ValidateWALFailover(t *testing.T, cluster string, cfg *AdvancedValidationConfig)

ValidateWALFailover verifies that WAL failover is properly configured by checking the --wal-failover flag and PVC. Pass nil config to rely on defaults or provide a pointer with overrides through AdvancedValidationConfig.WALFailover.

func (*Region) VerifyHelmUpgrade

func (r *Region) VerifyHelmUpgrade(
	t *testing.T, initialTimestamp time.Time, kubectlOptions *k8s.KubectlOptions,
) error

VerifyHelmUpgrade waits till all the pods are restarted after the helm upgrade is completed, it verifies with initialTimestamp which is the timestamp of the pods before recreation and returns the pod name.

type WALFailoverValidation

type WALFailoverValidation struct {
	CustomPath string
}

WALFailoverValidation captures WAL failover expectations.

Directories

Path Synopsis
Package infra provides AWS infrastructure provisioning and management for e2e operator tests.
Package infra provides AWS infrastructure provisioning and management for e2e operator tests.

Jump to

Keyboard shortcuts

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