Skip to content

Commit 9702a75

Browse files
committed
fix some minor things
1 parent b2b1af6 commit 9702a75

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

pkg/instance/migrate/migrate.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"beryju.io/gravity/pkg/roles"
1212
"beryju.io/gravity/pkg/storage"
1313
"github.com/Masterminds/semver/v3"
14+
"github.com/getsentry/sentry-go"
1415
clientv3 "go.etcd.io/etcd/client/v3"
1516
"go.uber.org/zap"
1617
)
@@ -77,15 +78,17 @@ func (mi *Migrator) Run(ctx context.Context) (*storage.Client, error) {
7778
}
7879
mi.log.Debug("Checking migrations to activate for cluster version", zap.String("clusterVersion", cv.String()))
7980
cli := mi.ri.KV()
81+
span := sentry.TransactionFromContext(ctx).StartChild("gravity.instance.migrate")
82+
defer span.Finish()
8083
for _, m := range mi.migrations {
8184
mi.log.Debug("Checking if migration needs to be run", zap.String("migration", m.Name()))
82-
enabled, err := m.Check(cv, ctx)
85+
enabled, err := m.Check(cv, span.Context())
8386
if err != nil {
8487
mi.log.Warn("failed to check if migration should be enabled", zap.String("migration", m.Name()), zap.Error(err))
8588
return nil, err
8689
}
8790
if enabled {
88-
_cli, err := m.Hook(ctx)
91+
_cli, err := m.Hook(span.Context())
8992
if err != nil {
9093
mi.log.Warn("failed to hook for migration", zap.String("migration", m.Name()), zap.Error(err))
9194
return nil, err
@@ -94,7 +97,7 @@ func (mi *Migrator) Run(ctx context.Context) (*storage.Client, error) {
9497
cli = _cli
9598
} else {
9699
mi.log.Info("Running cleanup for migration", zap.String("migration", m.Name()))
97-
err := m.Cleanup(ctx)
100+
err := m.Cleanup(span.Context())
98101
if err != nil {
99102
mi.log.Warn("failed to cleanup migration", zap.String("migration", m.Name()), zap.Error(err))
100103
continue

pkg/roles/dhcp/role_migrations.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,26 @@ import (
1212
"go.uber.org/zap"
1313
)
1414

15-
func (r *Role) migrateMoveInitial() {
15+
func (r *Role) migrateMoveInitial(ctx context.Context) {
1616
r.log.Info("Running initial move migration")
17-
res, err := r.i.KV().Get(
18-
r.ctx,
19-
r.i.KV().Key(types.KeyRole, types.KeyLegacyLeases).Prefix(true).String(),
20-
clientv3.WithPrefix(),
21-
)
17+
pfx := r.i.KV().Key(types.KeyRole, types.KeyLegacyLeases).Prefix(true).String()
18+
res, err := r.i.KV().Get(ctx, pfx, clientv3.WithPrefix())
2219
if err != nil {
2320
r.log.Warn("failed to get legacy leases", zap.Error(err))
2421
return
2522
}
2623
// Copy from legacy prefix (global scope) to new prefix (scope-scoped)
2724
for _, kv := range res.Kvs {
2825
l := &Lease{}
26+
ident := strings.TrimPrefix(string(kv.Key), pfx)
2927
err = json.Unmarshal(kv.Value, &l)
3028
if err != nil {
3129
r.log.Warn("failed to parse lease", zap.Error(err))
3230
continue
3331
}
3432
_, err = r.i.KV().Put(
35-
r.ctx,
36-
r.i.KV().Key(types.KeyRole, types.KeyScopes, l.ScopeKey, l.Identifier).String(),
33+
ctx,
34+
r.i.KV().Key(types.KeyRole, types.KeyScopes, l.ScopeKey, ident).String(),
3735
string(kv.Value),
3836
)
3937
if err != nil {
@@ -67,7 +65,7 @@ func (r *Role) RegisterMigrations() {
6765
pureKV := r.i.KV()
6866
leasePrefix := r.i.KV().Key(types.KeyRole, types.KeyScopes).Prefix(true).String()
6967

70-
r.migrateMoveInitial()
68+
r.migrateMoveInitial(ctx)
7169

7270
return r.i.KV().WithHooks(storage.StorageHook{
7371
PutPost: func(ctx context.Context, key, val string, res *clientv3.PutResponse, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) {

0 commit comments

Comments
 (0)