in controllers/util/zk_util.go [33:141]
func GenerateZookeeperCluster(solrCloud *solrv1beta1.SolrCloud, zkSpec *solrv1beta1.ZookeeperSpec) *zkApi.ZookeeperCluster {
labels := solrCloud.SharedLabelsWith(solrCloud.GetLabels())
labels["technology"] = solrv1beta1.ZookeeperTechnologyLabel
zkSpecLabels := labels
if len(zkSpec.Labels) > 0 {
zkSpecLabels = MergeLabelsOrAnnotations(zkSpec.Labels, zkSpecLabels)
}
zkCluster := &zkApi.ZookeeperCluster{
ObjectMeta: metav1.ObjectMeta{
Name: solrCloud.ProvidedZookeeperName(),
Namespace: solrCloud.GetNamespace(),
Labels: labels,
},
Spec: zkApi.ZookeeperClusterSpec{
Image: zkApi.ContainerImage{
Repository: zkSpec.Image.Repository,
Tag: zkSpec.Image.Tag,
PullPolicy: zkSpec.Image.PullPolicy,
},
Labels: zkSpecLabels,
Replicas: *zkSpec.Replicas,
Ports: []corev1.ContainerPort{
{
Name: "client",
ContainerPort: 2181,
},
{
Name: "quorum",
ContainerPort: 2888,
},
{
Name: "leader-election",
ContainerPort: 3888,
},
},
Pod: zkApi.PodPolicy{
Labels: zkSpec.ZookeeperPod.Labels,
NodeSelector: zkSpec.ZookeeperPod.NodeSelector,
Affinity: zkSpec.ZookeeperPod.Affinity,
TopologySpreadConstraints: zkSpec.ZookeeperPod.TopologySpreadConstraints,
Resources: zkSpec.ZookeeperPod.Resources,
Tolerations: zkSpec.ZookeeperPod.Tolerations,
Env: zkSpec.ZookeeperPod.Env,
Annotations: zkSpec.ZookeeperPod.Annotations,
SecurityContext: zkSpec.ZookeeperPod.SecurityContext,
TerminationGracePeriodSeconds: zkSpec.ZookeeperPod.TerminationGracePeriodSeconds,
ServiceAccountName: zkSpec.ZookeeperPod.ServiceAccountName,
ImagePullSecrets: zkSpec.ZookeeperPod.ImagePullSecrets,
},
AdminServerService: zkSpec.AdminServerService,
ClientService: zkSpec.ClientService,
HeadlessService: zkSpec.HeadlessService,
Conf: zkApi.ZookeeperConfig(zkSpec.Config),
Containers: zkSpec.Containers,
InitContainers: zkSpec.InitContainers,
Volumes: zkSpec.Volumes,
VolumeMounts: zkSpec.VolumeMounts,
Probes: zkSpec.Probes,
MaxUnavailableReplicas: zkSpec.MaxUnavailableReplicas,
},
}
// Add storage information for the ZK Cluster
if zkSpec.Persistence != nil {
// If persistence is provided, then chose it.
zkCluster.Spec.StorageType = "persistence"
} else if zkSpec.Ephemeral != nil {
// If ephemeral is provided, then chose it.
zkCluster.Spec.StorageType = "ephemeral"
} else {
// If neither option is provided, default to the option used for solr (which defaults to ephemeral)
if solrCloud.Spec.StorageOptions.PersistentStorage != nil {
zkCluster.Spec.StorageType = "persistence"
} else {
zkCluster.Spec.StorageType = "ephemeral"
}
}
// Set the persistence/ephemeral options if necessary
if zkSpec.Persistence != nil && zkCluster.Spec.StorageType == "persistence" {
zkCluster.Spec.Persistence = &zkApi.Persistence{
VolumeReclaimPolicy: zkApi.VolumeReclaimPolicy(zkSpec.Persistence.VolumeReclaimPolicy),
PersistentVolumeClaimSpec: zkSpec.Persistence.PersistentVolumeClaimSpec,
Annotations: zkSpec.Persistence.Annotations,
}
} else if zkSpec.Ephemeral != nil && zkCluster.Spec.StorageType == "ephemeral" {
zkCluster.Spec.Ephemeral = &zkApi.Ephemeral{
EmptyDirVolumeSource: zkSpec.Ephemeral.EmptyDirVolumeSource,
}
}
if solrCloud.Spec.SolrAddressability.KubeDomain != "" {
zkCluster.Spec.KubernetesClusterDomain = solrCloud.Spec.SolrAddressability.KubeDomain
}
if zkSpec.Image.ImagePullSecret != "" {
if len(zkSpec.ZookeeperPod.ImagePullSecrets) > 0 {
zkCluster.Spec.Pod.ImagePullSecrets = append(zkCluster.Spec.Pod.ImagePullSecrets, corev1.LocalObjectReference{Name: zkSpec.Image.ImagePullSecret})
} else {
zkCluster.Spec.Pod.ImagePullSecrets = []corev1.LocalObjectReference{{Name: zkSpec.Image.ImagePullSecret}}
}
}
// Add defaults that the ZK Operator should set itself, otherwise we will have problems with reconcile loops.
zkCluster.WithDefaults()
return zkCluster
}