Skip to content

Commit

Permalink
refactor reconciliation flow to avoid unneeded recreation
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs committed Sep 7, 2023
1 parent 76c4b1f commit 4825e63
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 214 deletions.
33 changes: 33 additions & 0 deletions pkg/controller/atlas/ip_access_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package atlas

import (
"context"
"fmt"
"net/http"

"go.mongodb.org/atlas/mongodbatlas"
)

type IPAccessListStatus func(ctx context.Context, projectID, entryValue string) (string, error)

func CustomIPAccessListStatus(client *mongodbatlas.Client) IPAccessListStatus {
type ipAccessListStatus struct {
Status string `json:"STATUS"`
}

return func(ctx context.Context, projectID, entryValue string) (string, error) {
urlStr := fmt.Sprintf("/api/atlas/v1.0/groups/%s/accessList/%s/status", projectID, entryValue)
req, err := client.NewRequest(context.Background(), http.MethodGet, urlStr, nil)
if err != nil {
return "", err
}

status := ipAccessListStatus{}
_, err = client.Do(context.Background(), req, &status)
if err != nil {
return "", err
}

return status.Status, nil
}
}
2 changes: 1 addition & 1 deletion pkg/controller/atlasproject/atlasproject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (r *AtlasProjectReconciler) ensureProjectResources(ctx context.Context, wor
}

var result workflow.Result
if result = ensureIPAccessList(ctx, workflowCtx, project, r.SubObjectDeletionProtection); result.IsOk() {
if result = ensureIPAccessList(ctx, workflowCtx, atlas.CustomIPAccessListStatus(&workflowCtx.Client), project, r.SubObjectDeletionProtection); result.IsOk() {
r.EventRecorder.Event(project, "Normal", string(status.IPAccessListReadyType), "")
}
results = append(results, result)
Expand Down
Loading

0 comments on commit 4825e63

Please sign in to comment.