util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseBackupRestorePath = "/var/solr/data/backup-restore"
	TarredFile            = "/var/solr/data/backup-restore/backup.tgz"
	CleanupCommand        = " && rm -rf " + BaseBackupRestorePath + "/*"
	BackupTarCommand      = "cd " + BaseBackupRestorePath + " && tar -czf /tmp/backup.tgz * " + CleanupCommand + " && mv /tmp/backup.tgz " + TarredFile + " && chmod -R a+rwx " + TarredFile + " && cd - && "

	AWSSecretDir = "/var/aws"

	JobTTLSeconds = int32(60)
)
View Source
const (
	SolrMetricsPort     = 8080
	SolrMetricsPortName = "solr-metrics"
	ExtSolrMetricsPort  = 80

	DefaultPrometheusExporterEntrypoint      = "/opt/solr/contrib/prometheus-exporter/bin/solr-exporter"
	PrometheusExporterConfigMapKey           = "solr-prometheus-exporter.xml"
	PrometheusExporterConfigXmlMd5Annotation = "solr.apache.org/exporterConfigXmlMd5"
)
View Source
const (
	DefaultMaxPodsUnavailable          = "25%"
	DefaultMaxShardReplicasUnavailable = 1
)
View Source
const (
	SolrClientPortName  = "solr-client"
	BackupRestoreVolume = "backup-restore"

	SolrNodeContainer = "solrcloud-node"

	DefaultSolrUser  = 8983
	DefaultSolrGroup = 8983

	SolrStorageFinalizer             = "storage.finalizers.solr.apache.org"
	SolrZKConnectionStringAnnotation = "solr.apache.org/zkConnectionString"
	SolrPVCTechnologyLabel           = "solr.apache.org/technology"
	SolrCloudPVCTechnology           = "solr-cloud"
	SolrPVCStorageLabel              = "solr.apache.org/storage"
	SolrCloudPVCDataStorage          = "data"
	SolrPVCInstanceLabel             = "solr.apache.org/instance"
	SolrXmlMd5Annotation             = "solr.apache.org/solrXmlMd5"
	SolrTlsCertMd5Annotation         = "solr.apache.org/tlsCertMd5"
	SolrXmlFile                      = "solr.xml"
	LogXmlMd5Annotation              = "solr.apache.org/logXmlMd5"
	LogXmlFile                       = "log4j2.xml"
	SecurityJsonFile                 = "security.json"
	BasicAuthMd5Annotation           = "solr.apache.org/basicAuthMd5"
	DefaultProbePath                 = "/admin/info/system"

	DefaultStatefulSetPodManagementPolicy = appsv1.ParallelPodManagement

	DefaultLivenessProbeInitialDelaySeconds = 20
	DefaultLivenessProbeTimeoutSeconds      = 1
	DefaultLivenessProbeSuccessThreshold    = 1
	DefaultLivenessProbeFailureThreshold    = 3
	DefaultLivenessProbePeriodSeconds       = 10

	DefaultReadinessProbeInitialDelaySeconds = 15
	DefaultReadinessProbeTimeoutSeconds      = 1
	DefaultReadinessProbeSuccessThreshold    = 1
	DefaultReadinessProbeFailureThreshold    = 3
	DefaultReadinessProbePeriodSeconds       = 5

	DefaultStartupProbeInitialDelaySeconds = 20
	DefaultStartupProbeTimeoutSeconds      = 30
	DefaultStartupProbeSuccessThreshold    = 1
	DefaultStartupProbeFailureThreshold    = 15
	DefaultStartupProbePeriodSeconds       = 10

	DefaultKeyStorePath         = "/var/solr/tls"
	Pkcs12KeystoreFile          = "keystore.p12"
	DefaultWritableKeyStorePath = "/var/solr/tls/pkcs12"
	TLSCertKey                  = "tls.crt"
	TLSKeyKey                   = "tls.key"
	DefaultTrustStorePath       = "/var/solr/tls-truststore"
)

Variables

This section is empty.

Functions

func AddACLsToEnv

func AddACLsToEnv(allACL *solr.ZookeeperACL, readOnlyACL *solr.ZookeeperACL) (hasACLs bool, envVars []corev1.EnvVar)

AddACLsToEnv creates the neccessary environment variables for using ZK ACLs, and returns whether ACLs were provided. info: Zookeeper Connection Information

func AsyncIdForCollectionBackup

func AsyncIdForCollectionBackup(collection string, backupName string) string

func BackupPath

func BackupPath(backupName string) string

func BackupRestoreSubPathForCloud

func BackupRestoreSubPathForCloud(directoryOverride string, cloud string) string

