Skip to content

Commit

Permalink
Migrate query host-port flags
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed May 12, 2021
1 parent 546e6a4 commit 56c95ec
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/upgrade/v1_22_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func upgrade1_22_0(ctx context.Context, client client.Client, jaeger v1.Jaeger)
j.Spec.Agent.Options = migrateDeprecatedOptions(j, j.Spec.Agent.Options, flagMapAgent)
j.Spec.Query.Options = migrateDeprecatedOptions(j, j.Spec.Query.Options, flagMapQuery)

//Migrate query host/port flags
j.Spec.Query.Options = migrateQueryHostPortFlagsv1_22_0(j.Spec.Query.Options)

return migrateCassandraVerifyFlagv1_22_0(jaeger), nil
}

Expand All @@ -59,3 +62,34 @@ func updateCassandraVerifyHostFlagv1_22_0(options v1.Options) v1.Options {
}
return v1.NewOptions(in)
}

func migrateQueryHostPortFlagsv1_22_0(options v1.Options) v1.Options {
in := options.GenericMap()

port, hasPortFlag := in["query.port"]
hostPort, hasHostPortFlag := in["query.host-port"]

_, hasGrpcFlag := in["query.grpc-server.host-port"]
_, hasHttpFlag := in["query.http-server.host-port"]

newValue := ""
if hasPortFlag {
newValue = ":" + port.(string)
} else if hasHostPortFlag {
newValue = hostPort.(string)
}

if newValue != "" {
if !hasGrpcFlag {
in["query.grpc-server.host-port"] = newValue
}
if !hasHttpFlag {
in["query.http-server.host-port"] = newValue
}
}

delete(in, "query.port")
delete(in, "query.host-port")

return v1.NewOptions(in)
}
99 changes: 99 additions & 0 deletions pkg/upgrade/v1_22_0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,102 @@ func TestCassandraVerifyHostFlags(t *testing.T) {
})
}
}

func TestMigrateQueryHostPortFlagsv1_22_0(t *testing.T) {

tests := []struct {
testName string
opts v1.Options
expectedOps map[string]string
}{
{
testName: "no old flags",
opts: v1.NewOptions(map[string]interface{}{
"query.grpc-server.host-port": ":8080",
"query.http-server.host-port": ":8081",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": ":8080",
"query.http-server.host-port": ":8081",
},
},

{
testName: "both old flags",
opts: v1.NewOptions(map[string]interface{}{
"query.port": "8080",
"query.host-port": "localhost:8081",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": ":8080",
"query.http-server.host-port": ":8080",
},
},

{
testName: "with query.host-port",
opts: v1.NewOptions(map[string]interface{}{
"query.host-port": "localhost:8081",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": "localhost:8081",
"query.http-server.host-port": "localhost:8081",
},
},
{
testName: "with grpc-server.host-port set",
opts: v1.NewOptions(map[string]interface{}{
"query.host-port": "localhost:8081",
"query.grpc-server.host-port": "other:7777",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": "other:7777",
"query.http-server.host-port": "localhost:8081",
},
},
{
testName: "with grpc-server.host-port set and query.port",
opts: v1.NewOptions(map[string]interface{}{
"query.port": "8081",
"query.grpc-server.host-port": "other:7777",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": "other:7777",
"query.http-server.host-port": ":8081",
},
},
{
testName: "with grpc/http-server.host-port set",
opts: v1.NewOptions(map[string]interface{}{
"query.host-port": "localhost:8081",
"query.grpc-server.host-port": "other:7777",
"query.http-server.host-port": "other:9999",
}),
expectedOps: map[string]string{
"query.grpc-server.host-port": "other:7777",
"query.http-server.host-port": "other:9999",
},
},
}
latestVersion := "1.22.0"
for _, tt := range tests {
nsn := types.NamespacedName{Name: "my-instance"}
existing := v1.NewJaeger(nsn)
existing.Status.Version = "1.21.0"
existing.Spec.Query.Options = tt.opts

objs := []runtime.Object{existing}
s := scheme.Scheme
s.AddKnownTypes(v1.SchemeGroupVersion, &v1.Jaeger{})
s.AddKnownTypes(v1.SchemeGroupVersion, &v1.JaegerList{})
cl := fake.NewFakeClient(objs...)
assert.NoError(t, ManagedInstances(context.Background(), cl, cl, latestVersion))

persisted := &v1.Jaeger{}
assert.NoError(t, cl.Get(context.Background(), nsn, persisted))
assert.Equal(t, latestVersion, persisted.Status.Version)
assert.Equal(t, tt.expectedOps, persisted.Spec.Query.Options.Map())

}

}

0 comments on commit 56c95ec

Please sign in to comment.