Skip to content

Commit

Permalink
Add support for deploying elasticsearch CR and necessary com.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay committed Feb 20, 2019
1 parent 991bd48 commit d91be1d
Show file tree
Hide file tree
Showing 59 changed files with 2,678 additions and 1,161 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.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IMPORT_LOG=import.log
FMT_LOG=fmt.log

OPERATOR_NAME ?= jaeger-operator
NAMESPACE ?= "$(USER)"
NAMESPACE ?= jaegertracing
BUILD_IMAGE ?= "$(NAMESPACE)/$(OPERATOR_NAME):latest"
OUTPUT_BINARY ?= "$(BIN_DIR)/$(OPERATOR_NAME)"
VERSION_PKG ?= "github.com/jaegertracing/jaeger-operator/pkg/version"
Expand Down Expand Up @@ -48,7 +48,7 @@ build: format
@${GO_FLAGS} go build -o $(OUTPUT_BINARY) -ldflags $(LD_FLAGS)

.PHONY: docker
docker:
docker: build
@docker build --file build/Dockerfile -t "$(BUILD_IMAGE)" .

.PHONY: push
Expand All @@ -62,7 +62,7 @@ unit-tests:
@go test $(PACKAGES) -cover -coverprofile=cover.out

.PHONY: e2e-tests
e2e-tests: cassandra es crd build docker push
e2e-tests: cassandra es crd build docker
@mkdir -p deploy/test
@echo Running end-to-end tests...

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:
eabled: 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
1 change: 1 addition & 0 deletions pkg/controller/jaeger/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (r *ReconcileJaeger) handleCreate(str strategy.S) (bool, error) {
objs := str.Create()
created := false
for _, obj := range objs {

err := r.client.Create(context.Background(), obj)
if err != nil && !apierrors.IsAlreadyExists(err) {
log.WithError(err).Error("failed to create")
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 d91be1d

Please sign in to comment.