1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] [Scheduler] Helm Driver Param (#1760)

This commit is contained in:
Adam Janikowski 2024-11-07 12:30:32 +01:00 committed by GitHub
parent 52087c1546
commit a09403d4c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 60 additions and 22 deletions

View file

@ -16,6 +16,7 @@
- (Feature) StorageV2 Integration Service Implementation - (Feature) StorageV2 Integration Service Implementation
- (Feature) (Platform) Storage V1Alpha1 RC - (Feature) (Platform) Storage V1Alpha1 RC
- (Feature) (Networking) ArangoRotue WebSocket Support - (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) ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD - (Feature) ArangoRoute CRD

View file

@ -27,6 +27,7 @@ import (
pbImplSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2" pbImplSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2"
pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition" 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/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
@ -42,6 +43,7 @@ func init() {
type schedulerV2 struct { type schedulerV2 struct {
Configuration pbImplSchedulerV2.Configuration Configuration pbImplSchedulerV2.Configuration
Driver string
} }
func (b *schedulerV2) Name() string { func (b *schedulerV2) Name() string {
@ -56,6 +58,7 @@ func (b *schedulerV2) Register(cmd *cobra.Command, fs FlagEnvHandler) error {
return errors.Errors( return errors.Errors(
fs.StringVar(&b.Configuration.Namespace, "namespace", constants.NamespaceWithDefault("default"), "Kubernetes Namespace"), fs.StringVar(&b.Configuration.Namespace, "namespace", constants.NamespaceWithDefault("default"), "Kubernetes Namespace"),
fs.StringVar(&b.Configuration.Deployment, "deployment", "", "ArangoDeployment Name"), fs.StringVar(&b.Configuration.Deployment, "deployment", "", "ArangoDeployment Name"),
fs.StringVar(&b.Driver, "driver", string(helm.ConfigurationDriverSecret), "Helm Driver"),
) )
} }
@ -68,6 +71,7 @@ func (b *schedulerV2) Handler(ctx context.Context, cmd *cobra.Command) (svc.Hand
helm, err := helm.NewClient(helm.Configuration{ helm, err := helm.NewClient(helm.Configuration{
Namespace: b.Configuration.Namespace, Namespace: b.Configuration.Namespace,
Client: client, Client: client,
Driver: (*helm.ConfigurationDriver)(util.NewType(b.Driver)),
}) })
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "Unable to create Helm Client") return nil, errors.Wrapf(err, "Unable to create Helm Client")

View file

@ -39,7 +39,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/kclient" "github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/arangodb/kube-arangodb/pkg/util/tests"
) )
func NewClient(cfg Configuration) (Client, error) { func NewClient(cfg Configuration) (Client, error) {
@ -49,7 +48,7 @@ func NewClient(cfg Configuration) (Client, error) {
var helm action.Configuration 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...) logger.Debug(format, v...)
}); err != nil { }); err != nil {
return nil, err return nil, err

View file

@ -29,6 +29,8 @@ type Configuration struct {
Namespace string Namespace string
Client kclient.Client Client kclient.Client
Driver *ConfigurationDriver
} }
func (c *Configuration) Validate() error { func (c *Configuration) Validate() error {
@ -44,5 +46,9 @@ func (c *Configuration) Validate() error {
return errors.Errorf("Namespace cannot be empty") return errors.Errorf("Namespace cannot be empty")
} }
if err := c.Driver.Validate(); err != nil {
return err
}
return nil return nil
} }

View file

@ -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
}

View file

@ -21,8 +21,6 @@
package kclient package kclient
import ( import (
"time"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery" "k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory" "k8s.io/client-go/discovery/cached/memory"
@ -34,24 +32,6 @@ import (
// RESTClientOption is a function that can be used to set the RESTClientOptions of a HelmClient. // RESTClientOption is a function that can be used to set the RESTClientOptions of a HelmClient.
type RESTClientOption func(*rest.Config) 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. // RESTClientGetter defines the values of a helm REST client.
type RESTClientGetter struct { type RESTClientGetter struct {
namespace string namespace string