-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement server side rpc call for peering
Signed-off-by: Rewant Soni <[email protected]>
- Loading branch information
1 parent
51fd45d
commit e0ed19e
Showing
3 changed files
with
152 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/red-hat-storage/ocs-operator/v4/services" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" | ||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type storageClusterPeerManager struct { | ||
client client.Client | ||
namespace string | ||
} | ||
|
||
func newStorageClusterPeerManager(cl client.Client, namespace string) (*storageClusterPeerManager, error) { | ||
return &storageClusterPeerManager{ | ||
client: cl, | ||
namespace: namespace, | ||
}, nil | ||
} | ||
|
||
func (s *storageClusterPeerManager) GetByStorageClusterUID(ctx context.Context, storageClusterUid types.UID) (*ocsv1.StorageClusterPeer, error) { | ||
storageClusterPeerList := &ocsv1.StorageClusterPeerList{} | ||
err := s.client.List(ctx, storageClusterPeerList, client.InNamespace(s.namespace)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for i := range storageClusterPeerList.Items { | ||
message, _, err := decodeTicket(storageClusterPeerList.Items[i].Spec.OnboardingToken) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ticketData services.OnboardingTicket | ||
err = json.Unmarshal(message, &ticketData) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal onboarding ticket message. %v", err) | ||
} | ||
|
||
if ticketData.StorageCluster == storageClusterUid { | ||
return &storageClusterPeerList.Items[i], nil | ||
} | ||
} | ||
return nil, fmt.Errorf("StorageClusterPeer linked to StorageCluster with uid %q not found", storageClusterUid) | ||
} | ||
|
||
func (s *storageClusterPeerManager) UpdateStatus(ctx context.Context, storageClusterPeer client.Object) error { | ||
if err := s.client.Status().Update(ctx, storageClusterPeer); err != nil { | ||
return fmt.Errorf("failed to update Status for StorageClusterPeer %v: %v", storageClusterPeer.GetName(), err) | ||
} | ||
klog.Infof("successfully updated Status for StorageClusterPeer %v", storageClusterPeer.GetName()) | ||
return nil | ||
} |