Skip to content

Commit

Permalink
Extend bucket implementation with iriBucket RuntimeService interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit-0505 committed Jul 9, 2024
1 parent 5a5b801 commit 33b8852
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 18 deletions.
17 changes: 17 additions & 0 deletions iri/apis/bucket/bucket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package bucket

import (
"context"

api "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
)

type RuntimeService interface {
ListBuckets(context.Context, *api.ListBucketsRequest) (*api.ListBucketsResponse, error)
CreateBucket(context.Context, *api.CreateBucketRequest) (*api.CreateBucketResponse, error)
ListBucketClasses(ctx context.Context, request *api.ListBucketClassesRequest) (*api.ListBucketClassesResponse, error)
DeleteBucket(context.Context, *api.DeleteBucketRequest) (*api.DeleteBucketResponse, error)
}
47 changes: 47 additions & 0 deletions iri/remote/bucket/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package bucket

import (
"context"
"fmt"

"github.com/ironcore-dev/ironcore/iri/apis/bucket"
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type remoteRuntime struct {
client iri.BucketRuntimeClient
}

func NewRemoteRuntime(endpoint string) (bucket.RuntimeService, error) {
conn, err := grpc.NewClient(endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, fmt.Errorf("error dialing: %w", err)
}

return &remoteRuntime{
client: iri.NewBucketRuntimeClient(conn),
}, nil
}

func (r *remoteRuntime) ListBuckets(ctx context.Context, request *iri.ListBucketsRequest) (*iri.ListBucketsResponse, error) {
return r.client.ListBuckets(ctx, request)
}

func (r *remoteRuntime) CreateBucket(ctx context.Context, request *iri.CreateBucketRequest) (*iri.CreateBucketResponse, error) {
return r.client.CreateBucket(ctx, request)
}

func (r *remoteRuntime) DeleteBucket(ctx context.Context, request *iri.DeleteBucketRequest) (*iri.DeleteBucketResponse, error) {
return r.client.DeleteBucket(ctx, request)
}

func (r *remoteRuntime) ListBucketClasses(ctx context.Context, request *iri.ListBucketClassesRequest) (*iri.ListBucketClassesResponse, error) {
return r.client.ListBucketClasses(ctx, request)
}
5 changes: 3 additions & 2 deletions poollet/bucketpoollet/bcm/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/ironcore-dev/ironcore/iri/apis/bucket"
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
"golang.org/x/exp/maps"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -37,7 +38,7 @@ type Generic struct {
bucketClassByName map[string]*iri.BucketClass
bucketClassByCapabilities map[capabilities][]*iri.BucketClass

bucketRuntime iri.BucketRuntimeClient
bucketRuntime bucket.RuntimeService

relistPeriod time.Duration
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func setGenericOptionsDefaults(o *GenericOptions) {
}
}

func NewGeneric(runtime iri.BucketRuntimeClient, opts GenericOptions) BucketClassMapper {
func NewGeneric(runtime bucket.RuntimeService, opts GenericOptions) BucketClassMapper {
setGenericOptionsDefaults(&opts)
return &Generic{
synced: make(chan struct{}),
Expand Down
15 changes: 2 additions & 13 deletions poollet/bucketpoollet/cmd/bucketpoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/ironcore-dev/ironcore/utils/client/config"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -137,19 +135,10 @@ func Run(ctx context.Context, opts Options) error {
return fmt.Errorf("error detecting bucket runtime endpoint: %w", err)
}

conn, err := grpc.NewClient(endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
bucketRuntime, err := iriremotebucket.NewRemoteRuntime(endpoint)
if err != nil {
return fmt.Errorf("error dialing: %w", err)
return fmt.Errorf("error creating remote bucket runtime: %w", err)
}
defer func() {
if err := conn.Close(); err != nil {
setupLog.Error(err, "Error closing bucket runtime connection")
}
}()

bucketRuntime := iri.NewBucketRuntimeClient(conn)

cfg, configCtrl, err := getter.GetConfig(ctx, &opts.GetConfigOptions)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion poollet/bucketpoollet/controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/go-logr/logr"
"github.com/ironcore-dev/controller-utils/clientutils"
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
iriBucket "github.com/ironcore-dev/ironcore/iri/apis/bucket"
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"

irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
bucketpoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/api/v1alpha1"
"github.com/ironcore-dev/ironcore/poollet/bucketpoollet/bcm"
Expand All @@ -39,7 +41,7 @@ type BucketReconciler struct {
client.Client
Scheme *runtime.Scheme

BucketRuntime iri.BucketRuntimeClient
BucketRuntime iriBucket.RuntimeService

BucketClassMapper bcm.BucketClassMapper

Expand Down
4 changes: 2 additions & 2 deletions poollet/bucketpoollet/controllers/bucketpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/go-logr/logr"
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
iriBucket "github.com/ironcore-dev/ironcore/iri/apis/bucket"
"github.com/ironcore-dev/ironcore/poollet/bucketpoollet/bcm"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -23,7 +23,7 @@ import (
type BucketPoolReconciler struct {
client.Client
BucketPoolName string
BucketRuntime iri.BucketRuntimeClient
BucketRuntime iriBucket.RuntimeService
BucketClassMapper bcm.BucketClassMapper
}

Expand Down

0 comments on commit 33b8852

Please sign in to comment.