Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
add temporary core/workspaces/v2
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Ilario <filario@redhat.com>
  • Loading branch information
filariow committed May 15, 2024
1 parent c9e32cb commit 9008bd0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
18 changes: 18 additions & 0 deletions server/core/workspace/v2/interfaces_read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package workspace

import (
"context"

restworkspacesv1alpha1 "github.com/konflux-workspaces/workspaces/server/api/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// WorkspaceLister is the interface the data source needs to implement to allow the ListWorkspaceHandler to fetch data from it
type WorkspaceLister interface {
ListUserWorkspaces(ctx context.Context, user string, objs *restworkspacesv1alpha1.WorkspaceList, opts ...client.ListOption) error
}

// WorkspaceReader is the interface the data source needs to implement to allow the ReadWorkspaceHandler to fetch data from it
type WorkspaceReader interface {
ReadUserWorkspace(ctx context.Context, user, owner, space string, obj *restworkspacesv1alpha1.Workspace, opts ...client.GetOption) error
}
4 changes: 2 additions & 2 deletions server/persistence/readclient/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "github.com/konflux-workspaces/workspaces/server/persistence/readclient"

//go:generate mockgen -source=interface_test.go -destination=mocks/readclient.go -package=mocks -exclude_interfaces=FakeIWMapper
type FakeIWReadClient interface {
readclient.IWReadClient
readclient.InternalWorkspacesReadClient
}

//go:generate mockgen -source=interface_test.go -destination=mocks/mapper.go -package=mocks -exclude_interfaces=FakeIWReadClient
type FakeIWMapper interface {
readclient.IWMapper
readclient.InternalWorkspacesMapper
}
21 changes: 13 additions & 8 deletions server/persistence/readclient/readclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ import (
"github.com/konflux-workspaces/workspaces/server/persistence/mapper"
)

type IWReadClient interface {
var (
_ InternalWorkspacesReadClient = &iwclient.Client{}
_ InternalWorkspacesMapper = mapper.Default
)

// InternalWorkspacesReadClient is the definition for a InternalWorkspaces Read Client
type InternalWorkspacesReadClient interface {
GetAsUser(context.Context, string, iwclient.SpaceKey, *workspacesv1alpha1.InternalWorkspace, ...client.GetOption) error
ListAsUser(context.Context, string, *workspacesv1alpha1.InternalWorkspaceList) error
}

var _ IWMapper = mapper.Default

type IWMapper interface {
// InternalWorkspacesMapper is the definition for a InternalWorkspaces/Workspaces Mapper
type InternalWorkspacesMapper interface {
InternalWorkspaceListToWorkspaceList(*workspacesv1alpha1.InternalWorkspaceList) (*restworkspacesv1alpha1.WorkspaceList, error)
InternalWorkspaceToWorkspace(*workspacesv1alpha1.InternalWorkspace) (*restworkspacesv1alpha1.Workspace, error)
WorkspaceToInternalWorkspace(*restworkspacesv1alpha1.Workspace) (*workspacesv1alpha1.InternalWorkspace, error)
Expand All @@ -30,8 +35,8 @@ type IWMapper interface {
// ReadClient implements the WorkspaceLister and WorkspaceReader interfaces
// using a client.Reader as backend
type ReadClient struct {
internalClient IWReadClient
mapper IWMapper
internalClient InternalWorkspacesReadClient
mapper InternalWorkspacesMapper
}

// NewDefaultWithCache creates a controller-runtime cache and use it as KubeReadClient's backend.
Expand All @@ -46,11 +51,11 @@ func NewDefaultWithCache(ctx context.Context, cfg *rest.Config, workspacesNamesp
}

// NewDefaultWithInternalClient creates a new KubeReadClient with the provided backend
func NewDefaultWithInternalClient(internalClient IWReadClient) *ReadClient {
func NewDefaultWithInternalClient(internalClient InternalWorkspacesReadClient) *ReadClient {
return New(internalClient, mapper.Default)
}

func New(internalClient IWReadClient, mapper IWMapper) *ReadClient {
func New(internalClient InternalWorkspacesReadClient, mapper InternalWorkspacesMapper) *ReadClient {
return &ReadClient{
internalClient: internalClient,
mapper: mapper,
Expand Down
4 changes: 2 additions & 2 deletions server/persistence/readclient/readclient_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

workspacesv1alpha1 "github.com/konflux-workspaces/workspaces/operator/api/v1alpha1"
restworkspacesv1alpha1 "github.com/konflux-workspaces/workspaces/server/api/v1alpha1"
"github.com/konflux-workspaces/workspaces/server/core/workspace/v2"
)

// TODO(filariow): enable this after merging changes to `core/workspace`
// var _ workspace.WorkspaceLister = &ReadClient{}
var _ workspace.WorkspaceLister = &ReadClient{}

// ListUserWorkspaces Returns all the workspaces the user has access to
func (c *ReadClient) ListUserWorkspaces(
Expand Down
4 changes: 2 additions & 2 deletions server/persistence/readclient/readclient_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

workspacesv1alpha1 "github.com/konflux-workspaces/workspaces/operator/api/v1alpha1"
restworkspacesv1alpha1 "github.com/konflux-workspaces/workspaces/server/api/v1alpha1"
"github.com/konflux-workspaces/workspaces/server/core/workspace/v2"
"github.com/konflux-workspaces/workspaces/server/log"
"github.com/konflux-workspaces/workspaces/server/persistence/iwclient"
)

// TODO(filariow): enable this after merging changes to `core/workspace`
// var _ workspace.WorkspaceReader = &ReadClient{}
var _ workspace.WorkspaceReader = &ReadClient{}

// ReadUserWorkspace returns the Workspace details only if the user has access to it
func (c *ReadClient) ReadUserWorkspace(
Expand Down

0 comments on commit 9008bd0

Please sign in to comment.