From 2136a7e83b3829d22d3f06a5f636760ecd8b1d4e Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Tue, 12 Nov 2024 12:12:06 +0530 Subject: [PATCH] storageclusterpeers: fix the peering since we always set the state to failed, from the server it never returns a valid response. Removed Failed state when we need to requeue Signed-off-by: Rewant Soni --- .../storageclusterpeer_controller.go | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/controllers/storageclusterpeer/storageclusterpeer_controller.go b/controllers/storageclusterpeer/storageclusterpeer_controller.go index 35ae24e826..431eeb10b6 100644 --- a/controllers/storageclusterpeer/storageclusterpeer_controller.go +++ b/controllers/storageclusterpeer/storageclusterpeer_controller.go @@ -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 } @@ -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 } @@ -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() @@ -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 + storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateFailed return ctrl.Result{}, nil } - storageClusterPeer.Status.State = ocsv1.ReconcileFailed - } else { - storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStatePeered + return ctrl.Result{}, err } + + storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStatePeered return ctrl.Result{}, nil }