Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CLOUDP-278384: Support Independent ID config generation #3330

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace github.com/mongodb/mongodb-atlas-kubernetes/v2 v2.4.1 => ../mongodb-atlas-kubernetes
Comment on lines +179 to +180
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for local development, but will not work on the CI, obviously.

This PR needs to wait for the 2.5 release to happen, or at least for the v2.5.0 to exist.

36 changes: 28 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwF
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI=
github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
github.com/aws/aws-sdk-go-v2/config v1.27.43 h1:p33fDDihFC390dhhuv8nOmX419wjOSDQRb+USt20RrU=
Expand Down Expand Up @@ -76,6 +80,10 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 h1:CiS7i0+FUe+/YY1GvIBLLrR/XNGZ
github.com/aws/aws-sdk-go-v2/service/sts v1.32.2/go.mod h1:HtaiBI8CjYoNVde8arShXb94UbQQi9L4EMr6D+xGBwo=
github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM=
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/briandowns/spinner v1.23.1 h1:t5fDPmScwUjozhDj4FA46p5acZWIPXYE30qW2Ptu650=
github.com/briandowns/spinner v1.23.1/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand Down Expand Up @@ -167,6 +175,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand All @@ -189,8 +199,8 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA=
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 h1:SJ+NtwL6QaZ21U+IrK7d0gGgpjGGvd2kz+FzTHVzdqI=
Expand Down Expand Up @@ -258,16 +268,14 @@ github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKk
github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg=
github.com/mongodb-labs/cobra2snooty v0.18.2 h1:qWpLCMWbQb5FSZ5ehiWN2URmieMJhQtQPxT0uhIK62A=
github.com/mongodb-labs/cobra2snooty v0.18.2/go.mod h1:WnzqCFmx4f72Yj9dL/ulBUqcatfURGdKFf8DLT4h7zQ=
github.com/mongodb/mongodb-atlas-kubernetes/v2 v2.4.1 h1:EzIRqZ6yXX1U0gQBJJF6LYH5KQksU7k7wOVv/vtPoXg=
github.com/mongodb/mongodb-atlas-kubernetes/v2 v2.4.1/go.mod h1:hb8r0m7WRoSeKVX4yMKMxbVpgu/xlDqPUKTQoytG1mQ=
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.19.1 h1:QXgq3Z8Crl5EL1WBAC98A5sEBHARrAJNzAmMxzLcRF0=
github.com/onsi/ginkgo/v2 v2.19.1/go.mod h1:O3DtEWQkPa/F7fBMgmZQKKsluAy8pd3rEQdrjkPb9zA=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand All @@ -281,7 +289,15 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand All @@ -305,6 +321,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down Expand Up @@ -526,6 +544,8 @@ k8s.io/apiserver v0.31.1 h1:Sars5ejQDCRBY5f7R3QFHdqN3s61nhkpaX8/k1iEw1c=
k8s.io/apiserver v0.31.1/go.mod h1:lzDhpeToamVZJmmFlaLwdYZwd7zB+WYRYIboqA1kGxM=
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
k8s.io/component-base v0.31.1 h1:UpOepcrX3rQ3ab5NB6g5iP0tvsgJWzxTyAo20sgYSy8=
k8s.io/component-base v0.31.1/go.mod h1:WGeaw7t/kTsqpVTaCoVEtillbqAhF2/JgvO0LDOMa0w=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand Down
23 changes: 14 additions & 9 deletions internal/cli/kubernetes/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ var ErrUnsupportedOperatorVersionFmt = "version %q is not supported. Supported v
type GenerateOpts struct {
cli.GlobalOpts
cli.OutputOpts
clusterName []string
dataFederationName []string
includeSecrets bool
targetNamespace string
operatorVersion string
store store.OperatorGenericStore
credsStore store.CredentialsGetter
crdsProvider crds.AtlasOperatorCRDProvider
clusterName []string
dataFederationName []string
includeSecrets bool
targetNamespace string
operatorVersion string
store store.OperatorGenericStore
credsStore store.CredentialsGetter
crdsProvider crds.AtlasOperatorCRDProvider
independentResources bool
}

