From a09403d4c2a1b7b44efce9f6e94804d4557e0b7e Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:30:32 +0100 Subject: [PATCH] [Feature] [Scheduler] Helm Driver Param (#1760) --- CHANGELOG.md | 1 + pkg/integrations/scheduler_v2.go | 4 ++ pkg/util/k8sutil/helm/client.go | 3 +- pkg/util/k8sutil/helm/configuration.go | 6 +++ pkg/util/k8sutil/helm/configuration_driver.go | 48 +++++++++++++++++++ pkg/util/kclient/rest.go | 20 -------- 6 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 pkg/util/k8sutil/helm/configuration_driver.go diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3ef40f3..c742cf5ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/integrations/scheduler_v2.go b/pkg/integrations/scheduler_v2.go index 452dd7438..b610c86b4 100644 --- a/pkg/integrations/scheduler_v2.go +++ b/pkg/integrations/scheduler_v2.go @@ -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" @@ -42,6 +43,7 @@ func init() { type schedulerV2 struct { Configuration pbImplSchedulerV2.Configuration + Driver string } func (b *schedulerV2) Name() string { @@ -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"), ) } @@ -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") diff --git a/pkg/util/k8sutil/helm/client.go b/pkg/util/k8sutil/helm/client.go index ab9cbaa0a..40ca7d1be 100644 --- a/pkg/util/k8sutil/helm/client.go +++ b/pkg/util/k8sutil/helm/client.go @@ -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) { @@ -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 diff --git a/pkg/util/k8sutil/helm/configuration.go b/pkg/util/k8sutil/helm/configuration.go index 7511e4295..c01833d08 100644 --- a/pkg/util/k8sutil/helm/configuration.go +++ b/pkg/util/k8sutil/helm/configuration.go @@ -29,6 +29,8 @@ type Configuration struct { Namespace string Client kclient.Client + + Driver *ConfigurationDriver } func (c *Configuration) Validate() error { @@ -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 } diff --git a/pkg/util/k8sutil/helm/configuration_driver.go b/pkg/util/k8sutil/helm/configuration_driver.go new file mode 100644 index 000000000..87db1645b --- /dev/null +++ b/pkg/util/k8sutil/helm/configuration_driver.go @@ -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 +} diff --git a/pkg/util/kclient/rest.go b/pkg/util/kclient/rest.go index 2117cddac..3340d0baa 100644 --- a/pkg/util/kclient/rest.go +++ b/pkg/util/kclient/rest.go @@ -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" @@ -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