Skip to content

Commit

Permalink
controllers: add deployment context to migrate cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao committed Nov 2, 2023
1 parent 26867f5 commit 621d566
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
18 changes: 18 additions & 0 deletions api/v1alpha1/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v1alpha1

import "context"

type versionCtxKey struct{}

// WithVersionContext returns a new context with the given verison.
func WithVersionContext(ctx context.Context, version string) context.Context {
return context.WithValue(ctx, versionCtxKey{}, version)
}

// VersionFromContext returns the version from the given context.
func VersionFromContext(ctx context.Context) string {
if v := ctx.Value(versionCtxKey{}); v != nil {
return v.(string)
}
return ""
}
8 changes: 7 additions & 1 deletion controllers/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ func (r *AtlasMigrationReconciler) reconcile(ctx context.Context, dir, envName s
}, nil
}
// Execute Atlas CLI migrate command
report, err := c.MigrateApply(ctx, &atlas.MigrateApplyParams{Env: envName})
report, err := c.MigrateApply(ctx, &atlas.MigrateApplyParams{
Env: envName,
Context: &atlas.DeployRunContext{
TriggerType: atlas.TriggerTypeKubernetes,
TriggerVersion: dbv1alpha1.VersionFromContext(ctx),
},
})
if err != nil {
return nil, transient(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.21.2

require (
ariga.io/atlas v0.14.3-0.20231010104048-0c071bfc9161
ariga.io/atlas-go-sdk v0.1.1-0.20231029150106-1927c56b057b
ariga.io/atlas-go-sdk v0.1.1-0.20231102105853-9ab4fb4ddd54
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/mod v0.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ariga.io/atlas v0.14.3-0.20231010104048-0c071bfc9161 h1:xZS2wAf1AzRNA/8iD2LTAXtIZuIDYDXsZRlYBAyBu0A=
ariga.io/atlas v0.14.3-0.20231010104048-0c071bfc9161/go.mod h1:isZrlzJ5cpoCoKFoY9knZug7Lq4pP1cm8g3XciLZ0Pw=
ariga.io/atlas-go-sdk v0.1.1-0.20231029150106-1927c56b057b h1:pFSDzqE7YU7S8+fRnkiycFXCe39hpLALr2fgYhxjzAQ=
ariga.io/atlas-go-sdk v0.1.1-0.20231029150106-1927c56b057b/go.mod h1:owkEEXw6jqne5KPVDfKsYB7cwMiMk3jtOiAAeKxS/yU=
ariga.io/atlas-go-sdk v0.1.1-0.20231102105853-9ab4fb4ddd54 h1:/LzEDWzKDJH2e8vht7+kl2VO5hmkSC5SCyKAZtkLhiI=
ariga.io/atlas-go-sdk v0.1.1-0.20231102105853-9ab4fb4ddd54/go.mod h1:owkEEXw6jqne5KPVDfKsYB7cwMiMk3jtOiAAeKxS/yU=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"bytes"
"context"
"flag"
"os"
"strconv"
Expand Down Expand Up @@ -89,6 +90,9 @@ func main() {
LeaderElection: enableLeaderElection,
LeaderElectionID: "5220c287.atlasgo.io",
LeaderElectionReleaseOnCancel: true,
BaseContext: func() context.Context {
return dbv1alpha1.WithVersionContext(context.Background(), version)
},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 621d566

Please sign in to comment.