-
Notifications
You must be signed in to change notification settings - Fork 184
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
storageClusterPeer: add logic for storageclusterpeer controller #2678
base: main
Are you sure you want to change the base?
Conversation
/retest-required |
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
1ea99b9
to
274a469
Compare
c31ebbe
to
cd4371e
Compare
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
cd4371e
to
47ad908
Compare
47ad908
to
4b3c038
Compare
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
0fe696a
to
cfbc4bf
Compare
cfbc4bf
to
34be7a1
Compare
44b0276
to
dc8a088
Compare
dc8a088
to
4f94c9e
Compare
/retest-required |
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
controllers/storageclusterpeer/storageclusterpeer_controller.go
Outdated
Show resolved
Hide resolved
4f94c9e
to
d69f6e7
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rewantsoni The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
8d456a4
to
99e35e9
Compare
storageClusterPeerList := ocsv1.StorageClusterPeerList{} | ||
if err := r.List(ctx, &storageClusterPeerList, client.InNamespace(sc.Namespace)); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
for i := range storageClusterPeerList.Items { | ||
storageClusterPeer := &storageClusterPeerList.Items[i] | ||
if err = controllerutil.SetOwnerReference(sc, storageClusterPeer, r.Client.Scheme()); err != nil { | ||
return reconcile.Result{}, fmt.Errorf("failed to set owner reference on storageClusterPeer %s: %w", storageClusterPeer.Name, err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be located here. This should be part of a reconcile function that runs as part of the storage cluster main reconcile
r.log.Error(err, "failed to fetch StorageCluster for StorageClusterPeer found in the same namespace.") | ||
if k8serrors.IsNotFound(err) { | ||
storageClusterPeer.Status.State = ocsv1.ReconcileFailed | ||
_ = r.updateStatus(storageClusterPeer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't update the status inside the reconciliation, have a central point outside of the reconciliation that ensures that no matter how we exist the reconcile a status update will happen. Ee take a similar approach in all of our controllers across the majority of our projects.
If you don't do that then all contributors need to always make sure they are sending an update status comment on every return. This is erroneous.
storageClusterPeer.Status.State = ocsv1.ReconcileFailed | ||
return ctrl.Result{}, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a continuation of the my last comment, here is an example of a missed update that will not get persistent
} | ||
storageClusterPeer.Status.State = ocsv1.StorageClusterPeerStateInitializing | ||
|
||
peerStorageClusterUID, err := readStorageClusterUIDFromTicket(storageClusterPeer.Spec.OnboardingToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- we use
token
notticket
in code - This is only needed once. Why is there a need for another function to be invoked?
peerStorageClusterUID, err := readStorageClusterUIDFromTicket(storageClusterPeer.Spec.OnboardingToken) | |
peerStorageClusterUID, err := readStorageClusterUIDFromTicket(storageClusterPeer.Spec.OnboardingToken) |
if storageClusterPeer.Status.PeerInfo == nil { | ||
storageClusterPeer.Status.PeerInfo = &ocsv1.PeerInfo{} | ||
} | ||
storageClusterPeer.Status.PeerInfo.StorageClusterUid = string(peerStorageClusterUID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are updating the storage cluster uid in the peer info then why do you assume all other information should not needs to be wiped out? If the existing storage cluster uid is different then the old info is meaningless and even misleading
|
||
_, err = ocsClient.PeerStorageCluster(r.ctx, storageClusterPeer.Spec.OnboardingToken, string(storageCluster.UID)) | ||
if err != nil { | ||
r.log.Error(err, fmt.Sprintf("failed to Peer Storage Cluster, code: %v.", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r.log.Error(err, fmt.Sprintf("failed to Peer Storage Cluster, code: %v.", err)) | |
r.log.Error(err, fmt.Sprintf("failed to Peer Storage Cluster, reason: %v.", err)) |
_, err = ocsClient.PeerStorageCluster(r.ctx, storageClusterPeer.Spec.OnboardingToken, string(storageCluster.UID)) | ||
if err != nil { | ||
r.log.Error(err, fmt.Sprintf("failed to Peer Storage Cluster, code: %v.", err)) | ||
st, _ := status.FromError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not assume zero errors.
func (r *StorageClusterPeerReconciler) updateStatus(obj client.Object) error { | ||
return r.Client.Status().Update(r.ctx, obj) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this? Status update should be located at a single place in the code when you exist the reconcile logic and should only run once for each reconcile.
var ticketData services.OnboardingTicket | ||
err = json.Unmarshal(message, &ticketData) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to unmarshal onboarding ticket message. %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", fmt.Errorf("failed to unmarshal onboarding ticket message. %v", err) | |
return "", fmt.Errorf("Onboarding ticket message is not a valid JSON. %v", err) |
c37c951
to
44f8993
Compare
Signed-off-by: Rewant Soni <[email protected]>
44f8993
to
ae29829
Compare
add logic for storage cluster peer controller
Depends on:
Part of RHSTOR-4886
(review only the last two commits)