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

CLOUDP-278461: Kubernetes Operator - Fixed Serverless PE export for GCP provider #3333

Merged
merged 4 commits into from
Oct 21, 2024
Merged
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
6 changes: 4 additions & 2 deletions internal/kubernetes/operator/config_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Patcher interface {
}

var (
ErrServerless = errors.New("serverless instance error")
ErrClusterNotFound = errors.New("cluster not found")
ErrNoCloudManagerClusters = errors.New("can not get 'advanced clusters' object")
)
Expand Down Expand Up @@ -282,13 +283,14 @@ func (e *ConfigExporter) exportDeployments(projectName string) ([]runtime.Object
}

// Try serverless cluster next
if serverlessCluster, err := deployment.BuildServerlessDeployments(e.dataProvider, e.featureValidator, e.projectID, projectName, deploymentName, e.targetNamespace, e.dictionaryForAtlasNames, e.operatorVersion); err == nil {
serverlessCluster, err := deployment.BuildServerlessDeployments(e.dataProvider, e.featureValidator, e.projectID, projectName, deploymentName, e.targetNamespace, e.dictionaryForAtlasNames, e.operatorVersion)
if err == nil {
if serverlessCluster != nil {
result = append(result, serverlessCluster)
}
continue
}
return nil, fmt.Errorf("%w: %s(%s)", ErrClusterNotFound, deploymentName, e.projectID)
return nil, fmt.Errorf("%w: %s(%s), e: %w", ErrServerless, deploymentName, e.projectID, err)
}
return result, nil
}
Expand Down
10 changes: 6 additions & 4 deletions internal/kubernetes/operator/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,13 @@ func BuildServerlessDeployments(deploymentStore store.OperatorClusterStore, vali
}

if validator.FeatureExist(features.ResourceAtlasDeployment, featureServerlessPrivateEndpoints) {
privateEndpoints, err := buildServerlessPrivateEndpoints(deploymentStore, projectID, deployment.GetName())
if err != nil {
return nil, err
if deployment.ProviderSettings.BackingProviderName != "GCP" {
privateEndpoints, err := buildServerlessPrivateEndpoints(deploymentStore, projectID, deployment.GetName())
if err != nil {
return nil, err
}
atlasDeployment.Spec.ServerlessSpec.PrivateEndpoints = privateEndpoints
}
atlasDeployment.Spec.ServerlessSpec.PrivateEndpoints = privateEndpoints
}

return atlasDeployment, nil
Expand Down
95 changes: 95 additions & 0 deletions internal/kubernetes/operator/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,101 @@ func TestBuildServerlessDeployments(t *testing.T) {
})
}

func TestBuildServerlessDeploymentsWithGCP(t *testing.T) {
const projectName = "testProject-2-1"
const clusterName = "testCluster-2-1"
const targetNamespace = "test-namespace-2-1"

ctl := gomock.NewController(t)
clusterStore := mocks.NewMockOperatorClusterStore(ctl)
dictionary := resources.AtlasNameToKubernetesName()

featureValidator := mocks.NewMockFeatureValidator(ctl)

t.Run("Can import Serverless deployment", func(t *testing.T) {
speID := "TestPEId-1"
speCloudProviderEndpointID := "TestCloudProviderID-1"
speComment := "TestPEName-1"
spePrivateEndpointIPAddress := ""

spe := []atlasClustersPinned.ServerlessTenantEndpoint{
{
Id: &speID,
CloudProviderEndpointId: &speCloudProviderEndpointID,
Comment: &speComment,
PrivateEndpointIpAddress: &spePrivateEndpointIPAddress,
ProviderName: pointer.Get("AZURE"),
},
}

cluster := &atlasClustersPinned.ServerlessInstanceDescription{
Id: pointer.Get("TestClusterID"),
GroupId: pointer.Get("TestGroupID"),
MongoDBVersion: pointer.Get("5.0"),
Name: pointer.Get(clusterName),
CreateDate: pointer.Get(time.Date(2021, time.January, 1, 0, 0, 0, 0, time.UTC)),
ProviderSettings: atlasClustersPinned.ServerlessProviderSettings{
BackingProviderName: "GCP",
ProviderName: pointer.Get("GCP"),
RegionName: "US_EAST_1",
},
StateName: pointer.Get(""),
ServerlessBackupOptions: nil,
ConnectionStrings: nil,
Links: nil,
}

clusterStore.EXPECT().GetServerlessInstance(projectName, clusterName).Return(cluster, nil)
clusterStore.EXPECT().ServerlessPrivateEndpoints(projectName, clusterName).Return(spe, nil).Times(0)

expected := &akov2.AtlasDeployment{
TypeMeta: metav1.TypeMeta{
Kind: "AtlasDeployment",
APIVersion: "atlas.mongodb.com/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: strings.ToLower(fmt.Sprintf("%s-%s", projectName, clusterName)),
Namespace: targetNamespace,
Labels: map[string]string{
features.ResourceVersion: resourceVersion,
},
},
Spec: akov2.AtlasDeploymentSpec{
Project: akov2common.ResourceRefNamespaced{
Name: strings.ToLower(projectName),
Namespace: targetNamespace,
},
BackupScheduleRef: akov2common.ResourceRefNamespaced{},
ServerlessSpec: &akov2.ServerlessSpec{
Name: cluster.GetName(),
ProviderSettings: &akov2.ServerlessProviderSettingsSpec{
BackingProviderName: cluster.ProviderSettings.BackingProviderName,
ProviderName: akov2provider.ProviderName(cluster.ProviderSettings.GetProviderName()),
RegionName: cluster.ProviderSettings.RegionName,
},
},
ProcessArgs: nil,
},
Status: akov2status.AtlasDeploymentStatus{
Common: akoapi.Common{
Conditions: []akoapi.Condition{},
},
},
}

featureValidator.EXPECT().FeatureExist(features.ResourceAtlasDeployment, featureServerlessPrivateEndpoints).Return(true)

got, err := BuildServerlessDeployments(clusterStore, featureValidator, projectName, projectName, clusterName, targetNamespace, dictionary, resourceVersion)
if err != nil {
t.Fatalf("%v", err)
}

if !reflect.DeepEqual(expected, got) {
t.Fatalf("Serverless deployment mismatch.\r\nexp: %v\r\ngot: %v\r\n", expected, got)
}
})
}

func TestCleanTenantFields(t *testing.T) {
for _, tt := range []struct {
name string
Expand Down