Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- (Maintenance) Fix CRD Generation and golangci version
- (Feature) (ML) Allow to use PlatformStorage
- (Maintenance) Bump Go Image to 1.22.11
- (Feature) Split Helm and KClient

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
6 changes: 3 additions & 3 deletions integrations/scheduler/v2/chart.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@ func (i *implementation) ListCharts(req *pbSchedulerV2.SchedulerV2ListChartsRequ
var ct string

for {
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).List(ctx, meta.ListOptions{
resp, err := i.kclient.Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).List(ctx, meta.ListOptions{
Limit: util.OptionalType(req.Items, 128),
Continue: ct,
})
Expand Down Expand Up @@ -67,7 +67,7 @@ func (i *implementation) ListCharts(req *pbSchedulerV2.SchedulerV2ListChartsRequ
}

func (i *implementation) GetChart(ctx context.Context, in *pbSchedulerV2.SchedulerV2GetChartRequest) (*pbSchedulerV2.SchedulerV2GetChartResponse, error) {
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).Get(ctx, in.GetName(), meta.GetOptions{})
resp, err := i.kclient.Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).Get(ctx, in.GetName(), meta.GetOptions{})
if err != nil {
logger.Err(err).Warn("Unable to run action: GetChart")
return nil, asGRPCError(err)
Expand Down
10 changes: 5 additions & 5 deletions integrations/scheduler/v2/chart_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,15 +43,15 @@ func Test_Chart_List(t *testing.T) {
ctx, c := context.WithCancel(context.Background())
defer c()

scheduler, h := InternalClient(t, ctx, func(c Configuration) Configuration {
scheduler, client, _ := InternalClient(t, ctx, func(c Configuration) Configuration {
c.Namespace = tests.FakeNamespace
c.Deployment = tests.FakeNamespace
return c
})

t.Run("Create Charts", func(t *testing.T) {
for i := 0; i < 1024; i++ {
_, err := h.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(tests.FakeNamespace).Create(context.Background(), &platformApi.ArangoPlatformChart{
_, err := client.Arango().PlatformV1alpha1().ArangoPlatformCharts(tests.FakeNamespace).Create(context.Background(), &platformApi.ArangoPlatformChart{
ObjectMeta: meta.ObjectMeta{
Name: fmt.Sprintf("chart-%05d", i),
Namespace: tests.FakeNamespace,
Expand Down Expand Up @@ -105,13 +105,13 @@ func Test_Chart_Get(t *testing.T) {
ctx, c := context.WithCancel(context.Background())
defer c()

scheduler, h := InternalClient(t, ctx, func(c Configuration) Configuration {
scheduler, client, _ := InternalClient(t, ctx, func(c Configuration) Configuration {
c.Namespace = tests.FakeNamespace
c.Deployment = tests.FakeNamespace
return c
})

z := h.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(tests.FakeNamespace)
z := client.Arango().PlatformV1alpha1().ArangoPlatformCharts(tests.FakeNamespace)

t1, err := z.Create(context.Background(), &platformApi.ArangoPlatformChart{
ObjectMeta: meta.ObjectMeta{
Expand Down
17 changes: 10 additions & 7 deletions integrations/scheduler/v2/implementation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -28,31 +28,34 @@ import (
pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/arangodb/kube-arangodb/pkg/util/svc"
)

var _ pbSchedulerV2.SchedulerV2Server = &implementation{}
var _ svc.Handler = &implementation{}

func New(client helm.Client, cfg Configuration) (svc.Handler, error) {
return newInternal(client, cfg)
func New(kclient kclient.Client, client helm.Client, cfg Configuration) (svc.Handler, error) {
return newInternal(kclient, client, cfg)
}

func newInternal(client helm.Client, c Configuration) (*implementation, error) {
func newInternal(kclient kclient.Client, client helm.Client, c Configuration) (*implementation, error) {
if err := c.Validate(); err != nil {
return nil, err
}

return &implementation{
cfg: c,
client: client,
cfg: c,
client: client,
kclient: kclient,
}, nil
}

type implementation struct {
cfg Configuration

client helm.Client
kclient kclient.Client
client helm.Client

pbSchedulerV2.UnimplementedSchedulerV2Server
}
Expand Down
19 changes: 10 additions & 9 deletions integrations/scheduler/v2/implementation_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,11 +34,12 @@ import (
pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/arangodb/kube-arangodb/pkg/util/tests"
"github.com/arangodb/kube-arangodb/pkg/util/tests/suite"
)

func cleanup(t *testing.T, c helm.Client) func() {
func cleanup(t *testing.T, client kclient.Client, c helm.Client) func() {
t.Run("Cleanup Pre", func(t *testing.T) {
items, err := c.List(context.Background(), func(in *action.List) {
in.All = true
Expand All @@ -54,14 +55,14 @@ func cleanup(t *testing.T, c helm.Client) func() {
}

t.Run("Remove NS", func(t *testing.T) {
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
if err := client.Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
}

for {
time.Sleep(time.Second)

if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
if _, err := client.Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
continue
}
Expand All @@ -71,7 +72,7 @@ func cleanup(t *testing.T, c helm.Client) func() {
})

t.Run("Create NS", func(t *testing.T) {
_, err = c.Client().Kubernetes().CoreV1().Namespaces().Create(context.Background(), &core.Namespace{
_, err = client.Kubernetes().CoreV1().Namespaces().Create(context.Background(), &core.Namespace{
ObjectMeta: meta.ObjectMeta{
Name: tests.FakeNamespace,
},
Expand All @@ -96,14 +97,14 @@ func cleanup(t *testing.T, c helm.Client) func() {
}

t.Run("Remove NS", func(t *testing.T) {
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
if err := client.Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
}

for {
time.Sleep(time.Second)

if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
if _, err := client.Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
continue
}
Expand All @@ -119,7 +120,7 @@ func Test_Implementation(t *testing.T) {
ctx, c := context.WithCancel(context.Background())
defer c()

scheduler, h := ExternalClient(t, ctx, func(c Configuration) Configuration {
scheduler, kc, h := ExternalClient(t, ctx, func(c Configuration) Configuration {
c.Namespace = tests.FakeNamespace
c.Deployment = tests.FakeNamespace
return c
Expand All @@ -130,7 +131,7 @@ func Test_Implementation(t *testing.T) {
})
require.NoError(t, err)

defer cleanup(t, h)()
defer cleanup(t, kc, h)()

t.Run("Alive", func(t *testing.T) {
_, err := scheduler.Alive(context.Background(), &pbSharedV1.Empty{})
Expand Down
4 changes: 2 additions & 2 deletions integrations/scheduler/v2/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,7 +112,7 @@ func (i *implementation) KubernetesPermissionCheck(ctx context.Context, in *pbSc
SubResource: in.GetSubResource(),
Name: in.GetName(),
Namespace: util.OptionalType(in.Namespace, i.client.Namespace()),
}.Verify(ctx, i.client.Client().Kubernetes())
}.Verify(ctx, i.kclient.Kubernetes())

var res pbSchedulerV2.SchedulerV2KubernetesPermissionCheckResponse

Expand Down
22 changes: 11 additions & 11 deletions integrations/scheduler/v2/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,32 +44,32 @@ func init() {
})
}

func Handler(t *testing.T, ctx context.Context, client helm.Client, mods ...Mod) svc.Handler {
handler, err := New(client, NewConfiguration().With(mods...))
func Handler(t *testing.T, ctx context.Context, kclient kclient.Client, client helm.Client, mods ...Mod) svc.Handler {
handler, err := New(kclient, client, NewConfiguration().With(mods...))
require.NoError(t, err)

return handler
}

func InternalClient(t *testing.T, ctx context.Context, mods ...Mod) (pbSchedulerV2.SchedulerV2Client, helm.Client) {
func InternalClient(t *testing.T, ctx context.Context, mods ...Mod) (pbSchedulerV2.SchedulerV2Client, kclient.Client, helm.Client) {
client := kclient.NewFakeClient()

h, err := helm.NewClient(helm.Configuration{
Namespace: tests.FakeNamespace,
Client: client,
Config: client.Config(),
})
require.NoError(t, err)

local := svc.NewService(svc.Configuration{
Address: "127.0.0.1:0",
}, Handler(t, ctx, h, mods...))
}, Handler(t, ctx, client, h, mods...))

start := local.Start(ctx)

return tgrpc.NewGRPCClient(t, ctx, pbSchedulerV2.NewSchedulerV2Client, start.Address()), h
return tgrpc.NewGRPCClient(t, ctx, pbSchedulerV2.NewSchedulerV2Client, start.Address()), client, h
}

func ExternalClient(t *testing.T, ctx context.Context, mods ...Mod) (pbSchedulerV2.SchedulerV2Client, helm.Client) {
func ExternalClient(t *testing.T, ctx context.Context, mods ...Mod) (pbSchedulerV2.SchedulerV2Client, kclient.Client, helm.Client) {
z, ok := os.LookupEnv("TEST_KUBECONFIG")
if !ok {
t.Skipf("TEST_KUBECONFIG is not set")
Expand All @@ -83,15 +83,15 @@ func ExternalClient(t *testing.T, ctx context.Context, mods ...Mod) (pbScheduler

h, err := helm.NewClient(helm.Configuration{
Namespace: tests.FakeNamespace,
Client: client,
Config: client.Config(),
})
require.NoError(t, err)

local := svc.NewService(svc.Configuration{
Address: "127.0.0.1:0",
}, Handler(t, ctx, h, mods...))
}, Handler(t, ctx, client, h, mods...))

start := local.Start(ctx)

return tgrpc.NewGRPCClient(t, ctx, pbSchedulerV2.NewSchedulerV2Client, start.Address()), h
return tgrpc.NewGRPCClient(t, ctx, pbSchedulerV2.NewSchedulerV2Client, start.Address()), client, h
}
6 changes: 3 additions & 3 deletions pkg/integrations/scheduler_v2.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,14 +70,14 @@ func (b *schedulerV2) Handler(ctx context.Context, cmd *cobra.Command) (svc.Hand

helm, err := helm.NewClient(helm.Configuration{
Namespace: b.Configuration.Namespace,
Client: client,
Config: client.Config(),
Driver: (*helm.ConfigurationDriver)(util.NewType(b.Driver)),
})
if err != nil {
return nil, errors.Wrapf(err, "Unable to create Helm Client")
}

return pbImplSchedulerV2.New(helm, b.Configuration)
return pbImplSchedulerV2.New(client, helm, b.Configuration)
}

func (*schedulerV2) Init(ctx context.Context, cmd *cobra.Command) error {
Expand Down
13 changes: 4 additions & 9 deletions pkg/util/k8sutil/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"k8s.io/client-go/util/flowcontrol"

"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/arangodb/kube-arangodb/pkg/util/kconfig"
)

func NewClient(cfg Configuration) (Client, error) {
Expand All @@ -48,13 +48,13 @@ func NewClient(cfg Configuration) (Client, error) {

var helm action.Configuration

if err := helm.Init(kclient.NewRESTClientGetter(cfg.Namespace, nil, cfg.Client.Config()), cfg.Namespace, string(cfg.Driver.Get()), func(format string, v ...interface{}) {
if err := helm.Init(kconfig.NewRESTClientGetter(cfg.Namespace, nil, cfg.Config), cfg.Namespace, string(cfg.Driver.Get()), func(format string, v ...interface{}) {
logger.Debug(format, v...)
}); err != nil {
return nil, err
}

dClient, err := discovery.NewDiscoveryClientForConfig(cfg.Client.Config())
dClient, err := discovery.NewDiscoveryClientForConfig(cfg.Config)
if err != nil {
return nil, err
}
Expand All @@ -69,7 +69,6 @@ func NewClient(cfg Configuration) (Client, error) {

type Client interface {
Namespace() string
Client() kclient.Client

Alive(ctx context.Context) error

Expand Down Expand Up @@ -103,10 +102,6 @@ func (c *client) Namespace() string {
return c.cfg.Namespace
}

func (c *client) Client() kclient.Client {
return c.cfg.Client
}

func (c *client) Status(ctx context.Context, name string, mods ...util.Mod[action.Status]) (*Release, error) {
act := action.NewStatus(c.helm)

Expand Down Expand Up @@ -334,7 +329,7 @@ func (c *client) restClientForApiVersion(gv schema.GroupVersion) (rest.Interface
return v, nil
}

configShallowCopy := *c.cfg.Client.Config()
configShallowCopy := *c.cfg.Config
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
Expand Down
Loading