func BackupSubPathForCloud

func BackupSubPathForCloud(directoryOverride string, cloud string, backupName string) string

func BasicAuthHeader

func BasicAuthHeader(basicAuthSecret *corev1.Secret) string

func CheckBackupForCollection

func CheckBackupForCollection(cloud *solr.SolrCloud, collection string, backupName string, httpHeaders map[string]string) (finished bool, success bool, asyncStatus string, err error)

func CheckStatusOfCollectionBackups

func CheckStatusOfCollectionBackups(backup *solr.SolrBackup) (allFinished bool)

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString helper function to test string contains

func CopyConfigMapFields

func CopyConfigMapFields(from, to *corev1.ConfigMap, logger logr.Logger) bool

CopyConfigMapFields copies the owned fields from one ConfigMap to another

func CopyDeploymentFields

func CopyDeploymentFields(from, to *appsv1.Deployment, logger logr.Logger) bool

CopyDeploymentFields copies the owned fields from one Deployment to another Returns true if the fields copied from don't match to.

func CopyIngressFields

func CopyIngressFields(from, to *netv1.Ingress, logger logr.Logger) bool

CopyIngressFields copies the owned fields from one Ingress to another

func CopyLabelsAndAnnotations

func CopyLabelsAndAnnotations(from, to *metav1.ObjectMeta, logger logr.Logger) (requireUpdate bool)

CopyLabelsAndAnnotations copies the labels and annotations from one object to another. Additional Labels and Annotations in the 'to' object will not be removed. Returns true if there are updates required to the object.

func CopyPodContainers

func CopyPodContainers(fromPtr, toPtr *[]corev1.Container, basePath string, logger logr.Logger) (requireUpdate bool)

func CopyPodTemplates

func CopyPodTemplates(from, to *corev1.PodTemplateSpec, basePath string, logger logr.Logger) (requireUpdate bool)

func CopyServiceFields

func CopyServiceFields(from, to *corev1.Service, logger logr.Logger) bool

CopyServiceFields copies the owned fields from one Service to another

func CopyStatefulSetFields

func CopyStatefulSetFields(from, to *appsv1.StatefulSet, logger logr.Logger) bool

CopyStatefulSetFields copies the owned fields from one StatefulSet to another Returns true if the fields copied from don't match to.

func CopyZookeeperClusterFields

func CopyZookeeperClusterFields(from, to *zk.ZookeeperCluster, logger logr.Logger) bool

CopyZookeeperClusterFields copies the owned fields from one ZookeeperCluster to another Returns true if the fields copied from don't match to.

func CreateCommonIngressRule

func CreateCommonIngressRule(solrCloud *solr.SolrCloud, domainName string) (ingressRule netv1.IngressRule)

CreateCommonIngressRule returns a new Ingress Rule generated for a SolrCloud under the given domainName solrCloud: SolrCloud instance domainName: string Domain for the ingress rule to use

func CreateMetricsIngressRule

func CreateMetricsIngressRule(solrPrometheusExporter *solr.SolrPrometheusExporter, ingressBaseDomain string) netv1.IngressRule

CreateMetricsIngressRule returns a new Ingress Rule generated for the solr metrics endpoint This is not currently used, as an ingress is not created for the metrics endpoint. solrCloud: SolrCloud instance nodeName: string Name of the node ingressBaseDomain: string base domain for the ingress controller

func CreateNodeIngressRule

func CreateNodeIngressRule(solrCloud *solr.SolrCloud, nodeName string, domainName string) (ingressRule netv1.IngressRule)

CreateNodeIngressRule returns a new Ingress Rule generated for a specific Solr Node under the given domainName solrCloud: SolrCloud instance nodeName: string Name of the node domainName: string Domain for the ingress rule to use

func CreateSolrIngressRules

func CreateSolrIngressRules(solrCloud *solr.SolrCloud, nodeNames []string, domainNames []string) []netv1.IngressRule

CreateSolrIngressRules returns all applicable ingress rules for a cloud. solrCloud: SolrCloud instance nodeNames: the names for each of the solr pods domainName: string Domain for the ingress rule to use

func DeepEqualWithNils

func DeepEqualWithNils(x, y interface{}) bool

DeepEqualWithNils returns a deepEquals call that treats nil and zero-length maps, arrays and slices as the same.

func DeleteAsyncInfoForBackup

func DeleteAsyncInfoForBackup(cloud *solr.SolrCloud, collection string, backupName string, httpHeaders map[string]string) (err error)

func DeterminePodsSafeToUpdate

