-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate jaeger.tags in existing CRs (#1380)
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
1 parent
39d24df
commit 883ae48
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
} | ||
) |