Skip to content

Commit

Permalink
Add support for deploying elasticsearch (#191)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Feb 21, 2019
1 parent 07de1a2 commit b7f9241
Show file tree
Hide file tree
Showing 58 changed files with 2,723 additions and 1,158 deletions.
12 changes: 6 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ spec:
<1> Identifies the kafka configuration used by the collector, to produce the messages, and the ingester to consume the messages
<2> The deadlock interval can be disabled to avoid the ingester being terminated when no messages arrive within the default 1 minute period

== Elasticsearch storage

If no `es.server-urls` are provided Jaeger operator creates Elasticsearch CR based on the configuration
provided in storage section. Make sure link:https://github.com/openshift/elasticsearch-operator[elasticsearch-operator]
is running in your cluster otherwise Elasticsearch deployment will not be created. The Elasticsearch is meant
to be dedicated for a single Jaeger instance.

At the moment there can be only one Jaeger with Elasticsearch instance in a namespace.

Note that Elasticsearch requires virtual memory settings: `minikube ssh -- 'sudo sysctl -w vm.max_map_count=262144'`

== Accessing the UI

=== Kubernetes
Expand Down
13 changes: 12 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
FROM alpine:3.8
FROM registry.svc.ci.openshift.org/openshift/origin-v4.0:base

RUN INSTALL_PKGS=" \
openssl \
" && \
yum install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum clean all && \
mkdir /tmp/_working_dir && \
chmod og+w /tmp/_working_dir

COPY scripts/* /scripts/

USER nobody

Expand Down
16 changes: 16 additions & 0 deletions deploy/examples/simple-prod-deploy-es.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This CR deploys Jaeger and Elasticsearch
apiVersion: io.jaegertracing/v1alpha1
kind: Jaeger
metadata:
name: simple-prod
spec:
strategy: production
storage:
type: elasticsearch
elasticsearch:
nodeCount: 2
resources:
esIndexCleaner:
enabled: true
schedule: "*/30 * * * *"
numberOfDays: 1
13 changes: 13 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ rules:
- routes
verbs:
- "*"
- apiGroups:
- rbac.authorization.k8s.io
resources:
- roles
- rolebindings
verbs:
- '*'
- apiGroups:
- elasticsearch.jaegertracing.io
resources:
- jaeger
verbs:
- 'get'
28 changes: 27 additions & 1 deletion pkg/account/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package account

import (
"fmt"

"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
)
Expand All @@ -12,5 +15,28 @@ func Get(jaeger *v1alpha1.Jaeger) []*v1.ServiceAccount {
if jaeger.Spec.Ingress.Security == v1alpha1.IngressSecurityOAuthProxy {
accounts = append(accounts, OAuthProxy(jaeger))
}
return accounts
return append(accounts, getMain(jaeger))
}

func getMain(jaeger *v1alpha1.Jaeger) *v1.ServiceAccount {
trueVar := true
return &v1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: JaegerServiceAccountFor(jaeger),
Namespace: jaeger.Namespace,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: jaeger.APIVersion,
Kind: jaeger.Kind,
Name: jaeger.Name,
UID: jaeger.UID,
Controller: &trueVar,
},
},
},
}
}

func JaegerServiceAccountFor(jaeger *v1alpha1.Jaeger) string {
return fmt.Sprintf("%s", jaeger.Name)
}
16 changes: 12 additions & 4 deletions pkg/account/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ import (
func TestWithSecurityNil(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestWithOAuthProxyNil")
assert.Equal(t, v1alpha1.IngressSecurityNone, jaeger.Spec.Ingress.Security)
assert.Len(t, Get(jaeger), 0)
sas := Get(jaeger)
assert.Len(t, sas, 1)
assert.Equal(t, getMain(jaeger), sas[0])
}

func TestWithSecurityNone(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestWithOAuthProxyFalse")
jaeger.Spec.Ingress.Security = v1alpha1.IngressSecurityNone

assert.Len(t, Get(jaeger), 0)
sas := Get(jaeger)
assert.Len(t, sas, 1)
assert.Equal(t, getMain(jaeger), sas[0])
}

func TestWithSecurityOAuthProxy(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestWithOAuthProxyTrue")
jaeger.Spec.Ingress.Security = v1alpha1.IngressSecurityOAuthProxy

assert.Len(t, Get(jaeger), 1)
assert.Len(t, Get(jaeger), 2)
}

func TestJaegerName(t *testing.T) {
jaeger := v1alpha1.NewJaeger("foo")
assert.Equal(t, "foo", JaegerServiceAccountFor(jaeger))
}
12 changes: 12 additions & 0 deletions pkg/apis/io/v1alpha1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package v1alpha1
import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1"
esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1"
)

