Skip to content

Commit 9652abd

Browse files
authored
DB User Translation Layer & SDK migration (#1543)
* PoC dbuser translation layer * Move translation layer to a package Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Migrate translation later to new SDK * Make translation function names consistent * Fix e2e tests Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Convert To/FromAtlas * Do not send password unless set * Fix clusterwide int test Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Clean e2e tests * Fix typo in action Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Fix empty value pointers to be nil * Fix the dateFromAtlas translation Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Mark user tests to debug better * Fix performUpdateInAtlas * Add ListClusterDeploymentNames * Fix comparison normalization Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Add TODO comment * Interface renames & refactors * Use translation and pointer Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Rename to ServerURL * Use diffs instead * Correct comparison logic with diffs Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Test clusterwide with local int tests Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Fix normalization Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Use common normalization code * Specifically run int tests AND wide int tests * Link TODO to follow up ticket CLOUDP-253951 * Avoid explicit enum normalizations already enforced by kube * Fix error returns and cleanup unneeded code * Add deletion unit tests Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Cover databaseuser changes with unit tests * Added NewUser and DiffSpecs unit tests * Add dbuser tests Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Fix and simplify diff into equals Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com> * Clear refs from spec before comparison * Clear debugging traces --------- Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
1 parent 367ccd2 commit 9652abd

29 files changed

+2193
-185
lines changed

.licenses-gomod.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
100644 00dda197f010caa332e89410c3ffee1369343795 go.mod
1+
100644 c73f2c61e23f551b04db496892f2d197c1325d38 go.mod

.mockery.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ mockname: "{{.InterfaceName}}Mock"
77
all: true
88
packages:
99
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/ipaccesslist:
10+
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/dbuser:
11+
github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/translation/deployment:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/google/go-cmp v0.6.0
2222
github.com/google/uuid v1.6.0
2323
github.com/mongodb-forks/digest v1.1.0
24+
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1
2425
github.com/onsi/ginkgo/v2 v2.19.0
2526
github.com/onsi/gomega v1.33.1
2627
github.com/sethvargo/go-password v0.3.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8
203203
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
204204
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
205205
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
206+
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1 h1:dOYG7LS/WK00RWZc8XGgcUTlTxpp3mKhdR2Q9z9HbXM=
207+
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8=
206208
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
207209
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
208210
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=

internal/cmp/normalize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NormalizeSlice[S ~[]E, E any](slice S, cmp func(a, b E) int) S {
2929
if len(slice) == 0 {
3030
return nil
3131
}
32-
slices.SortFunc(slice, cmp)
32+
slices.SortStableFunc(slice, cmp)
3333
return slice
3434
}
3535

internal/cmp/sort.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ func marshalJSON[T any](obj T) (string, error) {
4949
}
5050
return string(jObj), nil
5151
}
52+
53+
func JSON[T any](obj T) []byte {
54+
jObj, err := json.MarshalIndent(obj, " ", " ")
55+
if err != nil {
56+
return ([]byte)(err.Error())
57+
}
58+
return jObj
59+
}
60+
61+
func JSONize[T any](obj T) string {
62+
return string(JSON(obj))
63+
}

internal/mocks/translation/atlas_deployments_service.go

Lines changed: 272 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)