Skip to content

Commit

Permalink
[Feature] [Scheduler] Helm Driver Param (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Nov 7, 2024
1 parent 52087c1 commit a09403d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- (Feature) StorageV2 Integration Service Implementation
- (Feature) (Platform) Storage V1Alpha1 RC
- (Feature) (Networking) ArangoRotue WebSocket Support
- (Feature) (Scheduler) Helm Driver Param

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
4 changes: 4 additions & 0 deletions pkg/integrations/scheduler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

pbImplSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2"
pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
Expand All @@ -42,6 +43,7 @@ func init() {

type schedulerV2 struct {
Configuration pbImplSchedulerV2.Configuration
Driver string
}

func (b *schedulerV2) Name() string {
Expand All @@ -56,6 +58,7 @@ func (b *schedulerV2) Register(cmd *cobra.Command, fs FlagEnvHandler) error {
return errors.Errors(
fs.StringVar(&b.Configuration.Namespace, "namespace", constants.NamespaceWithDefault("default"), "Kubernetes Namespace"),
fs.StringVar(&b.Configuration.Deployment, "deployment", "", "ArangoDeployment Name"),
fs.StringVar(&b.Driver, "driver", string(helm.ConfigurationDriverSecret), "Helm Driver"),
)
}

Expand All @@ -68,6 +71,7 @@ func (b *schedulerV2) Handler(ctx context.Context, cmd *cobra.Command) (svc.Hand
helm, err := helm.NewClient(helm.Configuration{
Namespace: b.Configuration.Namespace,
Client: client,
Driver: (*helm.ConfigurationDriver)(util.NewType(b.Driver)),
})
if err != nil {
return nil, errors.Wrapf(err, "Unable to create Helm Client")
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/k8sutil/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (

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

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

var helm action.Configuration

if err := helm.Init(kclient.NewRESTClientGetter(tests.FakeNamespace, nil, cfg.Client.Config()), cfg.Namespace, "configmap", func(format string, v ...interface{}) {
if err := helm.Init(kclient.NewRESTClientGetter(cfg.Namespace, nil, cfg.Client.Config()), cfg.Namespace, string(cfg.Driver.Get()), func(format string, v ...interface{}) {
logger.Debug(format, v...)
}); err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/k8sutil/helm/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Configuration struct {
Namespace string

Client kclient.Client

Driver *ConfigurationDriver
}

func (c *Configuration) Validate() error {
Expand All @@ -44,5 +46,9 @@ func (c *Configuration) Validate() error {
return errors.Errorf("Namespace cannot be empty")
}

if err := c.Driver.Validate(); err != nil {
return err
}

return nil
}
48 changes: 48 additions & 0 deletions pkg/util/k8sutil/helm/configuration_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// DISCLAIMER
//
// Copyright 2024 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package helm

import "github.com/arangodb/kube-arangodb/pkg/util/errors"

type ConfigurationDriver string

const (
ConfigurationDriverDefault = ConfigurationDriverSecret
ConfigurationDriverConfigMap ConfigurationDriver = "configmap"
ConfigurationDriverSecret ConfigurationDriver = "secret"
)

func (c *ConfigurationDriver) Validate() error {
switch v := c.Get(); v {
case ConfigurationDriverConfigMap, ConfigurationDriverSecret:
return nil
default:
return errors.Errorf("Unknown option: %s", v)
}
}

func (c *ConfigurationDriver) Get() ConfigurationDriver {
if c == nil {
return ConfigurationDriverDefault
}

return *c
}
20 changes: 0 additions & 20 deletions pkg/util/kclient/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
package kclient

import (
"time"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
Expand All @@ -34,24 +32,6 @@ import (
// RESTClientOption is a function that can be used to set the RESTClientOptions of a HelmClient.
type RESTClientOption func(*rest.Config)

// Timeout specifies the timeout for a RESTClient as a RESTClientOption.
// The default (if unspecified) is 32 seconds.
// See [1] for reference.
// [^1]: https://github.com/kubernetes/client-go/blob/c6bd30b9ec5f668df191bc268c6f550c37726edb/discovery/discovery_client.go#L52
func Timeout(d time.Duration) RESTClientOption {
return func(r *rest.Config) {
r.Timeout = d
}
}

// Maximum burst for throttle
// the created RESTClient will use DefaultBurst: 100.
func Burst(v int) RESTClientOption {
return func(r *rest.Config) {
r.Burst = v
}
}

// RESTClientGetter defines the values of a helm REST client.
type RESTClientGetter struct {
namespace string
Expand Down

0 comments on commit a09403d

Please sign in to comment.