From dcd7873f26f670605669174d928493c2ccaceb1d Mon Sep 17 00:00:00 2001 From: Gary Brown Date: Tue, 27 Aug 2019 10:00:04 +0100 Subject: [PATCH] Add badger to supported list of storage types (#616) Signed-off-by: Gary Brown --- deploy/examples/with-badger-and-volume.yaml | 25 +++++++++++++++++++++ deploy/examples/with-badger.yaml | 7 ++++++ pkg/apis/jaegertracing/v1/jaeger_types.go | 2 +- pkg/storage/types.go | 1 + pkg/storage/types_test.go | 3 ++- pkg/strategy/controller.go | 6 ++++- pkg/strategy/controller_test.go | 15 ++++++++++++- test/e2e/examples_test.go | 13 ++++++++--- 8 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 deploy/examples/with-badger-and-volume.yaml create mode 100644 deploy/examples/with-badger.yaml diff --git a/deploy/examples/with-badger-and-volume.yaml b/deploy/examples/with-badger-and-volume.yaml new file mode 100644 index 000000000..ad8f39c12 --- /dev/null +++ b/deploy/examples/with-badger-and-volume.yaml @@ -0,0 +1,25 @@ +apiVersion: jaegertracing.io/v1 +kind: Jaeger +metadata: + name: with-badger-and-volume +spec: + allInOne: + volumeMounts: + - name: data + mountPath: /badger + volumes: + - name: data + emptyDir: {} + storage: + type: badger + options: + badger: + ephemeral: false + directory-key: "/badger/key" + directory-value: "/badger/data" + volumeMounts: + - name: data + mountPath: /badger + volumes: + - name: data + emptyDir: {} diff --git a/deploy/examples/with-badger.yaml b/deploy/examples/with-badger.yaml new file mode 100644 index 000000000..dc8dfa51c --- /dev/null +++ b/deploy/examples/with-badger.yaml @@ -0,0 +1,7 @@ +apiVersion: jaegertracing.io/v1 +kind: Jaeger +metadata: + name: with-badger +spec: + storage: + type: badger diff --git a/pkg/apis/jaegertracing/v1/jaeger_types.go b/pkg/apis/jaegertracing/v1/jaeger_types.go index 24e1242f0..67dd4e0f5 100644 --- a/pkg/apis/jaegertracing/v1/jaeger_types.go +++ b/pkg/apis/jaegertracing/v1/jaeger_types.go @@ -280,7 +280,7 @@ type JaegerAgentSpec struct { // JaegerStorageSpec defines the common storage options to be used for the query and collector // +k8s:openapi-gen=true type JaegerStorageSpec struct { - // Type can be `memory` (default), `cassandra`, `elasticsearch`, `kafka` or `managed` + // Type can be `memory` (default), `cassandra`, `elasticsearch`, `kafka` or `badger` // +optional Type string `json:"type,omitempty"` diff --git a/pkg/storage/types.go b/pkg/storage/types.go index 6eeec251b..12fa7e49f 100644 --- a/pkg/storage/types.go +++ b/pkg/storage/types.go @@ -11,6 +11,7 @@ func ValidTypes() []string { "kafka", "elasticsearch", "cassandra", + "badger", } } diff --git a/pkg/storage/types_test.go b/pkg/storage/types_test.go index 615b52a1c..a86d8378b 100644 --- a/pkg/storage/types_test.go +++ b/pkg/storage/types_test.go @@ -15,9 +15,10 @@ func TestElasticsearchPrefix(t *testing.T) { } func TestValidTypes(t *testing.T) { - assert.Len(t, ValidTypes(), 4) + assert.Len(t, ValidTypes(), 5) assert.Contains(t, ValidTypes(), "memory") assert.Contains(t, ValidTypes(), "elasticsearch") assert.Contains(t, ValidTypes(), "cassandra") assert.Contains(t, ValidTypes(), "kafka") + assert.Contains(t, ValidTypes(), "badger") } diff --git a/pkg/strategy/controller.go b/pkg/strategy/controller.go index 6502740bf..7e8289799 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -77,7 +77,7 @@ func normalize(jaeger *v1.Jaeger) { // check for incompatible options // if the storage is `memory`, then the only possible strategy is `all-in-one` - if strings.EqualFold(jaeger.Spec.Storage.Type, "memory") && !strings.EqualFold(jaeger.Spec.Strategy, "allinone") { + if !distributedStorage(jaeger.Spec.Storage.Type) && !strings.EqualFold(jaeger.Spec.Strategy, "allinone") { jaeger.Logger().WithField("storage", jaeger.Spec.Storage.Type).Warn("No suitable storage provided. Falling back to all-in-one") jaeger.Spec.Strategy = "allInOne" } @@ -100,6 +100,10 @@ func normalize(jaeger *v1.Jaeger) { normalizeUI(&jaeger.Spec) } +func distributedStorage(storage string) bool { + return !strings.EqualFold(storage, "memory") && !strings.EqualFold(storage, "badger") +} + func normalizeSparkDependencies(spec *v1.JaegerStorageSpec) { // auto enable only for supported storages if cronjob.SupportedStorage(spec.Type) && diff --git a/pkg/strategy/controller_test.go b/pkg/strategy/controller_test.go index 1c70a9cc0..88488b53c 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -72,7 +72,7 @@ func TestDefaultName(t *testing.T) { assert.NotEmpty(t, jaeger.Name) } -func TestIncompatibleStorageForProduction(t *testing.T) { +func TestIncompatibleMemoryStorageForProduction(t *testing.T) { jaeger := &v1.Jaeger{ Spec: v1.JaegerSpec{ Strategy: "production", @@ -85,6 +85,19 @@ func TestIncompatibleStorageForProduction(t *testing.T) { assert.Equal(t, "allInOne", jaeger.Spec.Strategy) } +func TestIncompatibleBadgerStorageForProduction(t *testing.T) { + jaeger := &v1.Jaeger{ + Spec: v1.JaegerSpec{ + Strategy: "production", + Storage: v1.JaegerStorageSpec{ + Type: "badger", + }, + }, + } + normalize(jaeger) + assert.Equal(t, "allInOne", jaeger.Spec.Strategy) +} + func TestIncompatibleStorageForStreaming(t *testing.T) { jaeger := &v1.Jaeger{ Spec: v1.JaegerSpec{ diff --git a/test/e2e/examples_test.go b/test/e2e/examples_test.go index 9c6dc77f2..07de82cbf 100644 --- a/test/e2e/examples_test.go +++ b/test/e2e/examples_test.go @@ -3,7 +3,7 @@ package e2e import ( - goctx "context" + "context" "encoding/json" "io/ioutil" "net/http" @@ -16,7 +16,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "golang.org/x/net/context" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" @@ -86,6 +85,14 @@ func (suite *ExamplesTestSuite) TestSimplestExample() { smokeTestAllInOneExample("simplest", "../../deploy/examples/simplest.yaml") } +func (suite *ExamplesTestSuite) TestWithBadgerExample() { + smokeTestAllInOneExample("with-badger", "../../deploy/examples/with-badger.yaml") +} + +func (suite *ExamplesTestSuite) TestWithBadgerAndVolumeExample() { + smokeTestAllInOneExample("with-badger-and-volume", "../../deploy/examples/with-badger-and-volume.yaml") +} + func (suite *ExamplesTestSuite) TestSimpleProdDeployEsExample() { if !isOpenShift(t) { t.Skip("Only applies to openshift") @@ -174,7 +181,7 @@ func (suite *ExamplesTestSuite) TestBusinessApp() { // Add a liveliness probe to create some traces vertxDeployment := &appsv1.Deployment{} key := types.NamespacedName{Name: "myapp", Namespace: namespace} - err = fw.Client.Get(goctx.Background(), key, vertxDeployment) + err = fw.Client.Get(context.Background(), key, vertxDeployment) require.NoError(t, err) vertxPort := intstr.IntOrString{IntVal: 8080}