// IngressSecurityType represents the possible values for the security type
Expand Down Expand Up @@ -136,6 +139,15 @@ type JaegerStorageSpec struct {
CassandraCreateSchema JaegerCassandraCreateSchemaSpec `json:"cassandraCreateSchema"`
SparkDependencies JaegerDependenciesSpec `json:"dependencies"`
EsIndexCleaner JaegerEsIndexCleanerSpec `json:"esIndexCleaner"`
Elasticsearch ElasticsearchSpec `json:"elasticsearch"`
}

type ElasticsearchSpec struct {
Resources v1.ResourceRequirements `json:"resources"`
NodeCount int32 `json:"nodeCount"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Storage esv1alpha1.ElasticsearchStorageSpec `json:"storage"`
RedundancyPolicy v1alpha1.RedundancyPolicyType `json:"redundancyPolicy"`
}

// JaegerCassandraCreateSchemaSpec holds the options related to the create-schema batch job
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package controller

import (
routev1 "github.com/openshift/api/route/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/manager"

esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1"
)

// AddToManagerFuncs is a list of functions to add all Controllers to the Manager
Expand All @@ -13,6 +16,9 @@ func AddToManager(m manager.Manager) error {
if err := routev1.AddToScheme(m.GetScheme()); err != nil {
return err
}
// TODO temporal fix https://github.com/jaegertracing/jaeger-operator/issues/206
gv := schema.GroupVersion{Group: "logging.openshift.io", Version: "v1alpha1"}
m.GetScheme().AddKnownTypes(gv, &esv1alpha1.Elasticsearch{})

for _, f := range AddToManagerFuncs {
if err := f(m); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cronjob/es_index_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func CreateEsIndexCleaner(jaeger *v1alpha1.Jaeger) *batchv1beta1.CronJob {
esUrls := getEsHostname(jaeger.Spec.Storage.Options.Map())
trueVar := true
one := int32(1)
name := fmt.Sprintf("%s-es-index-cleaner", jaeger.Name)
return &batchv1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -35,6 +36,7 @@ func CreateEsIndexCleaner(jaeger *v1alpha1.Jaeger) *batchv1beta1.CronJob {
Schedule: jaeger.Spec.Storage.EsIndexCleaner.Schedule,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Parallelism: &one,
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down
5 changes: 4 additions & 1 deletion pkg/cronjob/spark_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func CreateSparkDependencies(jaeger *v1alpha1.Jaeger) *batchv1beta1.CronJob {
envVars = append(envVars, getStorageEnvs(jaeger.Spec.Storage)...)

trueVar := true
one := int32(1)
name := fmt.Sprintf("%s-spark-dependencies", jaeger.Name)
return &batchv1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -45,9 +46,11 @@ func CreateSparkDependencies(jaeger *v1alpha1.Jaeger) *batchv1beta1.CronJob {
},
},
Spec: batchv1beta1.CronJobSpec{
Schedule: jaeger.Spec.Storage.SparkDependencies.Schedule,
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Schedule: jaeger.Spec.Storage.SparkDependencies.Schedule,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Parallelism: &one,
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployment/all-in-one.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/config/sampling"
"github.com/jaegertracing/jaeger-operator/pkg/config/ui"
Expand Down Expand Up @@ -157,7 +158,8 @@ func (a *AllInOne) Get() *appsv1.Deployment {
},
Resources: commonSpec.Resources,
}},
Volumes: commonSpec.Volumes,
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(a.jaeger),
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/config/sampling"
"github.com/jaegertracing/jaeger-operator/pkg/service"
Expand Down Expand Up @@ -147,7 +148,8 @@ func (c *Collector) Get() *appsv1.Deployment {
},
Resources: commonSpec.Resources,
}},
Volumes: commonSpec.Volumes,
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(c.jaeger),
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
Expand Down Expand Up @@ -133,7 +134,8 @@ func (i *Ingester) Get() *appsv1.Deployment {
},
Resources: commonSpec.Resources,
}},
Volumes: commonSpec.Volumes,
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(i.jaeger),
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/config/ui"
"github.com/jaegertracing/jaeger-operator/pkg/service"
Expand Down Expand Up @@ -132,7 +133,8 @@ func (q *Query) Get() *appsv1.Deployment {
},
Resources: commonSpec.Resources,
}},
Volumes: commonSpec.Volumes,
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(q.jaeger),
},
},
},
Expand Down
Loading

0 comments on commit b7f9241

Please sign in to comment.