mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-21 21:33:06 +01:00
refactor(provider): move app/providers to pkg/provider (#517)
This commit is contained in:
2
.github/labeler.yml
vendored
2
.github/labeler.yml
vendored
@@ -8,7 +8,7 @@ reverse-proxy:
|
|||||||
|
|
||||||
provider:
|
provider:
|
||||||
- changed-files:
|
- changed-files:
|
||||||
- any-glob-to-any-file: 'app/providers/**'
|
- any-glob-to-any-file: 'pkg/provider/**'
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
- changed-files:
|
- changed-files:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package discovery
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"github.com/sablierapp/sablier/pkg/store"
|
"github.com/sablierapp/sablier/pkg/store"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -13,8 +13,8 @@ import (
|
|||||||
// as running instances by Sablier.
|
// as running instances by Sablier.
|
||||||
// By default, Sablier does not stop all already running instances. Meaning that you need to make an
|
// By default, Sablier does not stop all already running instances. Meaning that you need to make an
|
||||||
// initial request in order to trigger the scaling to zero.
|
// initial request in order to trigger the scaling to zero.
|
||||||
func StopAllUnregisteredInstances(ctx context.Context, provider providers.Provider, s store.Store, logger *slog.Logger) error {
|
func StopAllUnregisteredInstances(ctx context.Context, p provider.Provider, s store.Store, logger *slog.Logger) error {
|
||||||
instances, err := provider.InstanceList(ctx, providers.InstanceListOptions{
|
instances, err := p.InstanceList(ctx, provider.InstanceListOptions{
|
||||||
All: false, // Only running containers
|
All: false, // Only running containers
|
||||||
Labels: []string{LabelEnable},
|
Labels: []string{LabelEnable},
|
||||||
})
|
})
|
||||||
@@ -35,15 +35,15 @@ func StopAllUnregisteredInstances(ctx context.Context, provider providers.Provid
|
|||||||
waitGroup := errgroup.Group{}
|
waitGroup := errgroup.Group{}
|
||||||
|
|
||||||
for _, name := range unregistered {
|
for _, name := range unregistered {
|
||||||
waitGroup.Go(stopFunc(ctx, name, provider, logger))
|
waitGroup.Go(stopFunc(ctx, name, p, logger))
|
||||||
}
|
}
|
||||||
|
|
||||||
return waitGroup.Wait()
|
return waitGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopFunc(ctx context.Context, name string, provider providers.Provider, logger *slog.Logger) func() error {
|
func stopFunc(ctx context.Context, name string, p provider.Provider, logger *slog.Logger) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
err := provider.Stop(ctx, name)
|
err := p.Stop(ctx, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorContext(ctx, "failed to stop instance", slog.String("instance", name), slog.Any("error", err))
|
logger.ErrorContext(ctx, "failed to stop instance", slog.String("instance", name), slog.Any("error", err))
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"github.com/neilotoole/slogt"
|
"github.com/neilotoole/slogt"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/providers/mock"
|
|
||||||
"github.com/sablierapp/sablier/app/types"
|
"github.com/sablierapp/sablier/app/types"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider/mock"
|
||||||
"github.com/sablierapp/sablier/pkg/store/inmemory"
|
"github.com/sablierapp/sablier/pkg/store/inmemory"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -30,7 +30,7 @@ func TestStopAllUnregisteredInstances(t *testing.T) {
|
|||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
// Set up expectations for InstanceList
|
// Set up expectations for InstanceList
|
||||||
mockProvider.On("InstanceList", ctx, providers.InstanceListOptions{
|
mockProvider.On("InstanceList", ctx, provider.InstanceListOptions{
|
||||||
All: false,
|
All: false,
|
||||||
Labels: []string{discovery.LabelEnable},
|
Labels: []string{discovery.LabelEnable},
|
||||||
}).Return(instances, nil)
|
}).Return(instances, nil)
|
||||||
@@ -62,7 +62,7 @@ func TestStopAllUnregisteredInstances_WithError(t *testing.T) {
|
|||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
// Set up expectations for InstanceList
|
// Set up expectations for InstanceList
|
||||||
mockProvider.On("InstanceList", ctx, providers.InstanceListOptions{
|
mockProvider.On("InstanceList", ctx, provider.InstanceListOptions{
|
||||||
All: false,
|
All: false,
|
||||||
Labels: []string{discovery.LabelEnable},
|
Labels: []string{discovery.LabelEnable},
|
||||||
}).Return(instances, nil)
|
}).Return(instances, nil)
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/http/routes"
|
"github.com/sablierapp/sablier/app/http/routes"
|
||||||
"github.com/sablierapp/sablier/app/providers/docker"
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"github.com/sablierapp/sablier/app/providers/dockerswarm"
|
"github.com/sablierapp/sablier/pkg/provider/docker"
|
||||||
"github.com/sablierapp/sablier/app/providers/kubernetes"
|
"github.com/sablierapp/sablier/pkg/provider/dockerswarm"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider/kubernetes"
|
||||||
"github.com/sablierapp/sablier/pkg/store/inmemory"
|
"github.com/sablierapp/sablier/pkg/store/inmemory"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
@@ -15,7 +16,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/sessions"
|
"github.com/sablierapp/sablier/app/sessions"
|
||||||
"github.com/sablierapp/sablier/app/storage"
|
"github.com/sablierapp/sablier/app/storage"
|
||||||
"github.com/sablierapp/sablier/app/theme"
|
"github.com/sablierapp/sablier/app/theme"
|
||||||
@@ -128,7 +128,7 @@ func Start(ctx context.Context, conf config.Config) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func onSessionExpires(ctx context.Context, provider providers.Provider, logger *slog.Logger) func(key string) {
|
func onSessionExpires(ctx context.Context, provider provider.Provider, logger *slog.Logger) func(key string) {
|
||||||
return func(_key string) {
|
return func(_key string) {
|
||||||
go func(key string) {
|
go func(key string) {
|
||||||
logger.InfoContext(ctx, "instance expired", slog.String("instance", key))
|
logger.InfoContext(ctx, "instance expired", slog.String("instance", key))
|
||||||
@@ -165,7 +165,7 @@ func saveSessions(storage storage.Storage, sessions sessions.Manager, logger *sl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProvider(ctx context.Context, logger *slog.Logger, config config.Provider) (providers.Provider, error) {
|
func NewProvider(ctx context.Context, logger *slog.Logger, config config.Provider) (provider.Provider, error) {
|
||||||
if err := config.IsValid(); err != nil {
|
if err := config.IsValid(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ func NewProvider(ctx context.Context, logger *slog.Logger, config config.Provide
|
|||||||
return nil, fmt.Errorf("unimplemented provider %s", config.Name)
|
return nil, fmt.Errorf("unimplemented provider %s", config.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WatchGroups(ctx context.Context, provider providers.Provider, frequency time.Duration, send chan<- map[string][]string, logger *slog.Logger) {
|
func WatchGroups(ctx context.Context, provider provider.Provider, frequency time.Duration, send chan<- map[string][]string, logger *slog.Logger) {
|
||||||
ticker := time.NewTicker(frequency)
|
ticker := time.NewTicker(frequency)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package mocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/pkg/tinykv"
|
"github.com/sablierapp/sablier/pkg/tinykv"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
@@ -16,7 +16,7 @@ type ProviderMock struct {
|
|||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
|
||||||
providers.Provider
|
provider.Provider
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"github.com/sablierapp/sablier/pkg/store"
|
"github.com/sablierapp/sablier/pkg/store"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -15,7 +16,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockgen -package sessionstest -source=sessions_manager.go -destination=sessionstest/mocks_sessions_manager.go *
|
//go:generate mockgen -package sessionstest -source=sessions_manager.go -destination=sessionstest/mocks_sessions_manager.go *
|
||||||
@@ -35,13 +35,13 @@ type Manager interface {
|
|||||||
|
|
||||||
type SessionsManager struct {
|
type SessionsManager struct {
|
||||||
store store.Store
|
store store.Store
|
||||||
provider providers.Provider
|
provider provider.Provider
|
||||||
groups map[string][]string
|
groups map[string][]string
|
||||||
|
|
||||||
l *slog.Logger
|
l *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSessionsManager(logger *slog.Logger, store store.Store, provider providers.Provider) Manager {
|
func NewSessionsManager(logger *slog.Logger, store store.Store, provider provider.Provider) Manager {
|
||||||
sm := &SessionsManager{
|
sm := &SessionsManager{
|
||||||
store: store,
|
store: store,
|
||||||
provider: provider,
|
provider: provider,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ providers.Provider = (*DockerClassicProvider)(nil)
|
var _ provider.Provider = (*DockerClassicProvider)(nil)
|
||||||
|
|
||||||
type DockerClassicProvider struct {
|
type DockerClassicProvider struct {
|
||||||
Client client.APIClient
|
Client client.APIClient
|
||||||
@@ -5,13 +5,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/neilotoole/slogt"
|
"github.com/neilotoole/slogt"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider/mocks"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/events"
|
"github.com/docker/docker/api/types/events"
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers/mocks"
|
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ func TestDockerClassicProvider_NotifyInstanceStopped(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
provider := setupProvider(t, mocks.NewDockerAPIClientMockWithEvents(tt.events, tt.errors))
|
provider := setupProvider(t, mocks.NewDockerAPIClientMockWithEvents(tt.events, tt.errors))
|
||||||
|
|
||||||
instanceC := make(chan string, 1)
|
instanceC := make(chan string, 1)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
@@ -7,12 +7,12 @@ import (
|
|||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/types"
|
"github.com/sablierapp/sablier/app/types"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *DockerClassicProvider) InstanceList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (p *DockerClassicProvider) InstanceList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
args := filters.NewArgs()
|
args := filters.NewArgs()
|
||||||
for _, label := range options.Labels {
|
for _, label := range options.Labels {
|
||||||
args.Add("label", label)
|
args.Add("label", label)
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ providers.Provider = (*DockerSwarmProvider)(nil)
|
var _ provider.Provider = (*DockerSwarmProvider)(nil)
|
||||||
|
|
||||||
type DockerSwarmProvider struct {
|
type DockerSwarmProvider struct {
|
||||||
Client client.APIClient
|
Client client.APIClient
|
||||||
@@ -4,13 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/neilotoole/slogt"
|
"github.com/neilotoole/slogt"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider/mocks"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/events"
|
"github.com/docker/docker/api/types/events"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers/mocks"
|
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -7,13 +7,13 @@ import (
|
|||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/types"
|
"github.com/sablierapp/sablier/app/types"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *DockerSwarmProvider) InstanceList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (p *DockerSwarmProvider) InstanceList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
args := filters.NewArgs()
|
args := filters.NewArgs()
|
||||||
for _, label := range options.Labels {
|
for _, label := range options.Labels {
|
||||||
args.Add("label", label)
|
args.Add("label", label)
|
||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ providers.Provider = (*KubernetesProvider)(nil)
|
var _ provider.Provider = (*KubernetesProvider)(nil)
|
||||||
|
|
||||||
type Workload interface {
|
type Workload interface {
|
||||||
GetScale(ctx context.Context, workloadName string, options metav1.GetOptions) (*autoscalingv1.Scale, error)
|
GetScale(ctx context.Context, workloadName string, options metav1.GetOptions) (*autoscalingv1.Scale, error)
|
||||||
@@ -3,12 +3,12 @@ package kubernetes
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/neilotoole/slogt"
|
"github.com/neilotoole/slogt"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider/mocks"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers/mocks"
|
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
v1 "k8s.io/api/apps/v1"
|
v1 "k8s.io/api/apps/v1"
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
@@ -3,8 +3,8 @@ package kubernetes
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/sablierapp/sablier/app/discovery"
|
"github.com/sablierapp/sablier/app/discovery"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/types"
|
"github.com/sablierapp/sablier/app/types"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
v1 "k8s.io/api/apps/v1"
|
v1 "k8s.io/api/apps/v1"
|
||||||
core_v1 "k8s.io/api/core/v1"
|
core_v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *KubernetesProvider) InstanceList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (p *KubernetesProvider) InstanceList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
deployments, err := p.deploymentList(ctx, options)
|
deployments, err := p.deploymentList(ctx, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -27,7 +27,7 @@ func (p *KubernetesProvider) InstanceList(ctx context.Context, options providers
|
|||||||
return append(deployments, statefulSets...), nil
|
return append(deployments, statefulSets...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *KubernetesProvider) deploymentList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (p *KubernetesProvider) deploymentList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
deployments, err := p.Client.AppsV1().Deployments(core_v1.NamespaceAll).List(ctx, metav1.ListOptions{
|
deployments, err := p.Client.AppsV1().Deployments(core_v1.NamespaceAll).List(ctx, metav1.ListOptions{
|
||||||
LabelSelector: strings.Join(options.Labels, ","),
|
LabelSelector: strings.Join(options.Labels, ","),
|
||||||
})
|
})
|
||||||
@@ -82,7 +82,7 @@ func (p *KubernetesProvider) deploymentToInstance(d v1.Deployment) types.Instanc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *KubernetesProvider) statefulSetList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (p *KubernetesProvider) statefulSetList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
statefulSets, err := p.Client.AppsV1().StatefulSets(core_v1.NamespaceAll).List(ctx, metav1.ListOptions{
|
statefulSets, err := p.Client.AppsV1().StatefulSets(core_v1.NamespaceAll).List(ctx, metav1.ListOptions{
|
||||||
LabelSelector: strings.Join(options.Labels, ","),
|
LabelSelector: strings.Join(options.Labels, ","),
|
||||||
})
|
})
|
||||||
@@ -3,13 +3,13 @@ package mock
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/sablierapp/sablier/app/instance"
|
"github.com/sablierapp/sablier/app/instance"
|
||||||
"github.com/sablierapp/sablier/app/providers"
|
|
||||||
"github.com/sablierapp/sablier/app/types"
|
"github.com/sablierapp/sablier/app/types"
|
||||||
|
"github.com/sablierapp/sablier/pkg/provider"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ providers.Provider = (*ProviderMock)(nil)
|
var _ provider.Provider = (*ProviderMock)(nil)
|
||||||
|
|
||||||
// ProviderMock is a structure that allows to define the behavior of a Provider
|
// ProviderMock is a structure that allows to define the behavior of a Provider
|
||||||
type ProviderMock struct {
|
type ProviderMock struct {
|
||||||
@@ -32,7 +32,7 @@ func (m *ProviderMock) GetGroups(ctx context.Context) (map[string][]string, erro
|
|||||||
args := m.Called(ctx)
|
args := m.Called(ctx)
|
||||||
return args.Get(0).(map[string][]string), args.Error(1)
|
return args.Get(0).(map[string][]string), args.Error(1)
|
||||||
}
|
}
|
||||||
func (m *ProviderMock) InstanceList(ctx context.Context, options providers.InstanceListOptions) ([]types.Instance, error) {
|
func (m *ProviderMock) InstanceList(ctx context.Context, options provider.InstanceListOptions) ([]types.Instance, error) {
|
||||||
args := m.Called(ctx, options)
|
args := m.Called(ctx, options)
|
||||||
return args.Get(0).([]types.Instance), args.Error(1)
|
return args.Get(0).([]types.Instance), args.Error(1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package providers
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package providers
|
package provider
|
||||||
|
|
||||||
type InstanceListOptions struct {
|
type InstanceListOptions struct {
|
||||||
All bool
|
All bool
|
||||||
Reference in New Issue
Block a user