Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject archive index configuration for provisioned ES #309

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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