Skip to content

Commit

Permalink
issue-581, handling no external IPs or private cluster for PostgreSQL…
Browse files Browse the repository at this point in the history
… users is implemented
  • Loading branch information
DoodgeMatvey committed Oct 2, 2023
1 parent ffc2a11 commit c5b6d46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 0 additions & 2 deletions controllers/clusterresources/postgresqluser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ func (r *PostgreSQLUserReconciler) Reconcile(ctx context.Context, req ctrl.Reque
"User has been created for a cluster. Cluster ID: %s, username: %s",
clusterID, newUsername)

// TODO: Add deletion user finalizers

continue
}

Expand Down
43 changes: 43 additions & 0 deletions controllers/clusters/postgresql_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,49 @@ func (r *PostgreSQLReconciler) handleCreateCluster(
}

if pg.Spec.UserRefs != nil {
nodeList := &k8sCore.NodeList{}

err = r.List(ctx, nodeList, &client.ListOptions{})
if err != nil {
logger.Error(err, "Cannot list all nodes",
"cluster name", pg.Spec.Name,
"clusterID", pg.Status.ID,
)

r.EventRecorder.Eventf(
pg, models.Warning, models.CreationFailed,
"Fetching all nodes is failed. Reason: %v",
err,
)

return models.ReconcileRequeue
}

var externalIPExists bool
for _, node := range nodeList.Items {
for _, nodeAddress := range node.Status.Addresses {
if nodeAddress.Type == k8sCore.NodeExternalIP {
externalIPExists = true
break
}
}
}

if !externalIPExists || pg.Spec.PrivateNetworkCluster {
logger.Error(err, "Cannot create PostgreSQL user, if your cluster is private or has no external ips "+
"you need to configure peering and remove user references from cluster specification",
"cluster name", pg.Spec.Name,
"clusterID", pg.Status.ID,
)

r.EventRecorder.Eventf(
pg, models.Warning, models.CreationFailed,
"Creating PostgreSQL user has been failed. Reason: %v", err,
)

return models.ReconcileRequeue
}

err = r.startUsersCreationJob(pg)
if err != nil {
logger.Error(err, "Failed to start user PostreSQL creation job")
Expand Down

0 comments on commit c5b6d46

Please sign in to comment.