-
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.
implemenent the server side rpc call for peering
Signed-off-by: Rewant Soni <[email protected]>
- Loading branch information
1 parent
20951c4
commit 3271af9
Showing
4 changed files
with
108 additions
and
16 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
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,41 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
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) GetByPeerStorageClusterUID(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, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to list StorageClusterPeer: %v", err)) | ||
} | ||
for i := range storageClusterPeerList.Items { | ||
storageClusterPeer := &storageClusterPeerList.Items[i] | ||
if storageClusterPeer.Status.PeerInfo != nil { | ||
if storageClusterUID == types.UID(storageClusterPeer.Status.PeerInfo.StorageClusterUid) { | ||
return storageClusterPeer, nil | ||
} | ||
} | ||
} | ||
return nil, status.Error(codes.NotFound, fmt.Sprintf("StorageClusterPeer linked to StorageCluster with uid %q not found", storageClusterUID)) | ||
} |