Skip to content

Commit

Permalink
added support for ocs provider server to fetch noobaa resources
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Majumder <[email protected]>
  • Loading branch information
Kaustav Majumder committed Jul 2, 2024
1 parent dfffbde commit 6bc76c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/storageconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ type CephResourcesSpec struct {
CephClients map[string]string `json:"cephClients,omitempty"`
}

type NoobaaResourcesSpec struct {
NoobaaManagementURL string `json:"noobaaMgmtURL,omitempty"`
NoobaaRemoteSecret string `json:"noobaaRemoteSecret,omitempty"`
}

// StorageConsumerStatus defines the observed state of StorageConsumer
type StorageConsumerStatus struct {
// State describes the state of StorageConsumer
State StorageConsumerState `json:"state,omitempty"`
// CephResources provide details of created ceph resources required for external storage
CephResources []*CephResourcesSpec `json:"cephResources,omitempty"`
// Noobaa Resources
NoobaaResources NoobaaResourcesSpec `json:"noobaaResources,omitempty"`
// Timestamp of last heartbeat received from consumer
LastHeartbeat metav1.Time `json:"lastHeartbeat,omitempty"`
// Information of storage client received from consumer
Expand Down
31 changes: 28 additions & 3 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"time"

"github.com/blang/semver/v4"
nb "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"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"
"github.com/red-hat-storage/ocs-operator/v4/services"
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"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -183,6 +183,7 @@ func (s *OCSProviderServer) GetStorageConfig(ctx context.Context, req *pb.Storag
func (s *OCSProviderServer) OffboardConsumer(ctx context.Context, req *pb.OffboardConsumerRequest) (*pb.OffboardConsumerResponse, error) {

err := s.consumerManager.Delete(ctx, req.StorageConsumerUUID)
// noobaa client resources here
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete storageConsumer resource with the provided UUID. %v", err)
}
Expand Down Expand Up @@ -367,6 +368,30 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe
}),
})

// Fetch noobaa remote secret and append to extResources
noobaaOperatorSecret := &v1.Secret{}
noobaaOperatorSecretName := "noobaa-operator"
err = s.client.Get(ctx, types.NamespacedName{Name: noobaaOperatorSecretName, Namespace: s.namespace}, noobaaOperatorSecret)
if err != nil {
return nil, fmt.Errorf("failed to get %s secret. %v", noobaaOperatorSecretName, err)
}
// Fetch noobaa management address from deployed noobaa CR
providerNoobaa := &nb.NooBaa{}
providerNoobaaName := "noobaa"
err = s.client.Get(ctx, types.NamespacedName{Name: providerNoobaaName, Namespace: s.namespace}, providerNoobaa)
if err != nil {
return nil, fmt.Errorf("failed to get %s cr. %v", providerNoobaaName, err)
}
//Todo : Make Fetching external DNS more robust
noobaaMgmtAddress := providerNoobaa.Status.Services.ServiceMgmt.ExternalDNS[0]
extR = append(extR, &pb.ExternalResource{
Name: "noobaa-join-secret",
Kind: "Secret",
Data: mustMarshal((map[string]string{
"auth-token": string(noobaaOperatorSecret.Data["auth-token"]),
"mgmt-address": noobaaMgmtAddress,
})),
})
return extR, nil
}

Expand Down

0 comments on commit 6bc76c0

Please sign in to comment.