-
Notifications
You must be signed in to change notification settings - Fork 185
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
shim layer for sending claim resources from existing storagerequest crs #3022
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ package server | |
|
||
import ( | ||
"context" | ||
"crypto/md5" | ||
"encoding/hex" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"sync" | ||
|
@@ -55,6 +58,43 @@ func newConsumerManager(ctx context.Context, cl client.Client, namespace string) | |
}, nil | ||
} | ||
|
||
// getStorageRequestHash generates a hash for a StorageRequest based | ||
// on the MD5 hash of the StorageClaim name and storageConsumer UUID. | ||
func getStorageRequestHash(consumerUUID, storageClaimName string) string { | ||
s := struct { | ||
StorageConsumerUUID string `json:"storageConsumerUUID"` | ||
StorageClaimName string `json:"storageClaimName"` | ||
}{ | ||
consumerUUID, | ||
storageClaimName, | ||
} | ||
|
||
requestName, err := json.Marshal(s) | ||
if err != nil { | ||
klog.Errorf("failed to marshal a name for a storage class request based on %v. %v", s, err) | ||
panic("failed to marshal storage class request name") | ||
} | ||
md5Sum := md5.Sum(requestName) | ||
return hex.EncodeToString(md5Sum[:16]) | ||
} | ||
|
||
// getStorageRequestName generates a name for a StorageRequest resource. | ||
func getStorageRequestName(consumerUUID, storageClaimName string) string { | ||
return fmt.Sprintf("storagerequest-%s", getStorageRequestHash(consumerUUID, storageClaimName)) | ||
} | ||
|
||
func (c *ocsConsumerManager) GetRequest(ctx context.Context, consumerUUID, storageClaimName string) (*ocsv1alpha1.StorageRequest, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a "TODO" comment explaining that this function is to be remove when we do the jump to 4.20 |
||
generatedRequestName := getStorageRequestName(consumerUUID, storageClaimName) | ||
storageRequestObj := &ocsv1alpha1.StorageRequest{} | ||
err := c.client.Get(ctx, types.NamespacedName{Name: generatedRequestName, Namespace: c.namespace}, storageRequestObj) | ||
if err != nil { | ||
klog.Errorf("failed to get a StorageRequest named %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageClaimName, err) | ||
return nil, err | ||
} | ||
Comment on lines
+89
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the point to remove the storage request API with this shim. If so it does not make sense to load the resource There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return storageRequestObj, nil | ||
} | ||
|
||
// Create creates a new storageConsumer resource, updates the consumer cache and returns the storageConsumer UID | ||
func (c *ocsConsumerManager) Create(ctx context.Context, onboard ifaces.StorageClientOnboarding, storageQuotaInGiB int) (string, error) { | ||
ticket := onboard.GetOnboardingTicket() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,6 @@ type OCSProviderServer struct { | |
pb.UnimplementedOCSProviderServer | ||
client client.Client | ||
consumerManager *ocsConsumerManager | ||
storageRequestManager *storageRequestManager | ||
storageClusterPeerManager *storageClusterPeerManager | ||
namespace string | ||
} | ||
|
@@ -95,11 +94,6 @@ func NewOCSProviderServer(ctx context.Context, namespace string) (*OCSProviderSe | |
return nil, fmt.Errorf("failed to create new OCSConumer instance. %v", err) | ||
} | ||
|
||
storageRequestManager, err := newStorageRequestManager(client, namespace) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create new StorageRequest instance. %v", err) | ||
} | ||
|
||
storageClusterPeerManager, err := newStorageClusterPeerManager(client, namespace) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create new StorageClusterPeer instance. %v", err) | ||
|
@@ -108,7 +102,6 @@ func NewOCSProviderServer(ctx context.Context, namespace string) (*OCSProviderSe | |
return &OCSProviderServer{ | ||
client: client, | ||
consumerManager: consumerManager, | ||
storageRequestManager: storageRequestManager, | ||
storageClusterPeerManager: storageClusterPeerManager, | ||
namespace: namespace, | ||
}, nil | ||
|
@@ -658,30 +651,13 @@ func decodeAndValidateTicket(ticket string, pubKey *rsa.PublicKey) (*services.On | |
// FulfillStorageClaim RPC call to create the StorageClaim CR on | ||
// provider cluster. | ||
func (s *OCSProviderServer) FulfillStorageClaim(ctx context.Context, req *pb.FulfillStorageClaimRequest) (*pb.FulfillStorageClaimResponse, error) { | ||
// Get storage consumer resource using UUID | ||
consumerObj, err := s.consumerManager.Get(ctx, req.StorageConsumerUUID) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
||
klog.Infof("Found StorageConsumer %q (%q)", consumerObj.Name, req.StorageConsumerUUID) | ||
|
||
var storageType string | ||
switch req.StorageType { | ||
case pb.FulfillStorageClaimRequest_BLOCK: | ||
storageType = "block" | ||
case pb.FulfillStorageClaimRequest_SHAREDFILE: | ||
storageType = "sharedfile" | ||
default: | ||
return nil, status.Errorf(codes.InvalidArgument, "encountered an unknown storage type, %s", storageType) | ||
} | ||
|
||
err = s.storageRequestManager.Create(ctx, consumerObj, req.StorageClaimName, storageType, req.EncryptionMethod, req.StorageProfile) | ||
// this is only here for backward compatibility as we expect no existing older client | ||
// wants to fulfill claims as current provider deprecated storagerequests | ||
_, err := s.consumerManager.GetRequest(ctx, req.StorageConsumerUUID, req.StorageClaimName) | ||
Comment on lines
+654
to
+656
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the better approach is to always return internal error (or some other error) for this operation |
||
if err != nil { | ||
errMsg := fmt.Sprintf("failed to fulfill storage class claim for %q. %v", req.StorageConsumerUUID, err) | ||
klog.Error(errMsg) | ||
if kerrors.IsAlreadyExists(err) { | ||
return nil, status.Error(codes.AlreadyExists, errMsg) | ||
errMsg := fmt.Sprintf("failed to get storageclaim config %q for %q. %v", req.StorageClaimName, req.StorageConsumerUUID, err) | ||
if kerrors.IsNotFound(err) { | ||
return nil, status.Error(codes.NotFound, errMsg) | ||
} | ||
return nil, status.Error(codes.Internal, errMsg) | ||
} | ||
|
@@ -692,13 +668,8 @@ func (s *OCSProviderServer) FulfillStorageClaim(ctx context.Context, req *pb.Ful | |
// RevokeStorageClaim RPC call to delete the StorageClaim CR on | ||
// provider cluster. | ||
func (s *OCSProviderServer) RevokeStorageClaim(ctx context.Context, req *pb.RevokeStorageClaimRequest) (*pb.RevokeStorageClaimResponse, error) { | ||
err := s.storageRequestManager.Delete(ctx, req.StorageConsumerUUID, req.StorageClaimName) | ||
if err != nil { | ||
errMsg := fmt.Sprintf("failed to revoke storage class claim %q for %q. %v", req.StorageClaimName, req.StorageConsumerUUID, err) | ||
klog.Error(errMsg) | ||
return nil, status.Error(codes.Internal, errMsg) | ||
} | ||
|
||
// client cluster want to stop using storageclasses and data on the backend can be removed | ||
// TODO: this should be transferred into removal of storageclasses and corresponding data | ||
Comment on lines
+671
to
+672
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the better approach is to always return internal error (or some other error) for this operation |
||
return &pb.RevokeStorageClaimResponse{}, nil | ||
} | ||
|
||
|
@@ -708,7 +679,7 @@ func storageClaimCephCsiSecretName(secretType, suffix string) string { | |
|
||
// GetStorageClaim RPC call to get the ceph resources for the StorageClaim. | ||
func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.StorageClaimConfigRequest) (*pb.StorageClaimConfigResponse, error) { | ||
storageRequest, err := s.storageRequestManager.Get(ctx, req.StorageConsumerUUID, req.StorageClaimName) | ||
storageRequest, err := s.consumerManager.GetRequest(ctx, req.StorageConsumerUUID, req.StorageClaimName) | ||
if err != nil { | ||
errMsg := fmt.Sprintf("failed to get storage class claim config %q for %q. %v", req.StorageClaimName, req.StorageConsumerUUID, err) | ||
if kerrors.IsNotFound(err) { | ||
|
This file was deleted.
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 these 2 functions as standalone functions? I see the logic belong for a single flow which is the
GetRequest
logic. Can we fold everything there?It will make it easier to move around and potentially remove in the future.