Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adejanovski committed May 6, 2024
1 parent 08537b7 commit 46d4b19
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions controllers/medusa/medusarestorejob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/go-logr/logr"
"github.com/k8ssandra/k8ssandra-operator/pkg/shared"
"net"
"time"
Expand Down Expand Up @@ -122,7 +123,7 @@ func (r *MedusaRestoreJobReconciler) Reconcile(ctx context.Context, req ctrl.Req
// Prepare the restore by placing a mapping file in the Cassandra data volume.
if !request.RestoreJob.Status.RestorePrepared {
restorePrepared := false
if restoreMapping, err := r.prepareRestore(ctx, request); err != nil {
if restoreMapping, err := r.prepareRestore(ctx, request, logger); err != nil {
logger.Error(err, "Failed to prepare restore")
return ctrl.Result{}, err
} else {
Expand Down Expand Up @@ -264,21 +265,18 @@ func (r *MedusaRestoreJobReconciler) podTemplateSpecUpdateComplete(ctx context.C

// prepareRestore prepares the MedusaRestoreMapping for the restore operation.
// It uses the Medusa client to get the host map for the restore operation, using the first pod answering on the backup sidecar port.
func (r *MedusaRestoreJobReconciler) prepareRestore(ctx context.Context, request *medusa.RestoreRequest) (*medusav1alpha1.MedusaRestoreMapping, error) {
func (r *MedusaRestoreJobReconciler) prepareRestore(ctx context.Context, request *medusa.RestoreRequest, logger logr.Logger) (*medusav1alpha1.MedusaRestoreMapping, error) {
pods, err := medusa.GetCassandraDatacenterPods(ctx, request.Datacenter, r, request.Log)
if err != nil {
request.Log.Error(err, "Failed to get datacenter pods")
logger.Error(err, "Failed to get datacenter pods")
return nil, err
}

for _, pod := range pods {
addr := net.JoinHostPort(pod.Status.PodIP, fmt.Sprint(shared.BackupSidecarPort))
if medusaClient, err := r.ClientFactory.NewClient(ctx, addr); err != nil {
request.Log.Error(err, "Failed to create Medusa client", "address", addr)
logger.Error(err, "Failed to create Medusa client", "address", addr)
} else {
if err != nil {
return nil, err
}
restoreHostMap, err := medusa.GetHostMap(request.Datacenter, *request.RestoreJob, medusaClient, ctx)
if err != nil {
return nil, err
Expand Down

0 comments on commit 46d4b19

Please sign in to comment.