Skip to content

Commit

Permalink
Migrate jaeger.tags in existing CRs (#1380)
Browse files Browse the repository at this point in the history
This commit adds a migration for existing CRs, moving from the deprecated jaeger.tags to collector.tags or agent.tags, according to the components being used.

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling authored Feb 4, 2021
1 parent 39d24df commit 883ae48
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/upgrade/v1_22_0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package upgrade

import (
"context"

"sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
)

func upgrade1_22_0(ctx context.Context, client client.Client, jaeger v1.Jaeger) (v1.Jaeger, error) {
flagMapCollector := []deprecationFlagMap{{
from: "jaeger.tags",
to: "collector.tags",
}}

flagMapAgent := []deprecationFlagMap{{
from: "jaeger.tags",
to: "agent.tags",
}}

j := &jaeger
j.Spec.AllInOne.Options = migrateDeprecatedOptions(j, j.Spec.AllInOne.Options, flagMapCollector)
j.Spec.Collector.Options = migrateDeprecatedOptions(j, j.Spec.Collector.Options, flagMapCollector)
j.Spec.Agent.Options = migrateDeprecatedOptions(j, j.Spec.Agent.Options, flagMapAgent)

return jaeger, nil
}
57 changes: 57 additions & 0 deletions pkg/upgrade/v1_22_0_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package upgrade

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
)

func TestUpgradeJaegerTagssv1_22_0(t *testing.T) {
latestVersion := "1.22.0"
opts := v1.NewOptions(map[string]interface{}{
"jaeger.tags": "somekey=somevalue",
})

nsn := types.NamespacedName{Name: "my-instance"}
existing := v1.NewJaeger(nsn)
existing.Status.Version = "1.21.0"
existing.Spec.AllInOne.Options = opts
existing.Spec.Agent.Options = opts
existing.Spec.Collector.Options = opts
objs := []runtime.Object{existing}

s := scheme.Scheme
s.AddKnownTypes(v1.SchemeGroupVersion, &v1.Jaeger{})
s.AddKnownTypes(v1.SchemeGroupVersion, &v1.JaegerList{})
cl := fake.NewFakeClient(objs...)

// test
assert.NoError(t, ManagedInstances(context.Background(), cl, cl, latestVersion))

// verify
persisted := &v1.Jaeger{}
assert.NoError(t, cl.Get(context.Background(), nsn, persisted))
assert.Equal(t, latestVersion, persisted.Status.Version)

aioOpts := persisted.Spec.AllInOne.Options.Map()
assert.Contains(t, aioOpts, "collector.tags")
assert.Equal(t, "somekey=somevalue", aioOpts["collector.tags"])
assert.NotContains(t, aioOpts, "jaeger.tags")

agOpts := persisted.Spec.Agent.Options.Map()
assert.Contains(t, agOpts, "agent.tags")
assert.Equal(t, "somekey=somevalue", agOpts["agent.tags"])
assert.NotContains(t, agOpts, "jaeger.tags")

colOpts := persisted.Spec.Collector.Options.Map()
assert.Contains(t, colOpts, "collector.tags")
assert.Equal(t, "somekey=somevalue", colOpts["collector.tags"])
assert.NotContains(t, colOpts, "jaeger.tags")
}
1 change: 1 addition & 0 deletions pkg/upgrade/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ var (
"1.17.0": upgrade1_17_0,
"1.18.0": upgrade1_18_0,
"1.20.0": upgrade1_20_0,
"1.22.0": upgrade1_22_0,
}
)

0 comments on commit 883ae48

Please sign in to comment.