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 20, 2023
1 parent aa483d6 commit 808eb24
Show file tree
Hide file tree
Showing 8 changed files with 242 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 @@ -6,7 +6,7 @@ import (
"fmt"
"sync"

ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1"
ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1"
cs "github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus"

Check failure on line 10 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / go test (1.20)

cannot query module due to -mod=vendor

Check failure on line 10 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / go test (1.21)

cannot find module providing package github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus: import lookup disabled by -mod=vendor

Check failure on line 10 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / go test (1.21)

cannot find module providing package github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus: import lookup disabled by -mod=vendor
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
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 {

Check failure on line 202 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.20)

undefined: ifaces (typecheck)

Check failure on line 202 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.20)

undefined: ifaces (typecheck)

Check failure on line 202 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21)

undefined: ifaces (typecheck)

Check failure on line 202 in services/provider/server/consumer.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21)

undefined: ifaces (typecheck)
consumerObj, err := c.Get(ctx, id)
if err != nil {
return err
Expand Down
13 changes: 13 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 @@ -91,6 +92,18 @@ func NewOCSProviderServer(ctx context.Context, namespace string) (*OCSProviderSe
// 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.FinalizeVersion(req.ClientOperatorVersion)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "malformed ClientPlatformVersion for client %q is provided. %v", req.ConsumerName, err)
}

provVersion, _ := semver.Make(ocsVersion.Version)
cliVersion, _ := semver.Make(version)
// M.m.z versions of ODF Provider and ODF Client Operators should match for onboarding
if cliVersion.NE(provVersion) {
return nil, status.Errorf(codes.InvalidArgument, "both server and client %q operators versions 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 808eb24

Please sign in to comment.