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

Single primary cluster file per cluster #2229

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions controllers/bounce_processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func (c bounceProcesses) reconcile(_ context.Context, r *FoundationDBClusterReco
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/change_coordinators.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ func (c changeCoordinators) reconcile(ctx context.Context, r *FoundationDBCluste
if err != nil {
return &requeue{curError: err, delayedRequeue: true}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/check_client_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ func (c checkClientCompatibility) reconcile(_ context.Context, r *FoundationDBCl
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/choose_removals.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ func (c chooseRemovals) reconcile(ctx context.Context, r *FoundationDBClusterRec
if err != nil {
return &requeue{curError: err, delayedRequeue: true}
}
defer func() {
_ = adminClient.Close()
}()

status, err = adminClient.GetStatus()
if err != nil {
Expand Down
35 changes: 9 additions & 26 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ func (r *FoundationDBClusterReconciler) Reconcile(ctx context.Context, request c
if err != nil {
return ctrl.Result{}, err
}
defer func() {
_ = adminClient.Close()
}()

err = cluster.Validate()
if err != nil {
Expand Down Expand Up @@ -556,17 +553,17 @@ func (r *FoundationDBClusterReconciler) updateOrApply(ctx context.Context, clust
// getStatusFromClusterOrDummyStatus will fetch the machine-readable status from the FoundationDBCluster if the cluster is configured. If not a default status is returned indicating, that
// some configuration is missing.
func (r *FoundationDBClusterReconciler) getStatusFromClusterOrDummyStatus(logger logr.Logger, cluster *fdbv1beta2.FoundationDBCluster) (*fdbv1beta2.FoundationDBStatus, error) {
if cluster.Status.ConnectionString == "" {
return &fdbv1beta2.FoundationDBStatus{
Cluster: fdbv1beta2.FoundationDBStatusClusterInfo{
Layers: fdbv1beta2.FoundationDBStatusLayerInfo{
Error: "configurationMissing",
},
},
}, nil
adminClient, err := r.getAdminClient(logger, cluster)
if err != nil {
return nil, err
}
// If the cluster is not yet configured, we can reduce the timeout to make sure the initial reconcile steps
// are faster.
if !cluster.Status.Configured {
adminClient.SetTimeout(10 * time.Second)
}

connectionString, err := tryConnectionOptions(logger, cluster, r)
connectionString, err := adminClient.GetConnectionString()
if err != nil {
return nil, err
}
Expand All @@ -579,20 +576,6 @@ func (r *FoundationDBClusterReconciler) getStatusFromClusterOrDummyStatus(logger
cluster.Status.ConnectionString = connectionString
}

adminClient, err := r.getAdminClient(logger, cluster)
if err != nil {
return nil, err
}
defer func() {
_ = adminClient.Close()
}()

// If the cluster is not yet configured, we can reduce the timeout to make sure the initial reconcile steps
// are faster.
if !cluster.Status.Configured {
adminClient.SetTimeout(10 * time.Second)
}

status, err := adminClient.GetStatus()
if err == nil {
return status, nil
Expand Down
3 changes: 0 additions & 3 deletions controllers/exclude_processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ func (e excludeProcesses) reconcile(ctx context.Context, r *FoundationDBClusterR
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

adminClient.WithValues()
// If the status is not cached, we have to fetch it.
Expand Down
3 changes: 0 additions & 3 deletions controllers/modify_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func (s modifyBackup) reconcile(ctx context.Context, r *FoundationDBBackupReconc
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

err = adminClient.ModifyBackup(snapshotPeriod)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/remove_incompatible_processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func processIncompatibleProcesses(ctx context.Context, r *FoundationDBClusterRec
if err != nil {
return err
}
defer func() {
_ = adminClient.Close()
}()

status, err = adminClient.GetStatus()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/remove_process_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func (u removeProcessGroups) reconcile(ctx context.Context, r *FoundationDBClust
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/replace_failed_process_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func (c replaceFailedProcessGroups) reconcile(ctx context.Context, r *Foundation
if err != nil {
return &requeue{curError: err, delayedRequeue: true}
}
defer func() {
_ = adminClient.Close()
}()

status, err = adminClient.GetStatus()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/start_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func (s startBackup) reconcile(ctx context.Context, r *FoundationDBBackupReconci
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

err = adminClient.StartBackup(backup.BackupURL(), backup.SnapshotPeriodSeconds())
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/start_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (s startRestore) reconcile(ctx context.Context, r *FoundationDBRestoreRecon
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

status, err := adminClient.GetRestoreStatus()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/stop_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func (s stopBackup) reconcile(ctx context.Context, r *FoundationDBBackupReconcil
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

err = adminClient.StopBackup(backup.BackupURL())
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions controllers/toggle_backup_paused.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func (s toggleBackupPaused) reconcile(ctx context.Context, r *FoundationDBBackup
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

err = adminClient.PauseBackups()
if err != nil {
Expand All @@ -58,9 +55,6 @@ func (s toggleBackupPaused) reconcile(ctx context.Context, r *FoundationDBBackup
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

err = adminClient.ResumeBackups()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/update_backup_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ func (s updateBackupStatus) reconcile(ctx context.Context, r *FoundationDBBackup
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

liveStatus, err := adminClient.GetBackupStatus()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/update_database_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func (u updateDatabaseConfiguration) reconcile(_ context.Context, r *FoundationD
if err != nil {
return &requeue{curError: err, delayedRequeue: true}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/update_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ func (u updatePods) reconcile(ctx context.Context, r *FoundationDBClusterReconci
if err != nil {
return &requeue{curError: err, delayedRequeue: true}
}
defer func() {
_ = adminClient.Close()
}()

// If the status is not cached, we have to fetch it.
if status == nil {
Expand Down
3 changes: 0 additions & 3 deletions controllers/update_restore_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func (updateRestoreStatus) reconcile(ctx context.Context, r *FoundationDBRestore
if err != nil {
return &requeue{curError: err}
}
defer func() {
_ = adminClient.Close()
}()

status, err := adminClient.GetRestoreStatus()
if err != nil {
Expand Down
55 changes: 0 additions & 55 deletions controllers/update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,61 +277,6 @@ func containsAll(current map[string]string, desired map[string]string) bool {
return true
}

// optionList creates an order-preserved unique list
func optionList(options ...string) []string {
valueMap := make(map[string]bool, len(options))
values := make([]string, 0, len(options))
for _, option := range options {
if option != "" && !valueMap[option] {
values = append(values, option)
valueMap[option] = true
}
}
return values
}

// tryConnectionOptions attempts to connect with all the connection strings for this cluster and
// returns the connection string that allows connecting to the cluster.
func tryConnectionOptions(logger logr.Logger, cluster *fdbv1beta2.FoundationDBCluster, r *FoundationDBClusterReconciler) (string, error) {
connectionStrings := optionList(cluster.Status.ConnectionString, cluster.Spec.SeedConnectionString)
logger.Info("Trying connection options", "connectionString", connectionStrings)

originalConnectionString := cluster.Status.ConnectionString
defer func() { cluster.Status.ConnectionString = originalConnectionString }()

var err error
for _, connectionString := range connectionStrings {
logger.Info("Attempting to get connection string from cluster", "connectionString", connectionString)
cluster.Status.ConnectionString = connectionString
adminClient, clientErr := r.getAdminClient(logger, cluster)
if clientErr != nil {
return originalConnectionString, clientErr
}

// If the cluster is not yet configured, we can reduce the timeout to make sure the initial reconcile steps
// are faster.
if !cluster.Status.Configured {
adminClient.SetTimeout(10 * time.Second)
}

var activeConnectionString string
activeConnectionString, err = adminClient.GetConnectionString()

closeErr := adminClient.Close()
if closeErr != nil {
logger.V(1).Info("Could not close admin client", "error", closeErr)
}

if err == nil {
logger.Info("Chose connection option", "connectionString", activeConnectionString)
return activeConnectionString, nil
}
logger.Error(err, "Error getting connection string from cluster", "connectionString", connectionString)
}

return originalConnectionString, nil
}

// checkAndSetProcessStatus checks the status of the Process and if missing or incorrect add it to the related status field
func checkAndSetProcessStatus(logger logr.Logger, r *FoundationDBClusterReconciler, cluster *fdbv1beta2.FoundationDBCluster, pod *corev1.Pod, processMap map[fdbv1beta2.ProcessGroupID][]fdbv1beta2.FoundationDBStatusProcessInfo, processCount int, processGroupStatus *fdbv1beta2.ProcessGroupStatus) error {
// Only perform any process specific validation if the machine-readable status has at least one process. We can improve this check
Expand Down
1 change: 0 additions & 1 deletion docs/design/better_coordination_multi_operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func (reconciler operatorCoordination) reconcile(ctx context.Context, r *Foundat
if err != nil {
return &requeue{curError: err}
}
defer adminClient.Close()

// Read all data from the lists to get the current state. If a prefix is provided to the get methods, only
// process groups with the additional sub path will be returned.
Expand Down
Loading