Skip to content

Commit

Permalink
Merge pull request #2889 from rewantsoni/scp
Browse files Browse the repository at this point in the history
storageclusterpeers: fix the peering
  • Loading branch information
openshift-merge-bot[bot] authored Nov 14, 2024
2 parents 201c936 + d97ccee commit 3f01d01
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions controllers/storageclusterpeer/storageclusterpeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ func (r *StorageClusterPeerReconciler) reconcileStates(storageClusterPeer *ocsv1
owner := util.FindOwnerRefByKind(storageClusterPeer, "StorageCluster")

if owner == nil {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
return ctrl.Result{}, fmt.Errorf("failed to find StorgeCluster owning the StorageClusterPeer")
}

storageCluster.Name = owner.Name

if err := r.get(storageCluster); client.IgnoreNotFound(err) != nil {
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
r.log.Error(err, "Error fetching StorageCluster for StorageClusterPeer found in the same namespace.")
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
return ctrl.Result{}, err
} else if k8serrors.IsNotFound(err) {
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
r.log.Error(err, "Cannot find a StorageCluster for StorageClusterPeer in the same namespace.")
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
return ctrl.Result{}, nil
}

Expand All @@ -138,20 +138,20 @@ func (r *StorageClusterPeerReconciler) reconcileStates(storageClusterPeer *ocsv1
// Read StorageClusterUID from ticket
ticketArr := strings.Split(string(storageClusterPeer.Spec.OnboardingToken), ".")
if len(ticketArr) != 2 {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
r.log.Error(fmt.Errorf("invalid ticket"), "Invalid onboarding ticket. Does not conform to expected ticket structure")
return ctrl.Result{}, nil
}
message, err := base64.StdEncoding.DecodeString(ticketArr[0])
if err != nil {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
r.log.Error(err, "failed to decode onboarding ticket")
return ctrl.Result{}, nil
}
var ticketData services.OnboardingTicket
err = json.Unmarshal(message, &ticketData)
if err != nil {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
r.log.Error(err, "onboarding ticket message is not a valid JSON.")
return ctrl.Result{}, nil
}
Expand All @@ -162,7 +162,7 @@ func (r *StorageClusterPeerReconciler) reconcileStates(storageClusterPeer *ocsv1

ocsClient, err := providerClient.NewProviderClient(r.ctx, storageClusterPeer.Spec.ApiEndpoint, time.Second*10)
if err != nil {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
return ctrl.Result{}, fmt.Errorf("failed to create a new provider client: %v", err)
}
defer ocsClient.Close()
Expand All @@ -174,18 +174,17 @@ func (r *StorageClusterPeerReconciler) reconcileStates(storageClusterPeer *ocsv1
r.log.Error(err, fmt.Sprintf("failed to Peer Storage Cluster, reason: %v.", err))
st, ok := status.FromError(err)
if !ok {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
r.log.Error(fmt.Errorf("invalid code"), "failed to extract an HTTP status code from error")
return ctrl.Result{}, fmt.Errorf("failed to extract an HTTP status code from error")
}
if st.Code() == codes.InvalidArgument {
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
return ctrl.Result{}, nil
if st.Code() != codes.InvalidArgument {
return ctrl.Result{}, err
}
storageClusterPeer.Status.State = ocsv1.ReconcileFailed
} else {
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStatePeered
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed
return ctrl.Result{}, nil
}

storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStatePeered
return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 3f01d01

Please sign in to comment.