Skip to content

Commit

Permalink
Inject archive index configuration for provisioned ES (#309)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Mar 13, 2019
1 parent ac49399 commit 0f1c97e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pkg/storage/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,34 @@ func (ed *ElasticsearchDeployment) InjectStorageConfiguration(p *corev1.PodSpec)
})
// we assume jaeger containers are first
if len(p.Containers) > 0 {
// TODO add to archive storage if it is enabled?
p.Containers[0].Args = append(p.Containers[0].Args,
"--es.server-urls="+elasticsearchURL,
"--es.token-file="+k8sTokenFile,
"--es.tls.ca="+caPath)
if !containsPrefix("--es.num-shards", p.Containers[0].Args) {
if findItem("--es.num-shards", p.Containers[0].Args) == "" {
// taken from https://github.com/openshift/cluster-logging-operator/blob/32b69e8bcf61a805e8f3c45c664a3c08d1ee62d5/vendor/github.com/openshift/elasticsearch-operator/pkg/k8shandler/configmaps.go#L38
// every ES node is a data node
p.Containers[0].Args = append(p.Containers[0].Args, fmt.Sprintf("--es.num-shards=%d", dataNodesCount(ed.Jaeger.Spec.Storage.Elasticsearch.NodeCount)))
}
if !containsPrefix("--es.num-replicas", p.Containers[0].Args) {
if findItem("--es.num-replicas", p.Containers[0].Args) == "" {
p.Containers[0].Args = append(p.Containers[0].Args, fmt.Sprintf("--es.num-replicas=%d",
calculateReplicaShards(ed.Jaeger.Spec.Storage.Elasticsearch.RedundancyPolicy, int(dataNodesCount(ed.Jaeger.Spec.Storage.Elasticsearch.NodeCount)))))
}
if strings.EqualFold(findItem("--es-archive.enabled", p.Containers[0].Args), "--es-archive.enabled=true") {
p.Containers[0].Args = append(p.Containers[0].Args,
"--es-archive.server-urls="+elasticsearchURL,
"--es-archive.token-file="+k8sTokenFile,
"--es-archive.tls.ca="+caPath)
if findItem("--es-archive.num-shards", p.Containers[0].Args) == "" {
// taken from https://github.com/openshift/cluster-logging-operator/blob/32b69e8bcf61a805e8f3c45c664a3c08d1ee62d5/vendor/github.com/openshift/elasticsearch-operator/pkg/k8shandler/configmaps.go#L38
// every ES node is a data node
p.Containers[0].Args = append(p.Containers[0].Args, fmt.Sprintf("--es-archive.num-shards=%d", dataNodesCount(ed.Jaeger.Spec.Storage.Elasticsearch.NodeCount)))
}
if findItem("--es-archive.num-replicas", p.Containers[0].Args) == "" {
p.Containers[0].Args = append(p.Containers[0].Args, fmt.Sprintf("--es-archive.num-replicas=%d",
calculateReplicaShards(ed.Jaeger.Spec.Storage.Elasticsearch.RedundancyPolicy, int(dataNodesCount(ed.Jaeger.Spec.Storage.Elasticsearch.NodeCount)))))
}
}
p.Containers[0].VolumeMounts = append(p.Containers[0].VolumeMounts, corev1.VolumeMount{
Name: volumeName,
ReadOnly: true,
Expand Down Expand Up @@ -182,11 +196,11 @@ func calculateReplicaShards(policyType esv1alpha1.RedundancyPolicyType, dataNode
}
}

func containsPrefix(prefix string, arr []string) bool {
func findItem(prefix string, arr []string) string {
for _, a := range arr {
if strings.HasPrefix(a, prefix) {
return true
return a
}
}
return false
return ""
}
27 changes: 27 additions & 0 deletions pkg/storage/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ func TestInject(t *testing.T) {
SecretName: "hoo-jaeger-elasticsearch"}}},
}},
},
{
pod: &corev1.PodSpec{Containers: []corev1.Container{{Args: []string{"--es-archive.enabled=true"}}}},
es: v1.ElasticsearchSpec{NodeCount: 15, RedundancyPolicy: esv1alpha1.FullRedundancy},
expected: &corev1.PodSpec{
Containers: []corev1.Container{{
Args: []string{
"--es-archive.enabled=true",
"--es.server-urls=" + elasticsearchURL,
"--es.token-file=" + k8sTokenFile,
"--es.tls.ca=" + caPath,
"--es.num-shards=12",
"--es.num-replicas=11",
"--es-archive.server-urls=" + elasticsearchURL,
"--es-archive.token-file=" + k8sTokenFile,
"--es-archive.tls.ca=" + caPath,
"--es-archive.num-shards=12",
"--es-archive.num-replicas=11",
},
VolumeMounts: []corev1.VolumeMount{
{Name: volumeName, ReadOnly: true, MountPath: volumeMountPath},
},
}},
Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "hoo-jaeger-elasticsearch"}}},
}},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 0f1c97e

Please sign in to comment.