Documentation ¶
Index ¶
- Constants
- Variables
- func AddContainersToPodTemplateSpec(dcConfig *DatacenterConfig, containers ...corev1.Container)
- func AddCqlUser(cassandraUserSecretRef corev1.LocalObjectReference, dcConfig *DatacenterConfig, ...)
- func AddInitContainersToPodTemplateSpec(dcConfig *DatacenterConfig, initContainers ...corev1.Container)
- func AddK8ssandraVolumesToPodTemplateSpec(dcConfig *DatacenterConfig, extraVolumes api.K8ssandraVolumes)
- func AddNumTokens(template *DatacenterConfig)
- func AddOrUpdateAdditionalVolume(dcConfig *DatacenterConfig, volume *v1beta1.AdditionalVolumes, volumeIndex int, ...)
- func AddOrUpdateVolume(dcConfig *DatacenterConfig, volume *corev1.Volume, volumeIndex int, found bool)
- func AddOrUpdateVolumeMount(container *corev1.Container, volume *corev1.Volume, mountPath string)
- func AddOrUpdateVolumeToSpec(templateSpec *corev1.PodTemplateSpec, volume *corev1.Volume, volumeIndex int, ...)
- func AddPodTemplateSpecMeta(dcConfig *DatacenterConfig, m api.EmbeddedObjectMeta)
- func AddStartRpc(template *DatacenterConfig)
- func AddVolumesToPodTemplateSpec(podTemplateSpec *corev1.PodTemplateSpec, volume corev1.Volume)
- func AllowAlterRfDuringRangeMovement(dcConfig *DatacenterConfig)
- func ApplyAuth(dcConfig *DatacenterConfig, authEnabled bool, useExternalSecrets bool)
- func ApplyAuthSettings(config api.CassandraConfig, authEnabled bool, ...) api.CassandraConfig
- func ApplySystemReplication(dcConfig *DatacenterConfig, replication SystemReplication)
- func ClientEncryptionEnabled(template *DatacenterConfig) bool
- func CompareReplications(actualReplication map[string]string, desiredReplication map[string]int) bool
- func ComputeInitialTokens(dcConfigs []*DatacenterConfig) error
- func ComputeReplication(maxReplicationPerDc int, datacenters ...*cassdcapi.CassandraDatacenter) map[string]int
- func ComputeReplicationFromDatacenters(maxReplicationPerDc int, externalDatacenters []string, ...) map[string]int
- func DatacenterReady(dc *cassdcapi.CassandraDatacenter) bool
- func DatacenterStopped(dc *cassdcapi.CassandraDatacenter) bool
- func DatacenterStopping(dc *cassdcapi.CassandraDatacenter) bool
- func DatacenterUpdatedAfter(t time.Time, dc *cassdcapi.CassandraDatacenter) bool
- func EnableSmartTokenAllocation(template *DatacenterConfig)
- func EncryptionVolumes(storeType encryption.StoreType, encryptionStores encryption.Stores) (*corev1.Volume, *corev1.Volume)
- func FindAdditionalVolume(dcConfig *DatacenterConfig, volumeName string) (int, bool)
- func FindContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName string) (int, bool)
- func FindInitContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName string) (int, bool)
- func FindVolume(dcPodTemplateSpec *corev1.PodTemplateSpec, volumeName string) (int, bool)
- func FindVolumeMount(container *corev1.Container, name string) *corev1.VolumeMount
- func HandleDeprecatedJvmOptions(jvmOptions *api.JvmOptions)
- func HandleEncryptionOptions(template *DatacenterConfig) error
- func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig) (*cassdcapi.CassandraDatacenter, error)
- func ReadEncryptionStorePassword(ctx context.Context, namespace string, remoteClient client.Client, ...) (string, error)
- func ReadEncryptionStoresSecrets(ctx context.Context, klusterKey types.NamespacedName, ...) error
- func ServerEncryptionEnabled(template *DatacenterConfig) bool
- func SetNewDefaultNumTokens(kc *api.K8ssandraCluster, desiredDc, actualDc *cassdcapi.CassandraDatacenter) (*cassdcapi.CassandraDatacenter, error)
- func StoreMountFullPath(storeType encryption.StoreType, storeName encryption.StoreName) string
- func UpdateCassandraContainer(p *corev1.PodTemplateSpec, f func(c *corev1.Container))
- func UpdateContainer(p *corev1.PodTemplateSpec, name string, f func(c *corev1.Container))
- func UpdateInitContainer(p *corev1.PodTemplateSpec, name string, f func(c *corev1.Container))
- func UpdateLoggerContainer(p *corev1.PodTemplateSpec, f func(c *corev1.Container))
- func ValidateConfig(desiredDc, actualDc *cassdcapi.CassandraDatacenter) error
- func ValidateDatacenterConfig(dcConfig *DatacenterConfig) error
- type DCConfigIncomplete
- type DatacenterConfig
- type ManagementApiFacade
- type ManagementApiFactory
- type Replication
- type SystemReplication
Constants ¶
const NetworkTopology = "org.apache.cassandra.locator.NetworkTopologyStrategy"
const (
StoresMountPath = "/mnt"
)
const (
SystemReplicationFactorStrategy = "-Dcassandra.system_distributed_replication"
)
Variables ¶
var ( ErrInitialTokensDCHasUserProvidedConfig = errors.New("cannot compute initial tokens: at least one DC has a user-provided per-node config") ErrInitialTokensInvalidNumTokens = errors.New("cannot compute initial tokens: invalid num_tokens") ErrInitialTokensNumTokensTooHigh = errors.New("cannot compute initial tokens: at least one DC has num_tokens >= 16") ErrInitialTokensInvalidAllocateTokens = errors.New("cannot compute initial tokens: invalid allocate_tokens_for_local_replication_factor") ErrInitialTokensInvalidPartitioner = errors.New("cannot compute initial tokens: invalid or unsupported partitioner") ErrInitialTokensPartitionerMismatch = errors.New("cannot compute initial tokens: partitioner mismatch") )
Functions ¶
func AddContainersToPodTemplateSpec ¶ added in v1.2.0
func AddContainersToPodTemplateSpec(dcConfig *DatacenterConfig, containers ...corev1.Container)
func AddCqlUser ¶
func AddCqlUser(cassandraUserSecretRef corev1.LocalObjectReference, dcConfig *DatacenterConfig, cassandraUserSecretName string)
If auth is enabled in this cluster, we need to allow components to access the cluster through CQL. This is done by declaring a Cassandra user whose credentials are pulled from CassandraUserSecretRef.
func AddInitContainersToPodTemplateSpec ¶ added in v1.2.0
func AddInitContainersToPodTemplateSpec(dcConfig *DatacenterConfig, initContainers ...corev1.Container)
func AddK8ssandraVolumesToPodTemplateSpec ¶ added in v1.4.0
func AddK8ssandraVolumesToPodTemplateSpec(dcConfig *DatacenterConfig, extraVolumes api.K8ssandraVolumes)
func AddNumTokens ¶ added in v1.4.0
func AddNumTokens(template *DatacenterConfig)
AddNumTokens adds the num_tokens option to cassandra.yaml if it is not already present, because otherwise Cassandra defaults to num_tokens: 1, which is not recommended.
func AddOrUpdateAdditionalVolume ¶
func AddOrUpdateAdditionalVolume(dcConfig *DatacenterConfig, volume *v1beta1.AdditionalVolumes, volumeIndex int, found bool)
func AddOrUpdateVolume ¶
func AddOrUpdateVolume(dcConfig *DatacenterConfig, volume *corev1.Volume, volumeIndex int, found bool)
func AddOrUpdateVolumeMount ¶
func AddOrUpdateVolumeToSpec ¶ added in v1.8.0
func AddPodTemplateSpecMeta ¶ added in v1.5.0
func AddPodTemplateSpecMeta(dcConfig *DatacenterConfig, m api.EmbeddedObjectMeta)
func AddStartRpc ¶ added in v1.4.0
func AddStartRpc(template *DatacenterConfig)
AddStartRpc adds the start_rpc option to cassandra.yaml, but only if Cassandra is 3.x.
func AddVolumesToPodTemplateSpec ¶ added in v1.2.0
func AddVolumesToPodTemplateSpec(podTemplateSpec *corev1.PodTemplateSpec, volume corev1.Volume)
func AllowAlterRfDuringRangeMovement ¶
func AllowAlterRfDuringRangeMovement(dcConfig *DatacenterConfig)
func ApplyAuth ¶
func ApplyAuth(dcConfig *DatacenterConfig, authEnabled bool, useExternalSecrets bool)
ApplyAuth modifies the dc config depending on whether auth is enabled in the cluster or not.
func ApplyAuthSettings ¶
func ApplyAuthSettings(config api.CassandraConfig, authEnabled bool, serverType api.ServerDistribution) api.CassandraConfig
ApplyAuthSettings modifies the given config and applies defaults for authenticator, authorizer and role manager, depending on whether auth is enabled or not, and only if these settings are empty in the input config.
func ApplySystemReplication ¶
func ApplySystemReplication(dcConfig *DatacenterConfig, replication SystemReplication)
ApplySystemReplication adds system properties to configure replication of system keyspaces.
func ClientEncryptionEnabled ¶
func ClientEncryptionEnabled(template *DatacenterConfig) bool
func CompareReplications ¶
func ComputeInitialTokens ¶ added in v1.4.0
func ComputeInitialTokens(dcConfigs []*DatacenterConfig) error
ComputeInitialTokens computes initial tokens for each DC, assign those tokens to the first RF pods in the DC, and stores the result in the DC config for later retrieval.
If any DC has num_tokens >= 16, or if the partitioner is not Murmur3 nor Random, or if there is something invalid in the cassandra.yaml configuration, then this function skips computing initial tokens, does not modify the DC configs, and returns an error.
func ComputeReplication ¶
func ComputeReplication(maxReplicationPerDc int, datacenters ...*cassdcapi.CassandraDatacenter) map[string]int
ComputeReplication computes the desired replication for each dc, taking into account the desired maximum replication per dc.
func ComputeReplicationFromDatacenters ¶ added in v1.0.0
func ComputeReplicationFromDatacenters(maxReplicationPerDc int, externalDatacenters []string, datacenters ...api.CassandraDatacenterTemplate) map[string]int
ComputeReplicationFromDatacenters is similar to ComputeReplication but takes dc templates as parameters along with potential external datacenters (unmanaged by the operator).
func DatacenterReady ¶
func DatacenterReady(dc *cassdcapi.CassandraDatacenter) bool
func DatacenterStopped ¶
func DatacenterStopped(dc *cassdcapi.CassandraDatacenter) bool
func DatacenterStopping ¶
func DatacenterStopping(dc *cassdcapi.CassandraDatacenter) bool
func DatacenterUpdatedAfter ¶
func DatacenterUpdatedAfter(t time.Time, dc *cassdcapi.CassandraDatacenter) bool
func EnableSmartTokenAllocation ¶ added in v1.5.0
func EnableSmartTokenAllocation(template *DatacenterConfig)
EnableSmartTokenAllocation adds the allocate_tokens_for_local_replication_factor option to cassandra.yaml if it is not already present when running DSE. This option is enabled by default in Cassandra but not DSE.
func EncryptionVolumes ¶
func EncryptionVolumes(storeType encryption.StoreType, encryptionStores encryption.Stores) (*corev1.Volume, *corev1.Volume)
func FindAdditionalVolume ¶
func FindAdditionalVolume(dcConfig *DatacenterConfig, volumeName string) (int, bool)
func FindContainer ¶
func FindContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName string) (int, bool)
func FindInitContainer ¶
func FindInitContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName string) (int, bool)
func FindVolume ¶
func FindVolume(dcPodTemplateSpec *corev1.PodTemplateSpec, volumeName string) (int, bool)
func FindVolumeMount ¶ added in v1.2.0
func FindVolumeMount(container *corev1.Container, name string) *corev1.VolumeMount
func HandleDeprecatedJvmOptions ¶ added in v1.4.0
func HandleDeprecatedJvmOptions(jvmOptions *api.JvmOptions)
HandleDeprecatedJvmOptions handles the deprecated settings: HeapSize and HeapNewGenSize by copying their values, if any, to the appropriate destination settings, iif these are nil.
func HandleEncryptionOptions ¶ added in v1.4.0
func HandleEncryptionOptions(template *DatacenterConfig) error
HandleEncryptionOptions sets up encryption in the datacenter config template. The keystore and truststore config maps are mounted into the datacenter pod and the secrets are read to be set in the datacenter config template.
func NewDatacenter ¶
func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig) (*cassdcapi.CassandraDatacenter, error)
func ReadEncryptionStoresSecrets ¶
func ReadEncryptionStoresSecrets(ctx context.Context, klusterKey types.NamespacedName, template *DatacenterConfig, remoteClient client.Client, logger logr.Logger) error
func ServerEncryptionEnabled ¶
func ServerEncryptionEnabled(template *DatacenterConfig) bool
func SetNewDefaultNumTokens ¶ added in v1.11.0
func SetNewDefaultNumTokens(kc *api.K8ssandraCluster, desiredDc, actualDc *cassdcapi.CassandraDatacenter) (*cassdcapi.CassandraDatacenter, error)
func StoreMountFullPath ¶
func StoreMountFullPath(storeType encryption.StoreType, storeName encryption.StoreName) string
func UpdateCassandraContainer ¶
func UpdateCassandraContainer(p *corev1.PodTemplateSpec, f func(c *corev1.Container))
UpdateCassandraContainer finds the cassandra container, passes it to f, and then adds it back to the PodTemplateSpec. The Container object is created if necessary before calling f. Only the Name field is initialized.
func UpdateContainer ¶
func UpdateContainer(p *corev1.PodTemplateSpec, name string, f func(c *corev1.Container))
UpdateContainer finds the container with the given name, passes it to f, and then adds it back to the PodTemplateSpec. The Container object is created if necessary before calling f. Only the Name field is initialized.
func UpdateInitContainer ¶
func UpdateInitContainer(p *corev1.PodTemplateSpec, name string, f func(c *corev1.Container))
UpdateInitContainer finds the init container with the given name, passes it to f, and then adds it back to the PodTemplateSpec. The Container object is created if necessary before calling f. Only the Name field is initialized.
func UpdateLoggerContainer ¶ added in v1.6.0
func UpdateLoggerContainer(p *corev1.PodTemplateSpec, f func(c *corev1.Container))
UpdateLoggerContainer updates the PodTemplateSpec part for server-system-logger
func ValidateConfig ¶
func ValidateConfig(desiredDc, actualDc *cassdcapi.CassandraDatacenter) error
func ValidateDatacenterConfig ¶ added in v1.4.0
func ValidateDatacenterConfig(dcConfig *DatacenterConfig) error
ValidateDatacenterConfig checks the coalesced DC config for missing fields and mandatory options, and then validates the cassandra.yaml file.
Types ¶
type DCConfigIncomplete ¶
type DCConfigIncomplete struct {
// contains filtered or unexported fields
}
func (DCConfigIncomplete) Error ¶
func (detail DCConfigIncomplete) Error() string
type DatacenterConfig ¶
type DatacenterConfig struct { Meta api.EmbeddedObjectMeta K8sContext string Cluster string SuperuserSecretRef corev1.LocalObjectReference ServerImage string ServerVersion *semver.Version ServerType api.ServerDistribution JmxInitContainerImage *images.Image Size int32 Stopped bool Resources *corev1.ResourceRequirements SystemLoggerResources *corev1.ResourceRequirements StorageConfig *cassdcapi.StorageConfig Racks []cassdcapi.Rack CassandraConfig api.CassandraConfig AdditionalSeeds []string Networking *cassdcapi.NetworkingConfig Users []cassdcapi.CassandraUser PodTemplateSpec corev1.PodTemplateSpec MgmtAPIHeap *resource.Quantity SoftPodAntiAffinity *bool Tolerations []corev1.Toleration ServerEncryptionStores *encryption.Stores ClientEncryptionStores *encryption.Stores ClientKeystorePassword string ClientTruststorePassword string ServerKeystorePassword string ServerTruststorePassword string CDC *cassdcapi.CDCConfiguration DseWorkloads *cassdcapi.DseWorkloads ManagementApiAuth *cassdcapi.ManagementApiAuthConfig PerNodeConfigMapRef corev1.LocalObjectReference PerNodeInitContainerImage string ServiceAccount string ExternalSecrets bool McacEnabled bool DatacenterName string ReadOnlyRootFilesystem *bool // InitialTokensByPodName is a list of initial tokens for the RF first pods in the cluster. It // is only populated when num_tokens < 16 in the whole cluster. Used for generating default // per-node configurations; not transferred directly to the CassandraDatacenter CRD but its // presence affects the PodTemplateSpec. InitialTokensByPodName map[string][]string }
DatacenterConfig provides the configuration to be applied to the CassandraDatacenter. A DatacenterConfig is essentially a coalescence of an api.CassandraClusterTemplate and an api.CassandraDatacenterTemplate. There are global, cluster-wide settings that need to be specified at the DC-level. Using a DatacenterConfig allows to keep the api types clean such that cluster-level settings won't leak into the dc-level settings.
func Coalesce ¶
func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate, dcTemplate *api.CassandraDatacenterTemplate) *DatacenterConfig
Coalesce merges the cluster and dc templates. If a property is defined in both templates, the dc-level property takes precedence.
func (*DatacenterConfig) CassDcName ¶ added in v1.6.0
func (in *DatacenterConfig) CassDcName() string
CassDcName returns the Cassandra datacenter name override if it exists, otherwise the cassdc object name.
func (*DatacenterConfig) SanitizedName ¶ added in v1.8.0
func (in *DatacenterConfig) SanitizedName() string
type ManagementApiFacade ¶
type ManagementApiFacade interface { // CreateKeyspaceIfNotExists calls the management API "POST /ops/keyspace/create" endpoint to create a new keyspace // if it does not exist yet. Calling this method on an existing keyspace is a no-op. CreateKeyspaceIfNotExists( keyspaceName string, replication map[string]int, ) error ListKeyspaces( keyspaceName string, ) ([]string, error) AlterKeyspace( keyspaceName string, replicationSettings map[string]int) error // GetKeyspaceReplication calls the management API "GET /ops/keyspace/replication" endpoint to retrieve the given // keyspace replication settings. GetKeyspaceReplication(keyspaceName string) (map[string]string, error) // ListTables calls the management API "GET /ops/tables" endpoint to retrieve the table names in the given keyspace. ListTables(keyspaceName string) ([]string, error) // CreateTable calls the management API "POST /ops/tables/create" endpoint to create a new table in the given // keyspace. CreateTable(definition *httphelper.TableDefinition) error // EnsureKeyspaceReplication checks if the given keyspace has the given replication, and if it does not, // alters it to match the desired replication. EnsureKeyspaceReplication(keyspaceName string, replication map[string]int) error // GetSchemaVersions list all of the schema versions know to this node. The map keys are schema version UUIDs. // The values are list of node IPs. GetSchemaVersions() (map[string][]string, error) }
ManagementApiFacade is a component mirroring methods available on httphelper.NodeMgmtClient.
type ManagementApiFactory ¶
type ManagementApiFactory interface { // NewManagementApiFacade returns a new ManagementApiFacade that will connect to the Management API of nodes in // the given datacenter. The k8sClient is used to fetch pods in that datacenter. NewManagementApiFacade( ctx context.Context, dc *cassdcapi.CassandraDatacenter, k8sClient client.Client, logger logr.Logger, ) (ManagementApiFacade, error) }
ManagementApiFactory creates request-scoped instances of ManagementApiFacade. This component exists mostly to allow tests to provide mocks for the Management API client.
func NewManagementApiFactory ¶
func NewManagementApiFactory() ManagementApiFactory
type Replication ¶
type Replication struct {
// contains filtered or unexported fields
}
// Replication provides a mapping of DCs to a mapping of keyspaces and their replica counts. NetworkTopologyStrategy is assumed for all keyspaces.
func ParseReplication ¶
func ParseReplication(val []byte) (*Replication, error)
func (*Replication) EachDcContainsKeyspaces ¶
func (r *Replication) EachDcContainsKeyspaces(keyspaces ...string) bool
EachDcContainsKeyspaces if every DC contains all the keyspaces.
func (*Replication) ForDcs ¶
func (r *Replication) ForDcs(dcs ...string) *Replication
ForDcs returns a new Replication that contains only the specifics dcs.
func (*Replication) ReplicationFactor ¶
func (r *Replication) ReplicationFactor(dc, ks string) int
type SystemReplication ¶
SystemReplication represents the replication factor of the system_auth, system_traces, and system_distributed keyspaces. This is applied to each datacenter. The replication is configured per DC.