cassandra

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SystemReplicationDcNames = "-Dcassandra.system_distributed_replication_dc_names"
	SystemReplicationFactor  = "-Dcassandra.system_distributed_replication_per_dc"
)
View Source
const JmxInitContainer = "jmx-credentials"
View Source
const NetworkTopology = "org.apache.cassandra.locator.NetworkTopologyStrategy"
View Source
const (
	StoresMountPath = "/mnt"
)

Variables

View Source
var DefaultJmxInitImage = images.Image{
	Registry:   images.DefaultRegistry,
	Repository: images.DockerOfficialRepository,
	Name:       "busybox",
	Tag:        "1.34.1",
}

Functions

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 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 AddOrUpdateVolumeMount(container *corev1.Container, volume *corev1.Volume, mountPath string)

func AllowAlterRfDuringRangeMovement

func AllowAlterRfDuringRangeMovement(dcConfig *DatacenterConfig)

func ApplyAuth

func ApplyAuth(dcConfig *DatacenterConfig, authEnabled 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) 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. It also sets the com.sun.management.jmxremote.authenticate JVM option to the appropriate value.

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 CompareReplications(actualReplication map[string]string, desiredReplication map[string]int) bool

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 ComputeReplicationFromDcTemplates

func ComputeReplicationFromDcTemplates(maxReplicationPerDc int, datacenters ...api.CassandraDatacenterTemplate) map[string]int

ComputeReplicationFromDcTemplates is similar to ComputeReplication but takes dc templates as parameters.

func CreateJsonConfig

func CreateJsonConfig(template *DatacenterConfig) ([]byte, error)

CreateJsonConfig parses dcConfig into a raw JSON base64-encoded string. If config is nil then nil, nil is returned

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 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 GetDatacentersForSystemReplication

func GetDatacentersForSystemReplication(kc *api.K8ssandraCluster) []api.CassandraDatacenterTemplate

GetDatacentersForSystemReplication determines the DCs that should be included for replication. This function should only be used for system keyspaces. Replication for system keyspaces is initially set through the management-api, not CQL. This allows us to specify non-existent DCs for replication even though Cassandra 4 does not allow that. That cannot be done when configuration replication through CQL which is why this func should only be used for system keyspaces.

func IsCassandra3

func IsCassandra3(version string) bool

func NewDatacenter

func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig) (*cassdcapi.CassandraDatacenter, error)

func ReadEncryptionStorePassword

func ReadEncryptionStorePassword(ctx context.Context, namespace string, remoteClient client.Client, secretName string, storeName encryption.StoreName) (string, 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 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 ValidateConfig

func ValidateConfig(desiredDc, actualDc *cassdcapi.CassandraDatacenter) error

Types

type CassYamlIR

type CassYamlIR struct {
	api.CassandraYaml           `json:",inline,omitempty"`
	StartRpc                    *bool                        `json:"start_rpc,omitempty"`
	ServerEncryptionOptionsYaml *ServerEncryptionOptionsYaml `json:"server_encryption_options,omitempty"`
	ClientEncryptionOptionsYaml *ClientEncryptionOptionsYaml `json:"client_encryption_options,omitempty"`
}

CassYamlIR is an internal representation of the cassandra.yaml. It is required because we want to make some options (esp. start_rpc) invisible to the user, but some of those options still need to be rendered out into the final cassandra.yaml.

type ClientEncryptionOptionsYaml

type ClientEncryptionOptionsYaml struct {
	encryption.ClientEncryptionOptions `json:",inline"`
	// contains filtered or unexported fields
}

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
	Cluster                  string
	SuperuserSecretRef       corev1.LocalObjectReference
	ServerImage              string
	ServerVersion            string
	JmxInitContainerImage    *images.Image
	Size                     int32
	Resources                *corev1.ResourceRequirements
	SystemReplication        SystemReplication
	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
	ServerEncryptionStores   *encryption.Stores
	ClientEncryptionStores   *encryption.Stores
	ClientKeystorePassword   string
	ClientTruststorePassword string
	ServerKeystorePassword   string
	ServerTruststorePassword 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 combines the cluster and dc templates with override semantics. If a property is defined in both templates, the dc-level property takes precedence.

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 ServerEncryptionOptionsYaml

type ServerEncryptionOptionsYaml struct {
	encryption.ServerEncryptionOptions `json:",inline"`
	// contains filtered or unexported fields
}

type SystemReplication

type SystemReplication struct {
	Datacenters       []string `json:"datacenters"`
	ReplicationFactor int      `json:"replicationFactor"`
}

SystemReplication represents the replication factor of the system_auth, system_traces, and system_distributed keyspaces. This is applied to each datacenter. The replication should be configured per DC, but that is currently not supported. See https://github.com/k8ssandra/management-api-for-apache-cassandra/issues/124 and https://github.com/k8ssandra/k8ssandra-operator/issues/91 for details. Note that when we can configure the replication per DC, this can be changed to a map[string]int.

func ComputeInitialSystemReplication

func ComputeInitialSystemReplication(kc *api.K8ssandraCluster) SystemReplication

Jump to

Keyboard shortcuts

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