func DeterminePodsSafeToUpdate(cloud *solr.SolrCloud, outOfDatePods []corev1.Pod, totalPods int, readyPods int, availableUpdatedPodCount int, outOfDatePodsNotStartedCount int, logger logr.Logger, httpHeaders map[string]string) (podsToUpdate []corev1.Pod, retryLater bool)

DeterminePodsSafeToUpdate takes a list of solr Pods and returns a list of pods that are safe to upgrade now. This function MUST be idempotent and return the same list of pods given the same kubernetes/solr state.

NOTE: It is assumed that the list of pods provided are all started. If an out of date pod has a solr container that is not started, it should be accounted for in outOfDatePodsNotStartedCount not outOfDatePods.

TODO:

  • Think about caching this for ~250 ms? Not a huge need to send these requests milliseconds apart.
  • Might be too much complexity for very little gain.

func DuplicateLabelsOrAnnotations

func DuplicateLabelsOrAnnotations(from map[string]string) map[string]string

func EnsureDirectoryForBackup

func EnsureDirectoryForBackup(solrCloud *solr.SolrCloud, backup string, config *rest.Config) (err error)

func GenerateBackupPersistenceJob

func GenerateBackupPersistenceJob(solrBackup *solr.SolrBackup, solrBackupVolume corev1.VolumeSource, backupSubPath string) *batchv1.Job

GenerateBackupPersistenceJob creates a Job that will persist backup data and purge the backup from the solrBackupVolume

func GenerateBackupPersistenceJobForCloud

func GenerateBackupPersistenceJobForCloud(backup *solr.SolrBackup, solrCloud *solr.SolrCloud) *batchv1.Job

func GenerateBasicAuthSecretWithBootstrap

func GenerateBasicAuthSecretWithBootstrap(solrCloud *solr.SolrCloud) (*corev1.Secret, *corev1.Secret)

func GenerateCommonService

func GenerateCommonService(solrCloud *solr.SolrCloud) *corev1.Service

GenerateCommonService returns a new corev1.Service pointer generated for the entire SolrCloud instance solrCloud: SolrCloud instance

func GenerateConfigMap

func GenerateConfigMap(solrCloud *solr.SolrCloud) *corev1.ConfigMap

GenerateConfigMap returns a new corev1.ConfigMap pointer generated for the SolrCloud instance solr.xml solrCloud: SolrCloud instance

func GenerateHeadlessService

func GenerateHeadlessService(solrCloud *solr.SolrCloud) *corev1.Service

GenerateHeadlessService returns a new Headless corev1.Service pointer generated for the SolrCloud instance The PublishNotReadyAddresses option is set as true, because we want each pod to be reachable no matter the readiness of the pod. solrCloud: SolrCloud instance

func GenerateIngress

func GenerateIngress(solrCloud *solr.SolrCloud, nodeNames []string) (ingress *netv1.Ingress)

GenerateIngress returns a new Ingress pointer generated for the entire SolrCloud, pointing to all instances solrCloud: SolrCloud instance nodeStatuses: []SolrNodeStatus the nodeStatuses

func GenerateMetricsConfigMap

func GenerateMetricsConfigMap(solrPrometheusExporter *solr.SolrPrometheusExporter) *corev1.ConfigMap

GenerateMetricsConfigMap returns a new corev1.ConfigMap pointer generated for the Solr Prometheus Exporter instance solr-prometheus-exporter.xml solrPrometheusExporter: SolrPrometheusExporter instance

func GenerateNodeService

func GenerateNodeService(solrCloud *solr.SolrCloud, nodeName string) *corev1.Service

GenerateNodeService returns a new External corev1.Service pointer generated for the given Solr Node. The PublishNotReadyAddresses option is set as true, because we want each pod to be reachable no matter the readiness of the pod. solrCloud: SolrCloud instance nodeName: string node

func GeneratePersistenceOptions

func GeneratePersistenceOptions(solrBackup *solr.SolrBackup, solrBackupVolume corev1.VolumeSource) (image solr.ContainerImage, envVars []corev1.EnvVar, command []string, volume *corev1.Volume, volumeMount *corev1.VolumeMount, numRetries *int32)

GeneratePersistenceOptions creates options for a Job that will persist backup data

func GenerateSolrMetricsService

func GenerateSolrMetricsService(solrPrometheusExporter *solr.SolrPrometheusExporter) *corev1.Service

GenerateSolrMetricsService returns a new corev1.Service pointer generated for the SolrCloud Prometheus Exporter deployment Metrics will be collected on this service endpoint, as we don't want to double-tick data if multiple exporters are runnning. solrPrometheusExporter: solrPrometheusExporter instance

func GenerateSolrPrometheusExporterDeployment

