Skip to content

Commit f69c8c1

Browse files
authored
internal/controller: login atlas cloud via project config (#275)
1 parent d035e37 commit f69c8c1

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

charts/atlas-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: atlas-operator
33
description: The Atlas Kubernetes Operator
44
type: application
5-
version: 0.7.3
6-
appVersion: 0.7.3
5+
version: 0.7.4
6+
appVersion: 0.7.4

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.23.2
66

77
require (
88
ariga.io/atlas v0.28.1
9-
ariga.io/atlas-go-sdk v0.6.4
9+
ariga.io/atlas-go-sdk v0.6.7
1010
github.com/hashicorp/hcl/v2 v2.18.1
1111
github.com/rogpeppe/go-internal v1.13.1
1212
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ariga.io/atlas v0.28.1 h1:cNE0FYmoYs1u4KF+FGnp2on1srhM6FDpjaCgL7Rd8/c=
22
ariga.io/atlas v0.28.1/go.mod h1:LOOp18LCL9r+VifvVlJqgYJwYl271rrXD9/wIyzJ8sw=
3-
ariga.io/atlas-go-sdk v0.6.4 h1:6iSUoMkHi7CijzxW4c+iMly53UFdw07HX8ECRglkUR4=
4-
ariga.io/atlas-go-sdk v0.6.4/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ=
3+
ariga.io/atlas-go-sdk v0.6.7 h1:FEM+1kTmJsqCm4Tud9fIkdGshDQf3lO/eSjYpyy4+xg=
4+
ariga.io/atlas-go-sdk v0.6.7/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ=
55
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
66
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
77
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=

internal/controller/atlasmigration_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ func (r *AtlasMigrationReconciler) reconcile(ctx context.Context, data *migratio
259259
return r.resultErr(res, err, "ReadingMigrationData")
260260
}
261261
defer wd.Close()
262-
c, err := r.atlasClient(wd.Path(), data.Cloud)
262+
c, err := r.atlasClient(wd.Path(), nil)
263263
if err != nil {
264264
return r.resultErr(res, err, dbv1alpha1.ReasonCreatingAtlasClient)
265265
}
266266
var whoami *atlasexec.WhoAmI
267-
switch whoami, err = c.WhoAmI(ctx); {
267+
switch whoami, err = c.WhoAmI(ctx, &atlasexec.WhoAmIParams{Vars: data.Vars}); {
268268
case errors.Is(err, atlasexec.ErrRequireLogin):
269269
log.Info("the resource is not connected to Atlas Cloud")
270270
if data.Config != nil {

internal/controller/atlasschema_controller.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
164164
_, err = wd.WriteFile("atlas.hcl", buf.Bytes())
165165
return err
166166
}
167-
cli, err := r.atlasClient(wd.Path(), data.Cloud)
167+
cli, err := r.atlasClient(wd.Path(), nil)
168168
if err != nil {
169169
return r.resultErr(res, err, dbv1alpha1.ReasonCreatingAtlasClient)
170170
}
@@ -190,7 +190,7 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
190190
// Below this line is the main logic of the controller.
191191
// ====================================================
192192
var whoami *atlasexec.WhoAmI
193-
switch whoami, err = cli.WhoAmI(ctx); {
193+
switch whoami, err = cli.WhoAmI(ctx, &atlasexec.WhoAmIParams{Vars: data.Vars}); {
194194
case errors.Is(err, atlasexec.ErrRequireLogin):
195195
log.Info("the resource is not connected to Atlas Cloud")
196196
if data.Config != nil {
@@ -823,6 +823,20 @@ func (d *managedData) setLintReview(v dbv1alpha1.LintReview, force bool) {
823823
// asBlocks returns the HCL block for the environment configuration.
824824
func (d *managedData) asBlocks() []*hclwrite.Block {
825825
var blocks []*hclwrite.Block
826+
if d.Cloud != nil {
827+
atlas := hclwrite.NewBlock("atlas", nil)
828+
cloud := atlas.Body().AppendNewBlock("cloud", nil).Body()
829+
if d.Cloud.Token != "" {
830+
cloud.SetAttributeValue("token", cty.StringVal(d.Cloud.Token))
831+
}
832+
if d.Cloud.URL != "" {
833+
cloud.SetAttributeValue("url", cty.StringVal(d.Cloud.URL))
834+
}
835+
if d.Cloud.Repo != "" {
836+
cloud.SetAttributeValue("project", cty.StringVal(d.Cloud.Repo))
837+
}
838+
blocks = append(blocks, atlas)
839+
}
826840
env := hclwrite.NewBlock("env", []string{d.EnvName})
827841
blocks = append(blocks, env)
828842
envBody := env.Body()

internal/controller/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type (
6868
// SchemaPlanList runs the `schema plan list` command.
6969
SchemaPlanList(context.Context, *atlasexec.SchemaPlanListParams) ([]atlasexec.SchemaPlanFile, error)
7070
// WhoAmI runs the `whoami` command.
71-
WhoAmI(ctx context.Context) (*atlasexec.WhoAmI, error)
71+
WhoAmI(context.Context, *atlasexec.WhoAmIParams) (*atlasexec.WhoAmI, error)
7272
}
7373
// AtlasExecFn is a function that returns an AtlasExec
7474
// with the working directory.

internal/controller/testhelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (m *mockAtlasExec) SchemaPush(context.Context, *atlasexec.SchemaPushParams)
7878
return m.schemaPush.res, m.schemaPush.err
7979
}
8080

81-
func (m *mockAtlasExec) WhoAmI(context.Context) (*atlasexec.WhoAmI, error) {
81+
func (m *mockAtlasExec) WhoAmI(context.Context, *atlasexec.WhoAmIParams) (*atlasexec.WhoAmI, error) {
8282
return m.whoami.res, m.whoami.err
8383
}
8484

0 commit comments

Comments
 (0)