Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22405a7

Browse files
authoredDec 30, 2021
Add private endpoint for AWS (#355)
* Add PE Service Creator * Add endpoint clean up * Fix status update * Use statuses to track PEs state * Fix project deletion * Fix status conversion for AZURE * Refactor the code changes * Enable private link tests * Apply a fix from Svetlana * fixup! Refactor the code changes
1 parent 7131b3f commit 22405a7

File tree

12 files changed

+361
-12
lines changed

12 files changed

+361
-12
lines changed
 

‎.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
"helm-wide",
146146
"helm-update",
147147
"multinamespaced",
148-
# "privatelink-aws",
148+
"privatelink-aws",
149149
]
150150
include:
151151
- k8s: "latest-openshift"

‎pkg/api/v1/project/privateendpoint.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ func (i PrivateEndpoint) ToAtlas() (*mongodbatlas.PrivateEndpoint, error) {
2727
err := compat.JSONCopy(result, i)
2828
return result, err
2929
}
30+
31+
// Identifier is required to satisfy "Identifiable" iterface
32+
func (i PrivateEndpoint) Identifier() interface{} {
33+
return string(i.Provider) + i.Region
34+
}

‎pkg/api/v1/status/atlascluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ type Endpoint struct {
8282

8383
// Region to which you deployed the private endpoint.
8484
Region string `json:"region,omitempty"`
85+
86+
// Private IP address of the private endpoint network interface you created in your Azure VNet.
87+
// +optional
88+
IP string `json:"ip,omitempty"`
8589
}
8690

8791
// +k8s:deepcopy-gen=false

‎pkg/api/v1/status/atlasproject.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package status
22

3-
import "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/project"
3+
import (
4+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/project"
5+
)
46

57
// +k8s:deepcopy-gen=false
68

@@ -19,6 +21,43 @@ func AtlasProjectExpiredIPAccessOption(lists []project.IPAccessList) AtlasProjec
1921
}
2022
}
2123

24+
func AtlasProjectAddPrivateEnpointsOption(privateEndpoints []ProjectPrivateEndpoint) AtlasProjectStatusOption {
25+
return func(s *AtlasProjectStatus) {
26+
s.PrivateEndpoints = append(s.PrivateEndpoints, privateEndpoints...)
27+
}
28+
}
29+
30+
func AtlasProjectUpdatePrivateEnpointsOption(privateEndpoints []ProjectPrivateEndpoint) AtlasProjectStatusOption {
31+
return func(s *AtlasProjectStatus) {
32+
result := []ProjectPrivateEndpoint{}
33+
34+
for _, currentPE := range privateEndpoints {
35+
var matchedPE *ProjectPrivateEndpoint
36+
for peIdx, statusPE := range s.PrivateEndpoints {
37+
if currentPE.ID == statusPE.ID {
38+
if currentPE.ServiceName != "" {
39+
s.PrivateEndpoints[peIdx].ServiceName = currentPE.ServiceName
40+
}
41+
if currentPE.ServiceResourceID != "" {
42+
s.PrivateEndpoints[peIdx].ServiceResourceID = currentPE.ServiceResourceID
43+
}
44+
if currentPE.InterfaceEndpointID != "" {
45+
s.PrivateEndpoints[peIdx].InterfaceEndpointID = currentPE.InterfaceEndpointID
46+
}
47+
48+
matchedPE = &s.PrivateEndpoints[peIdx]
49+
}
50+
}
51+
52+
if matchedPE != nil {
53+
result = append(result, *matchedPE)
54+
}
55+
}
56+
57+
s.PrivateEndpoints = result
58+
}
59+
}
60+
2261
// AtlasProjectStatus defines the observed state of AtlasProject
2362
type AtlasProjectStatus struct {
2463
Common `json:",inline"`

‎pkg/api/v1/status/condition.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ const (
3333

3434
// AtlasProject condition types
3535
const (
36-
ProjectReadyType ConditionType = "ProjectReady"
37-
IPAccessListReadyType ConditionType = "IPAccessListReady"
36+
ProjectReadyType ConditionType = "ProjectReady"
37+
IPAccessListReadyType ConditionType = "IPAccessListReady"
38+
PrivateEndpointServiceReadyType ConditionType = "PrivateEndpointServiceReady"
39+
PrivateEndpointReadyType ConditionType = "PrivateEndpointReady"
3840
)
3941

4042
// AtlasCluster condition types

‎pkg/api/v1/status/privateendpoint.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ package status
33
import "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider"
44

55
type ProjectPrivateEndpoint struct {
6+
// Unique identifier for AWS or AZURE Private Link Connection.
7+
ID string `json:"id,omitempty"`
68
// Cloud provider for which you want to retrieve a private endpoint service. Atlas accepts AWS or AZURE.
79
Provider provider.ProviderName `json:"provider"`
810
// Cloud provider region for which you want to create the private endpoint service.
911
Region string `json:"region"`
1012
// Name of the AWS or Azure Private Link Service that Atlas manages.
1113
ServiceName string `json:"serviceName,omitempty"`
12-
// Unique identifier of the AWS or Azure PrivateLink connection.
14+
// Unique identifier of the Azure Private Link Service (for AWS the same as ID).
1315
ServiceResourceID string `json:"serviceResourceId,omitempty"`
16+
// Unique identifier of the AWS or Azure Private Link Interface Endpoint.
17+
InterfaceEndpointID string `json:"interfaceEndpointId,omitempty"`
18+
}
19+
20+
func (pe ProjectPrivateEndpoint) Identifier() interface{} {
21+
return string(pe.Provider) + pe.Region
1422
}

‎pkg/api/v1/status/zz_generated.deepcopy.go

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

‎pkg/api/v1/zz_generated.deepcopy.go

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

‎pkg/controller/atlasproject/atlasproject_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ func (r *AtlasProjectReconciler) Reconcile(context context.Context, req ctrl.Req
128128
return result.ReconcileResult(), nil
129129
}
130130

131+
if result = DeleteAllPrivateEndpoints(ctx, atlasClient, projectID, project.Status.PrivateEndpoints, log); !result.IsOk() {
132+
ctx.SetConditionFromResult(status.PrivateEndpointReadyType, result)
133+
return result.ReconcileResult(), nil
134+
}
135+
131136
if err = r.deleteAtlasProject(context, atlasClient, project); err != nil {
132137
result = workflow.Terminate(workflow.Internal, err.Error())
133138
ctx.SetConditionFromResult(status.ClusterReadyType, result)
@@ -155,6 +160,11 @@ func (r *AtlasProjectReconciler) Reconcile(context context.Context, req ctrl.Req
155160
ctx.SetConditionTrue(status.IPAccessListReadyType)
156161
r.EventRecorder.Event(project, "Normal", string(status.IPAccessListReadyType), "")
157162

163+
if result = r.ensurePrivateEndpoint(ctx, projectID, project); !result.IsOk() {
164+
return result.ReconcileResult(), nil
165+
}
166+
r.EventRecorder.Event(project, "Normal", string(status.PrivateEndpointReadyType), "")
167+
158168
ctx.SetConditionTrue(status.ReadyType)
159169
return ctrl.Result{}, nil
160170
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.