func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrPrometheusExporter, solrConnectionInfo SolrConnectionInfo, configXmlMd5 string, tls *TLSClientOptions, basicAuthMd5 string) *appsv1.Deployment

GenerateSolrPrometheusExporterDeployment returns a new appsv1.Deployment pointer generated for the SolrCloud Prometheus Exporter instance solrPrometheusExporter: SolrPrometheusExporter instance

func GenerateStatefulSet

func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCloudStatus, hostNameIPs map[string]string, reconcileConfigInfo map[string]string, createPkcs12InitContainer bool, tlsCertMd5 string) *appsv1.StatefulSet

GenerateStatefulSet returns a new appsv1.StatefulSet pointer generated for the SolrCloud instance object: SolrCloud instance replicas: the number of replicas for the SolrCloud instance storage: the size of the storage for the SolrCloud instance (e.g. 100Gi) zkConnectionString: the connectionString of the ZK instance to connect to

func GenerateZookeeperCluster

func GenerateZookeeperCluster(solrCloud *solr.SolrCloud, zkSpec *solr.ZookeeperSpec) *zk.ZookeeperCluster

GenerateZookeeperCluster returns a new ZookeeperCluster pointer generated for the SolrCloud instance object: SolrCloud instance zkSpec: the spec of the ZookeeperCluster to generate

func GetCustomProbePaths

func GetCustomProbePaths(solrCloud *solr.SolrCloud) []string

func IsPVCOrphan

func IsPVCOrphan(pvcName string, replicas int32) bool

IsPVCOrphan determines whether the given name represents a PVC that is an orphan, or no longer has a pod associated with it.

func MergeLabelsOrAnnotations

func MergeLabelsOrAnnotations(base, additional map[string]string) map[string]string

func OvertakeControllerRef

func OvertakeControllerRef(owner metav1.Object, controlled metav1.Object, scheme *runtime.Scheme) (needsUpdate bool, err error)

OvertakeControllerRef makes sure that the controlled object has the owner as the controller ref. If the object has a different controller, then that ref will be downgraded to an "owner" and the new controller ref will be added

func RemoveString

func RemoveString(slice []string, s string) (result []string)

RemoveString helper function to remove string

func ResolveMaxPodsUnavailable

func ResolveMaxPodsUnavailable(maxPodsUnavailable *intstr.IntOrString, desiredPods int) (int, error)

ResolveMaxPodsUnavailable resolves the maximum number of pods that are allowed to be unavailable, when choosing pods to update.

func ResolveMaxShardReplicasUnavailable

func ResolveMaxShardReplicasUnavailable(maxShardReplicasUnavailable *intstr.IntOrString, shard string, totalShardReplicas map[string]int, cache map[string]int) (int, error)

ResolveMaxShardReplicasUnavailable resolves the maximum number of replicas that are allowed to be unavailable for a given shard, when choosing pods to update.

func RestorePath

func RestorePath(backupName string) string

func RestoreSubPathForCloud

func RestoreSubPathForCloud(directoryOverride string, cloud string, restoreName string) string

func RunExecForPod

func RunExecForPod(podName string, namespace string, command []string, config rest.Config) (err error)

func SolrNodeName

func SolrNodeName(solrCloud *solr.SolrCloud, pod corev1.Pod) string

SolrNodeName takes a cloud and a pod and returns the Solr nodeName for that pod

func StartBackupForCollection

func StartBackupForCollection(cloud *solr.SolrCloud, collection string, backupName string, httpHeaders map[string]string) (success bool, err error)

func TLSEnvVars

func TLSEnvVars(opts *solr.SolrTLSOptions, createPkcs12InitContainer bool) []corev1.EnvVar

func ValidateBasicAuthSecret

func ValidateBasicAuthSecret(basicAuthSecret *corev1.Secret) error

Types

type SolrConnectionInfo

type SolrConnectionInfo struct {
	CloudZkConnnectionInfo *solr.ZookeeperConnectionInfo
	StandaloneAddress      string
}

SolrConnectionInfo defines how to connect to a cloud or standalone solr instance. One, and only one, of Cloud or Standalone must be provided.

type SolrNodeContents

type SolrNodeContents struct {
	// contains filtered or unexported fields
}

func (*SolrNodeContents) InClusterState

func (nodeContents *SolrNodeContents) InClusterState() bool

type TLSClientOptions

type TLSClientOptions struct {
	TLSOptions               *solr.SolrTLSOptions
	NeedsPkcs12InitContainer bool
	TLSCertMd5               string
}

Used internally to capture config needed to provided Solr client apps like the exporter with config needed to call TLS enabled Solr pods

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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