func (opts *GenerateOpts) ValidateTargetNamespace() error {
Expand Down Expand Up @@ -93,6 +94,7 @@ func (opts *GenerateOpts) Run() error {
WithFeatureValidator(atlasCRDs).
WithPatcher(atlasCRDs).
WithDataFederationNames(opts.dataFederationName).
WithIndependentResources(opts.independentResources).
Run()
if err != nil {
return err
Expand All @@ -115,6 +117,9 @@ func GenerateBuilder() *cobra.Command {
Example: `# Export Project, DatabaseUsers, Deployments resources for a specific project without connection and integration secrets:
atlas kubernetes config generate --projectId=<projectId>

# Export Project, DatabaseUsers, Deployments resources for a specific project, but use external IDs where supported:
atlas kubernetes config generate --projectId=<projectId> --independentResources

# Export Project, DatabaseUsers, Deployments resources for a specific project including connection and integration secrets:
atlas kubernetes config generate --projectId=<projectId> --includeSecrets

Expand Down Expand Up @@ -149,6 +154,6 @@ func GenerateBuilder() *cobra.Command {
cmd.Flags().StringVar(&opts.targetNamespace, flag.OperatorTargetNamespace, "", usage.OperatorTargetNamespace)
cmd.Flags().StringVar(&opts.operatorVersion, flag.OperatorVersion, features.LatestOperatorMajorVersion, usage.OperatorVersion)
cmd.Flags().StringSliceVar(&opts.dataFederationName, flag.DataFederationName, []string{}, usage.ExporterDataFederationName)

cmd.Flags().BoolVar(&opts.independentResources, flag.IndependentResources, false, usage.IndependentResources)
return cmd
}
1 change: 1 addition & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,5 @@ const (
IdentityProviderID = "identityProviderId" // IdentityProviderId flag
AuditAuthorizationSuccess = "auditAuthorizationSuccess" // AuditAuthorizationSuccess flag
AuditFilter = "auditFilter" // AuditFilter flag
IndependentResources = "independentResources" // IndependentResources flag
)
30 changes: 27 additions & 3 deletions internal/kubernetes/operator/config_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/resources"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/streamsprocessing"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
"go.mongodb.org/atlas-sdk/v20240805004/admin"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
Expand All @@ -40,6 +41,8 @@ const (
maxClusters = 500
DefaultClustersCount = 10
InactiveStatus = "INACTIVE"

credentialSuffix = "-credentials"
)

type ConfigExporter struct {
Expand All @@ -55,6 +58,7 @@ type ConfigExporter struct {
dictionaryForAtlasNames map[string]string
dataFederationNames []string
patcher Patcher
independentResources bool
}

type Patcher interface {
Expand Down Expand Up @@ -115,6 +119,11 @@ func (e *ConfigExporter) WithPatcher(p Patcher) *ConfigExporter {
return e
}

func (e *ConfigExporter) WithIndependentResources(enabled bool) *ConfigExporter {
e.independentResources = enabled
return e
}

func (e *ConfigExporter) Run() (string, error) {
// TODO: Add REST to OPERATOR entities matcher
output := bytes.NewBufferString(yamlSeparator)
Expand Down Expand Up @@ -158,6 +167,7 @@ func (e *ConfigExporter) Run() (string, error) {
r = append(r, streamProcessingResources...)

for _, res := range r {
res = filterResource(res, e.independentResources, projectName+credentialSuffix)
if e.patcher != nil {
err = e.patcher.Patch(res)
if err != nil {
Expand Down Expand Up @@ -215,9 +225,9 @@ func (e *ConfigExporter) exportProject() ([]runtime.Object, string, error) {
}

// Project secret with credentials
r = append(r, project.BuildProjectConnectionSecret(
r = append(r, project.BuildProjectNamedConnectionSecret(
e.credsProvider,
projectData.Project.Name,
projectData.Project.Name+credentialSuffix,
projectData.Project.Namespace,
e.orgID,
e.includeSecretsData,
Expand Down Expand Up @@ -417,9 +427,12 @@ func (e *ConfigExporter) exportAtlasFederatedAuth(projectName string) ([]runtime
// Gets the FederationAuthSetting
federatedAuthentificationSetting, err := e.dataProvider.FederationSetting(&admin.GetFederationSettingsApiParams{OrgId: e.orgID})
if err != nil {
if admin.IsErrorCode(err, "RESOURCE_NOT_FOUND") {
return nil, nil
}
return nil, fmt.Errorf("failed to retrieve federation settings: %w", err)
}
// Does not have an IdenityProvider set then no need to generate
// Does not have an IdentityProvider set then no need to generate
if !federatedAuthentificationSetting.HasIdentityProviderStatus() || federatedAuthentificationSetting.GetIdentityProviderStatus() == InactiveStatus {
return nil, nil
}
Expand All @@ -443,3 +456,14 @@ func (e *ConfigExporter) exportAtlasFederatedAuth(projectName string) ([]runtime
}
return append(result, federatedAuthentification), nil
}

func filterResource(obj runtime.Object, independentResource bool, credentials string) runtime.Object {
switch r := obj.(type) {
case *akov2.AtlasDatabaseUser:
return dbusers.FixReference(r, independentResource, credentials)
case *akov2.AtlasDeployment:
return deployment.FixReference(r, independentResource, credentials)
default:
return obj
}
}
17 changes: 16 additions & 1 deletion internal/kubernetes/operator/dbusers/dbusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ func BuildDBUsers(provider store.OperatorDBUsersStore, projectID, projectName, t
},
},
Spec: akov2.AtlasDatabaseUserSpec{
Project: akov2common.ResourceRefNamespaced{
Project: &akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(projectName, dictionary),
Namespace: targetNamespace,
},
ExternalProjectRef: &akov2.ExternalProjectReference{
ID: projectID,
},
DatabaseName: user.DatabaseName,
DeleteAfterDate: getDeleteAfterDate(user),
Labels: labels,
Expand Down Expand Up @@ -177,3 +180,15 @@ func suggestResourceName(

return resourceName
}

func FixReference(dbUser *akov2.AtlasDatabaseUser, independentResource bool, credentials string) *akov2.AtlasDatabaseUser {
if independentResource {
dbUser.Spec.Project = nil
dbUser.Spec.ConnectionSecret = &akoapi.LocalObjectReference{
Name: credentials,
}
return dbUser
}
dbUser.Spec.ExternalProjectRef = nil
return dbUser
}
6 changes: 4 additions & 2 deletions internal/kubernetes/operator/dbusers/dbusers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func Test_buildUserSecret(t *testing.T) {
projectName := "TestProject-1"
projectID := "123"
atlasUser := &atlasv2.CloudDatabaseUser{
Password: pointer.Get("TestPassword"),
Username: "TestName",
}

Expand Down Expand Up @@ -194,10 +193,13 @@ func TestBuildDBUsers(t *testing.T) {
},
},
Spec: akov2.AtlasDatabaseUserSpec{
Project: akov2common.ResourceRefNamespaced{
Project: &akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(projectName, dictionary),
Namespace: targetNamespace,
},
ExternalProjectRef: &akov2.ExternalProjectReference{
ID: projectID,
},
DatabaseName: user.DatabaseName,
DeleteAfterDate: user.DeleteAfterDate.Format(timeFormatISO8601),
Labels: []akov2common.LabelSpec{
Expand Down
19 changes: 17 additions & 2 deletions internal/kubernetes/operator/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
akoapi "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api"
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common"
akov2provider "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/provider"

Check failure on line 28 in internal/kubernetes/operator/deployment/deployment.go

View workflow job for this annotation

GitHub Actions / docs

github.com/mongodb/mongodb-atlas-kubernetes/[email protected]: replacement directory ../mongodb-atlas-kubernetes does not exist

Check failure on line 28 in internal/kubernetes/operator/deployment/deployment.go

View workflow job for this annotation

GitHub Actions / unit-tests (ubuntu-latest)

github.com/mongodb/mongodb-atlas-kubernetes/[email protected]: replacement directory ../mongodb-atlas-kubernetes does not exist

Check failure on line 28 in internal/kubernetes/operator/deployment/deployment.go

View workflow job for this annotation

GitHub Actions / unit-tests (windows-latest)

github.com/mongodb/mongodb-atlas-kubernetes/[email protected]: replacement directory ../mongodb-atlas-kubernetes does not exist

Check failure on line 28 in internal/kubernetes/operator/deployment/deployment.go

View workflow job for this annotation

GitHub Actions / unit-tests (macos-latest)

github.com/mongodb/mongodb-atlas-kubernetes/[email protected]: replacement directory ../mongodb-atlas-kubernetes does not exist
akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status"
atlasClustersPinned "go.mongodb.org/atlas-sdk/v20240530005/admin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -124,10 +124,13 @@
},
},
Spec: akov2.AtlasDeploymentSpec{
Project: akov2common.ResourceRefNamespaced{
Project: &akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(projectName, dictionary),
Namespace: targetNamespace,
},
ExternalProjectRef: &akov2.ExternalProjectReference{
ID: projectID,
},
DeploymentSpec: advancedSpec,
ServerlessSpec: nil,
ProcessArgs: nil,
Expand Down Expand Up @@ -490,7 +493,7 @@
},
},
Spec: akov2.AtlasDeploymentSpec{
Project: akov2common.ResourceRefNamespaced{
Project: &akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(projectName, dictionary),
Namespace: targetNamespace,
},
Expand Down Expand Up @@ -544,3 +547,15 @@
}
return result, nil
}

func FixReference(deployment *akov2.AtlasDeployment, independentResource bool, credentials string) *akov2.AtlasDeployment {
if independentResource {
deployment.Spec.Project = nil
deployment.Spec.ConnectionSecret = &akoapi.LocalObjectReference{
Name: credentials,
}
return deployment
}
deployment.Spec.ExternalProjectRef = nil
return deployment
}
Loading
Loading