Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Karasek committed Mar 13, 2023
1 parent c02e739 commit e741d93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 9 additions & 4 deletions pkg/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"
"errors"

"github.com/hasura/go-graphql-client"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"

"github.com/kubeshop/botkube/internal/graphql"
)

var (
Expand All @@ -26,6 +25,12 @@ var (
}
)

// GraphQLClient defines GraphQL client.
type GraphQLClient interface {
Client() *graphql.Client
DeploymentID() string
}

// ConfigPersistenceManager manages persistence of the configuration.
type ConfigPersistenceManager interface {
PersistSourceBindings(ctx context.Context, commGroupName string, platform CommPlatformIntegration, channelAlias string, sourceBindings []string) error
Expand All @@ -39,11 +44,11 @@ type ConfigPersistenceManager interface {
var ErrUnsupportedPlatform = errors.New("unsupported platform to persist data")

// NewManager creates a new PersistenceManager instance.
func NewManager(remoteCfgEnabled bool, log logrus.FieldLogger, cfg PersistentConfig, k8sCli kubernetes.Interface, gql *graphql.Gql) ConfigPersistenceManager {
func NewManager(remoteCfgEnabled bool, log logrus.FieldLogger, cfg PersistentConfig, k8sCli kubernetes.Interface, client GraphQLClient) ConfigPersistenceManager {
if remoteCfgEnabled {
return &RemoteConfigPersistenceManager{
log: log,
gql: gql,
gql: client,
}
}
return &LocalConfigPersistenceManager{
Expand Down
12 changes: 5 additions & 7 deletions pkg/config/manager_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (

"github.com/hasura/go-graphql-client"
"github.com/sirupsen/logrus"

gql "github.com/kubeshop/botkube/internal/graphql"
)

// RemotePersistenceManager manages persistence of the configuration.
type RemoteConfigPersistenceManager struct {
log logrus.FieldLogger
gql *gql.Gql
gql GraphQLClient
resourceVersion int
resVerMutex sync.RWMutex
}
Expand Down Expand Up @@ -45,7 +43,7 @@ func (m *RemoteConfigPersistenceManager) PersistNotificationsEnabled(ctx context
Success bool `graphql:"patchDeploymentConfig(id: $id, input: $input)"`
}
variables := map[string]interface{}{
"id": graphql.ID(m.gql.DeploymentID),
"id": graphql.ID(m.gql.DeploymentID()),
"input": PatchDeploymentConfigInput{
ResourceVersion: m.getResourceVersion(),
Notification: &NotificationPatchDeploymentConfigInput{
Expand All @@ -57,7 +55,7 @@ func (m *RemoteConfigPersistenceManager) PersistNotificationsEnabled(ctx context
},
}

return m.gql.Cli.Mutate(ctx, &mutation, variables)
return m.gql.Client().Mutate(ctx, &mutation, variables)
}

func (m *RemoteConfigPersistenceManager) PersistSourceBindings(ctx context.Context, commGroupName string, platform CommPlatformIntegration, channelAlias string, sourceBindings []string) error {
Expand All @@ -83,7 +81,7 @@ func (m *RemoteConfigPersistenceManager) PersistSourceBindings(ctx context.Conte
Success bool `graphql:"patchDeploymentConfig(id: $id, input: $input)"`
}
variables := map[string]interface{}{
"id": graphql.ID(m.gql.DeploymentID),
"id": graphql.ID(m.gql.DeploymentID()),
"input": PatchDeploymentConfigInput{
ResourceVersion: m.getResourceVersion(),
SourceBinding: &SourceBindingPatchDeploymentConfigInput{
Expand All @@ -95,7 +93,7 @@ func (m *RemoteConfigPersistenceManager) PersistSourceBindings(ctx context.Conte
},
}

return m.gql.Cli.Mutate(ctx, &mutation, variables)
return m.gql.Client().Mutate(ctx, &mutation, variables)
}

func (m *RemoteConfigPersistenceManager) PersistFilterEnabled(ctx context.Context, name string, enabled bool) error {
Expand Down

0 comments on commit e741d93

Please sign in to comment.