Skip to content

CLOUDP-297918: Move to New Atlas SDK #2304

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

Draft
wants to merge 19 commits into
base: main
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
29 changes: 14 additions & 15 deletions api/v1/alert_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strconv"
"strings"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
"go.uber.org/zap"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
Expand Down Expand Up @@ -61,14 +61,14 @@ func (in *AlertConfiguration) ToAtlas() (*admin.GroupAlertsConfig, error) {
result.SetEnabled(in.Enabled)
result.SetEventTypeName(in.EventTypeName)

matchers := make([]map[string]interface{}, 0, len(in.Matchers))
matchers := make([]admin.StreamsMatcher, 0, len(in.Matchers))
for _, m := range in.Matchers {
matchers = append(
matchers,
map[string]interface{}{
"fieldName": m.FieldName,
"operator": m.Operator,
"value": m.Value,
admin.StreamsMatcher{
FieldName: m.FieldName,
Operator: m.Operator,
Value: m.Value,
},
)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func (in Threshold) Key() string {
return in.Operator + "|" + in.Units + "|" + in.Threshold
}

func (in *Threshold) IsEqual(threshold *admin.GreaterThanRawThreshold) bool {
func (in *Threshold) IsEqual(threshold *admin.StreamProcessorMetricThreshold) bool {
logger := zap.NewExample().Sugar()
if in == nil {
return threshold == nil
Expand All @@ -161,21 +161,20 @@ func (in *Threshold) IsEqual(threshold *admin.GreaterThanRawThreshold) bool {
return true
}

func (in *Threshold) ToAtlas() (*admin.GreaterThanRawThreshold, error) {
func (in *Threshold) ToAtlas() (*admin.StreamProcessorMetricThreshold, error) {
if in == nil {
return nil, nil
}

tr64, err := strconv.ParseInt(in.Threshold, 10, 64)
tr64, err := strconv.ParseFloat(in.Threshold, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse threshold value: %w. should be float", err)
}

tr := int(tr64)
result := &admin.GreaterThanRawThreshold{
result := &admin.StreamProcessorMetricThreshold{
Operator: &in.Operator,
Units: &in.Units,
Threshold: &tr,
Threshold: &tr64,
}

return result, nil
Expand Down Expand Up @@ -367,7 +366,7 @@ func (in MetricThreshold) Key() string {
in.Mode
}

func (in *MetricThreshold) IsEqual(threshold *admin.ServerlessMetricThreshold) bool {
func (in *MetricThreshold) IsEqual(threshold *admin.FlexClusterMetricThreshold) bool {
if in == nil {
return threshold == nil
}
Expand All @@ -388,7 +387,7 @@ func (in *MetricThreshold) IsEqual(threshold *admin.ServerlessMetricThreshold) b
in.Mode == threshold.GetMode()
}

func (in *MetricThreshold) ToAtlas() (*admin.ServerlessMetricThreshold, error) {
func (in *MetricThreshold) ToAtlas() (*admin.FlexClusterMetricThreshold, error) {
if in == nil {
return nil, nil
}
Expand All @@ -398,7 +397,7 @@ func (in *MetricThreshold) ToAtlas() (*admin.ServerlessMetricThreshold, error) {
return nil, fmt.Errorf("failed to parse threshold value: %w. should be float", err)
}

result := &admin.ServerlessMetricThreshold{
result := &admin.FlexClusterMetricThreshold{
MetricName: in.MetricName,
Operator: &in.Operator,
Threshold: &tr,
Expand Down
14 changes: 7 additions & 7 deletions api/v1/alert_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
)
Expand All @@ -27,12 +27,12 @@ func TestServerlessMetricThreshold(t *testing.T) {
tests := []struct {
name string
akoData *MetricThreshold
atlasData *admin.ServerlessMetricThreshold
atlasData *admin.FlexClusterMetricThreshold
equal bool
}{
{
name: "Should be able to parse float Theshold",
atlasData: &admin.ServerlessMetricThreshold{
atlasData: &admin.FlexClusterMetricThreshold{
MetricName: "test",
Mode: pointer.MakePtr("test"),
Operator: pointer.MakePtr("IN"),
Expand All @@ -50,7 +50,7 @@ func TestServerlessMetricThreshold(t *testing.T) {
},
{
name: "Should be able to parse int Theshold",
atlasData: &admin.ServerlessMetricThreshold{
atlasData: &admin.FlexClusterMetricThreshold{
MetricName: "test",
Mode: pointer.MakePtr("test"),
Operator: pointer.MakePtr("IN"),
Expand All @@ -68,7 +68,7 @@ func TestServerlessMetricThreshold(t *testing.T) {
},
{
name: "Should be false if Theshold is not a number",
atlasData: &admin.ServerlessMetricThreshold{
atlasData: &admin.FlexClusterMetricThreshold{
MetricName: "test",
Mode: pointer.MakePtr("test"),
Operator: pointer.MakePtr("IN"),
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestServerlessMetricThreshold(t *testing.T) {
},
{
name: "Should be false if operator mismatched",
atlasData: &admin.ServerlessMetricThreshold{
atlasData: &admin.FlexClusterMetricThreshold{
MetricName: "test",
Mode: pointer.MakePtr("test"),
Operator: pointer.MakePtr("IN"),
Expand All @@ -116,7 +116,7 @@ func TestServerlessMetricThreshold(t *testing.T) {
},
{
name: "Should fail if Threshold mismatched",
atlasData: &admin.ServerlessMetricThreshold{
atlasData: &admin.FlexClusterMetricThreshold{
MetricName: "test",
Mode: pointer.MakePtr("test"),
Operator: pointer.MakePtr("IN"),
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasbackupcompliancepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package v1
import (
"strings"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasbackupcompliancepolicy_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasdatabaseuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"fmt"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package v1
import (
"errors"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
"go.mongodb.org/atlas/mongodbatlas"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasfederatedauth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"
"fmt"

"go.mongodb.org/atlas-sdk/v20241113001/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasfederatedauth_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/go-test/deep"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"go.mongodb.org/atlas-sdk/v20241113001/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasproject_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/atlas-sdk/v20231115004/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
"sigs.k8s.io/yaml"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/atlasteam_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/networkpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/provider"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/compat"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/privateendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/provider"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/status"
Expand Down
2 changes: 1 addition & 1 deletion api/v1/project_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
)

type ProjectSettings struct {
Expand Down
2 changes: 1 addition & 1 deletion api/v1/project_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
)
Expand Down
6 changes: 3 additions & 3 deletions api/v1/status/alert_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"strconv"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
"go.uber.org/zap"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/compat"
Expand Down Expand Up @@ -160,7 +160,7 @@ type Threshold struct {
Threshold string `json:"threshold,omitempty"`
}

func ThresholdFromAtlas(threshold *admin.GreaterThanRawThreshold) *Threshold {
func ThresholdFromAtlas(threshold *admin.StreamProcessorMetricThreshold) *Threshold {
if threshold == nil {
return nil
}
Expand All @@ -185,7 +185,7 @@ type MetricThreshold struct {
Mode string `json:"mode,omitempty"`
}

func MetricThresholdFromAtlas(threshold *admin.ServerlessMetricThreshold) *MetricThreshold {
func MetricThresholdFromAtlas(threshold *admin.FlexClusterMetricThreshold) *MetricThreshold {
if threshold == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/status/networkpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package status

import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/provider"
)
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ require (
github.com/sethvargo/go-password v0.3.1
github.com/stretchr/testify v1.10.0
go.mongodb.org/atlas v0.38.0
go.mongodb.org/atlas-sdk/v20231115004 v20231115004.1.0
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
go.mongodb.org/mongo-driver v1.17.3
go.uber.org/zap v1.27.0
golang.org/x/sync v0.13.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/atlas v0.38.0 h1:zfwymq20GqivGwxPZfypfUDry+WwMGVui97z1d8V4bU=
go.mongodb.org/atlas v0.38.0/go.mod h1:DJYtM+vsEpPEMSkQzJnFHrT0sP7ev6cseZc/GGjJYG8=
go.mongodb.org/atlas-sdk/v20231115004 v20231115004.1.0 h1:vOvfk8bPedcphaTHIm6p8UB/ZPeVOqJZ7+MmTuI1eGs=
go.mongodb.org/atlas-sdk/v20231115004 v20231115004.1.0/go.mod h1:FzD5DLz+WPB+z3OGgNBjXMPQJjJ7Y+hKn4iupXZuoOc=
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0 h1:OuV1HfIpZUZa4+BKvtrvDlNqnilkCkdHspuZok6KAbM=
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0/go.mod h1:0707RpWIrNFZ6Msy/dwRDCzC5JVDon61JoOqcbfCujg=
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0 h1:G3UZcWwWziGUuaILWp/Gc+jLm1tfu7OUhUOpMWVZSWc=
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0/go.mod h1:fMiUyCacIAm+XwFkJ4j+rJtYLRsGU7hButtgGv+SBU4=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0 h1:KX8PrYp3/PCSxG4NbGLcc3+EsNcfyhcvylGbe/oRlx8=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0/go.mod h1:HHCmHxHPdJRr1bUXlvRIZbm7M4gRujjur1GnjE44YgA=
go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeHxQ=
go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/atlas/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package atlas

import "go.mongodb.org/atlas-sdk/v20231115008/admin"
import "go.mongodb.org/atlas-sdk/v20250312002/admin"

func NewClient(domain, publicKey, privateKey string) (*admin.APIClient, error) {
return admin.NewClient(
Expand Down
25 changes: 7 additions & 18 deletions internal/controller/atlas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"strings"

"github.com/mongodb-forks/digest"
adminv20231115008 "go.mongodb.org/atlas-sdk/v20231115008/admin"
adminv20241113001 "go.mongodb.org/atlas-sdk/v20241113001/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
"go.mongodb.org/atlas/mongodbatlas"
"go.uber.org/zap"

Expand All @@ -47,8 +46,7 @@ type Provider interface {
}

type ClientSet struct {
SdkClient20231115008 *adminv20231115008.APIClient
SdkClient20241113001 *adminv20241113001.APIClient
SdkClient20250312002 *admin.APIClient
}

type ProductionProvider struct {
Expand Down Expand Up @@ -144,25 +142,16 @@ func (p *ProductionProvider) SdkClientSet(ctx context.Context, creds *Credential

httpClient := &http.Client{Transport: transport}

clientv20231115008, err := adminv20231115008.NewClient(
adminv20231115008.UseBaseURL(p.domain),
adminv20231115008.UseHTTPClient(httpClient),
adminv20231115008.UseUserAgent(operatorUserAgent()))
if err != nil {
return nil, err
}

clientv20241113001, err := adminv20241113001.NewClient(
adminv20241113001.UseBaseURL(p.domain),
adminv20241113001.UseHTTPClient(httpClient),
adminv20241113001.UseUserAgent(operatorUserAgent()))
clientv20250312002, err := admin.NewClient(
admin.UseBaseURL(p.domain),
admin.UseHTTPClient(httpClient),
admin.UseUserAgent(operatorUserAgent()))
if err != nil {
return nil, err
}

return &ClientSet{
SdkClient20231115008: clientv20231115008,
SdkClient20241113001: clientv20241113001,
SdkClient20250312002: clientv20250312002,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func (r *AtlasCustomRoleReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if err != nil {
return r.terminate(workflowCtx, atlasCustomRole, api.ProjectCustomRolesReadyType, workflow.AtlasAPIAccessNotConfigured, true, err), nil
}
service := customroles.NewCustomRoles(atlasSdkClientSet.SdkClient20231115008.CustomDatabaseRolesApi)
project, err := r.ResolveProject(ctx, atlasSdkClientSet.SdkClient20231115008, atlasCustomRole)
service := customroles.NewCustomRoles(atlasSdkClientSet.SdkClient20250312002.CustomDatabaseRolesApi)
project, err := r.ResolveProject(ctx, atlasSdkClientSet.SdkClient20250312002, atlasCustomRole)
if err != nil {
return r.terminate(workflowCtx, atlasCustomRole, api.ProjectCustomRolesReadyType, workflow.AtlasAPIAccessNotConfigured, true, err), nil
}
Expand Down
Loading
Loading