Skip to content

Commit

Permalink
Onboard clients only if they are on same version as provider - 2
Browse files Browse the repository at this point in the history
- Operator major and minor version of client and provider should match
for onboarding process to begin
- After this commit older clients will fail to get onboarded

Minor: Rename package clientstatus to interfaces

Signed-off-by: Leela Venkaiah G <[email protected]>
  • Loading branch information
leelavg committed Dec 12, 2023
1 parent a0a6503 commit dea0632
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 192 deletions.
20 changes: 12 additions & 8 deletions services/provider/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

cs "github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus"
ifaces "github.com/red-hat-storage/ocs-operator/v4/services/provider/interfaces"
pb "github.com/red-hat-storage/ocs-operator/v4/services/provider/pb"

"google.golang.org/grpc"
Expand Down Expand Up @@ -53,17 +53,21 @@ func (cc *OCSProviderClient) Close() {
cc.Client = nil
}

func NewOnboardConsumerRequest() ifaces.StorageClientOnboarding {
return &pb.OnboardConsumerRequest{}
}

// OnboardConsumer to validate the consumer and create StorageConsumer
// resource on the StorageProvider cluster
func (cc *OCSProviderClient) OnboardConsumer(ctx context.Context, ticket, name string) (*pb.OnboardConsumerResponse, error) {
func (cc *OCSProviderClient) OnboardConsumer(ctx context.Context, ticket, name string,
args ifaces.StorageClientOnboarding) (*pb.OnboardConsumerResponse, error) {
if cc.Client == nil || cc.clientConn == nil {
return nil, fmt.Errorf("provider client is closed")
}

req := &pb.OnboardConsumerRequest{
OnboardingTicket: ticket,
ConsumerName: name,
}
req := args.(*pb.OnboardConsumerRequest)
req.OnboardingTicket = ticket
req.ConsumerName = name

apiCtx, cancel := context.WithTimeout(ctx, cc.timeout)
defer cancel()
Expand Down Expand Up @@ -189,11 +193,11 @@ func (cc *OCSProviderClient) GetStorageClassClaimConfig(ctx context.Context, con
return cc.Client.GetStorageClassClaimConfig(apiCtx, req)
}

func NewStorageClientStatus() cs.StorageClientStatus {
func NewStorageClientStatus() ifaces.StorageClientStatus {
return &pb.ReportStatusRequest{}
}

func (cc *OCSProviderClient) ReportStatus(ctx context.Context, consumerUUID string, status cs.StorageClientStatus) (*pb.ReportStatusResponse, error) {
func (cc *OCSProviderClient) ReportStatus(ctx context.Context, consumerUUID string, status ifaces.StorageClientStatus) (*pb.ReportStatusResponse, error) {
if cc.Client == nil || cc.clientConn == nil {
return nil, fmt.Errorf("Provider client is closed")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clientstatus
package interfaces

type StorageClientStatus interface {
GetPlatformVersion() string
Expand All @@ -7,3 +7,9 @@ type StorageClientStatus interface {
SetPlatformVersion(string) StorageClientStatus
SetOperatorVersion(string) StorageClientStatus
}

type StorageClientOnboarding interface {
GetOperatorVersion() string

SetOperatorVersion(string) StorageClientOnboarding
}
323 changes: 168 additions & 155 deletions services/provider/pb/provider.pb.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions services/provider/pb/storageclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package providerpb

import (
ifaces "github.com/red-hat-storage/ocs-operator/v4/services/provider/interfaces"
)

// ensure ReportStatusRequest satisfies StorageClientStatus interface
var _ ifaces.StorageClientStatus = &ReportStatusRequest{}

func (r *ReportStatusRequest) GetPlatformVersion() string {
return r.ClientPlatformVersion
}

func (r *ReportStatusRequest) GetOperatorVersion() string {
return r.ClientOperatorVersion
}

func (r *ReportStatusRequest) SetPlatformVersion(version string) ifaces.StorageClientStatus {
r.ClientPlatformVersion = version
return r
}

func (r *ReportStatusRequest) SetOperatorVersion(version string) ifaces.StorageClientStatus {
r.ClientOperatorVersion = version
return r
}

// ensure OnboardConsumerRequest satisfies StorageClientOnboarding interface
var _ ifaces.StorageClientOnboarding = &OnboardConsumerRequest{}

func (o *OnboardConsumerRequest) GetOperatorVersion() string {
return o.ClientOperatorVersion
}

func (o *OnboardConsumerRequest) SetOperatorVersion(version string) ifaces.StorageClientOnboarding {
o.ClientOperatorVersion = version
return o
}
26 changes: 0 additions & 26 deletions services/provider/pb/storageclient_status.go

This file was deleted.

2 changes: 2 additions & 0 deletions services/provider/proto/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ message OnboardConsumerRequest{
string onboardingTicket = 1;
// consumerName is the name of the consumer that is used to create the storageConsumer resource
string consumerName = 2;
// clientOperatorVersion is the semver version of ocs-client-operator
string clientOperatorVersion = 3;
}

// OnboardConsumerResponse holds the response for OnboardConsumer API request
Expand Down
4 changes: 2 additions & 2 deletions services/provider/server/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1"
cs "github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus"
ifaces "github.com/red-hat-storage/ocs-operator/v4/services/provider/interfaces"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -199,7 +199,7 @@ func (c *ocsConsumerManager) Get(ctx context.Context, id string) (*ocsv1alpha1.S
return consumerObj, nil
}

func (c *ocsConsumerManager) UpdateConsumerStatus(ctx context.Context, id string, status cs.StorageClientStatus) error {
func (c *ocsConsumerManager) UpdateConsumerStatus(ctx context.Context, id string, status ifaces.StorageClientStatus) error {
consumerObj, err := c.Get(ctx, id)
if err != nil {
return err
Expand Down
17 changes: 17 additions & 0 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1"
controllers "github.com/red-hat-storage/ocs-operator/v4/controllers/storageconsumer"
pb "github.com/red-hat-storage/ocs-operator/v4/services/provider/pb"
ocsVersion "github.com/red-hat-storage/ocs-operator/v4/version"
rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"

"google.golang.org/grpc"
Expand Down Expand Up @@ -57,6 +58,7 @@ type OCSProviderServer struct {
consumerManager *ocsConsumerManager
storageClassRequestManager *storageClassRequestManager
namespace string
version *semver.Version
}

type onboardingTicket struct {
Expand All @@ -80,17 +82,32 @@ func NewOCSProviderServer(ctx context.Context, namespace string) (*OCSProviderSe
return nil, fmt.Errorf("failed to create new StorageClassRequest instance. %v", err)
}

version, err := semver.Make(ocsVersion.Version)
if err != nil {
return nil, fmt.Errorf("failed to parse operator version as semver. %v", err)
}

return &OCSProviderServer{
client: client,
consumerManager: consumerManager,
storageClassRequestManager: storageClassRequestManager,
namespace: namespace,
version: &version,
}, nil
}

// OnboardConsumer RPC call to onboard a new OCS consumer cluster.
func (s *OCSProviderServer) OnboardConsumer(ctx context.Context, req *pb.OnboardConsumerRequest) (*pb.OnboardConsumerResponse, error) {

version, err := semver.Make(req.ClientOperatorVersion)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "malformed ClientPlatformVersion for client %q is provided. %v", req.ConsumerName, err)
}

if s.version.Minor != version.Minor || s.version.Major != version.Major {
return nil, status.Errorf(codes.InvalidArgument, "both major and minor version of server and client %q should match for onboarding process", req.ConsumerName)
}

pubKey, err := s.getOnboardingValidationKey(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get public key to validate onboarding ticket for consumer %q. %v", req.ConsumerName, err)
Expand Down

0 comments on commit dea0632

Please sign in to comment.