Skip to content

Commit

Permalink
Merge pull request #2484 from leelavg/webhook
Browse files Browse the repository at this point in the history
proto: send ocs-operator subscription channel name in heartbeat response
  • Loading branch information
openshift-merge-bot[bot] authored Mar 13, 2024
2 parents 4e5d8b7 + b0781db commit 73ae0f2
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 55 deletions.
11 changes: 11 additions & 0 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ func GetKeyRotationSpec(sc *ocsv1.StorageCluster) (bool, string) {
}
return *sc.Spec.Encryption.KeyRotation.Enable, schedule
}

// Find returns the first entry matching the function "f" or else return nil
func Find[T any](list []T, f func(item *T) bool) *T {
for idx := range list {
ele := &list[idx]
if f(ele) {
return ele
}
}
return nil
}
7 changes: 7 additions & 0 deletions deploy/ocs-operator/manifests/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ rules:
- list
- create
- delete
- apiGroups:
- operators.coreos.com
resources:
- subscriptions
verbs:
- get
- list
7 changes: 7 additions & 0 deletions rbac/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ rules:
- list
- create
- delete
- apiGroups:
- operators.coreos.com
resources:
- subscriptions
verbs:
- get
- list
120 changes: 67 additions & 53 deletions services/provider/pb/provider.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion services/provider/proto/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,7 @@ message ReportStatusRequest{
string clientOperatorVersion = 3;
}

message ReportStatusResponse{}
message ReportStatusResponse{
// Contains subscription channel of provider operator for client operator to match
string desiredClientOperatorChannel = 1;
}
28 changes: 27 additions & 1 deletion services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1"
ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1"
controllers "github.com/red-hat-storage/ocs-operator/v4/controllers/storageconsumer"
"github.com/red-hat-storage/ocs-operator/v4/controllers/util"
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"

opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/red-hat-storage/ocs-operator/v4/services"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -227,6 +229,10 @@ func newClient() (client.Client, error) {
if err != nil {
return nil, fmt.Errorf("failed to add rookCephv1 to scheme. %v", err)
}
err = opv1a1.AddToScheme(scheme)
if err != nil {
return nil, fmt.Errorf("failed to add operatorsv1alpha1 to scheme. %v", err)
}

config, err := config.GetConfig()
if err != nil {
Expand Down Expand Up @@ -688,5 +694,25 @@ func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStat
return nil, status.Errorf(codes.Internal, "Failed to update lastHeartbeat payload in the storageConsumer resource: %v", err)
}

return &pb.ReportStatusResponse{}, nil
channelName, err := s.getOCSSubscriptionChannel(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to construct status response: %v", err)
}

return &pb.ReportStatusResponse{DesiredClientOperatorChannel: channelName}, nil
}

func (s *OCSProviderServer) getOCSSubscriptionChannel(ctx context.Context) (string, error) {
subscriptionList := &opv1a1.SubscriptionList{}
err := s.client.List(ctx, subscriptionList, client.InNamespace(s.namespace))
if err != nil {
return "", err
}
subscription := util.Find(subscriptionList.Items, func(sub *opv1a1.Subscription) bool {
return sub.Spec.Package == "ocs-operator"
})
if subscription == nil {
return "", fmt.Errorf("unable to find ocs-operator subscription")
}
return subscription.Spec.Channel, nil
}

0 comments on commit 73ae0f2

Please sign in to comment.