From b2a000850ebcc286725aaa3a4e2f724274c7119b Mon Sep 17 00:00:00 2001 From: lamai93 Date: Thu, 10 Jan 2019 12:01:15 +0100 Subject: [PATCH] Add option for different exporter docker image. --- .../deployment/v1alpha/deployment_spec.go | 8 ++++ pkg/apis/deployment/v1alpha/metrics_spec.go | 42 ++++++++++++++++++- .../v1alpha/zz_generated.deepcopy.go | 5 +++ pkg/deployment/resources/pod_creator.go | 5 +++ pkg/util/k8sutil/pods.go | 6 +-- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/pkg/apis/deployment/v1alpha/deployment_spec.go b/pkg/apis/deployment/v1alpha/deployment_spec.go index 0f75f78b9..b28a43fa5 100644 --- a/pkg/apis/deployment/v1alpha/deployment_spec.go +++ b/pkg/apis/deployment/v1alpha/deployment_spec.go @@ -180,6 +180,7 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) { s.Coordinators.SetDefaults(ServerGroupCoordinators, s.GetMode().HasCoordinators(), s.GetMode()) s.SyncMasters.SetDefaults(ServerGroupSyncMasters, s.Sync.IsEnabled(), s.GetMode()) s.SyncWorkers.SetDefaults(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode()) + s.Metrics.SetDefaults() s.Chaos.SetDefaults() } @@ -218,6 +219,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) { s.Coordinators.SetDefaultsFrom(source.Coordinators) s.SyncMasters.SetDefaultsFrom(source.SyncMasters) s.SyncWorkers.SetDefaultsFrom(source.SyncWorkers) + s.Metrics.SetDefaultsFrom(source.Metrics) s.Chaos.SetDefaultsFrom(source.Chaos) } @@ -272,6 +274,9 @@ func (s *DeploymentSpec) Validate() error { if err := s.SyncWorkers.Validate(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode(), s.GetEnvironment()); err != nil { return maskAny(err) } + if err := s.Metrics.Validate(); err != nil { + return maskAny(errors.Wrap(err, "spec.metrics")) + } if err := s.Chaos.Validate(); err != nil { return maskAny(errors.Wrap(err, "spec.chaos")) } @@ -333,5 +338,8 @@ func (s DeploymentSpec) ResetImmutableFields(target *DeploymentSpec) []string { if l := s.SyncWorkers.ResetImmutableFields(ServerGroupSyncWorkers, "syncworkers", &target.SyncWorkers); l != nil { resetFields = append(resetFields, l...) } + if l := s.Metrics.ResetImmutableFields("metrics", &target.Metrics); l != nil { + resetFields = append(resetFields, l...) + } return resetFields } diff --git a/pkg/apis/deployment/v1alpha/metrics_spec.go b/pkg/apis/deployment/v1alpha/metrics_spec.go index c1705a850..a1f4e819e 100644 --- a/pkg/apis/deployment/v1alpha/metrics_spec.go +++ b/pkg/apis/deployment/v1alpha/metrics_spec.go @@ -25,10 +25,50 @@ import "github.com/arangodb/kube-arangodb/pkg/util" // MetricsSpec contains spec for arangodb exporter type MetricsSpec struct { - Enabled *bool `json:"enabled,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Image *string `json:"image,omitempty"` + //Authentication struct { + // // JWTSecretName contains the name of the JWT kubernetes secret used for authentication + // JWTSecretName *string `json:"JWTSecretName,omitempty"` + //} `json:"authentication,omitempty"` } // IsEnabled returns whether metrics are enabled or not func (s *MetricsSpec) IsEnabled() bool { return util.BoolOrDefault(s.Enabled, false) } + +// HasImage returns whether a image was specified or not +func (s *MetricsSpec) HasImage() bool { + return s.Image != nil +} + +// GetImage returns the Image or empty string +func (s *MetricsSpec) GetImage() string { + return util.StringOrDefault(s.Image) +} + +// SetDefaults sets default values +func (s *MetricsSpec) SetDefaults() { + s.Enabled = util.NewBool(false) +} + +// SetDefaultsFrom fills unspecified fields with a value from given source spec. +func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) { + if s.Enabled == nil { + s.Enabled = util.NewBoolOrNil(source.Enabled) + } + if s.Image == nil { + s.Image = util.NewStringOrNil(source.Image) + } +} + +// Validate the given spec +func (s *MetricsSpec) Validate() error { + return nil +} + +// ResetImmutableFields replaces all immutable fields in the given target with values from the source spec. +func (s SyncSpec) ResetImmutableFields(fieldPrefix string, target *SyncSpec) []string { + return nil +} diff --git a/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go b/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go index 5036d291c..2b7109903 100644 --- a/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go @@ -534,6 +534,11 @@ func (in *MetricsSpec) DeepCopyInto(out *MetricsSpec) { *out = new(bool) **out = **in } + if in.Image != nil { + in, out := &in.Image, &out.Image + *out = new(string) + **out = **in + } return } diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 196a47670..30234a3d5 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -619,10 +619,15 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string, SecretName: spec.Authentication.GetJWTSecretName(), SecretKey: constants.SecretKeyToken, } + image := spec.GetImage() + if spec.Metrics.HasImage() { + image = spec.Metrics.GetImage() + } exporter = &k8sutil.ArangodbExporterContainerConf{ Args: createExporterArgs(), Env: env, LivenessProbe: createExporterLivenessProbe(), + Image: image, } } } diff --git a/pkg/util/k8sutil/pods.go b/pkg/util/k8sutil/pods.go index fbb04e06b..d417953da 100644 --- a/pkg/util/k8sutil/pods.go +++ b/pkg/util/k8sutil/pods.go @@ -336,7 +336,7 @@ func arangodbexporterContainer(image string, imagePullPolicy v1.PullPolicy, args c := v1.Container{ Command: append([]string{"/app/arangodb-exporter"}, args...), Name: ExporterContainerName, - Image: "arangodb/arangodb-exporter:0.1.3", + Image: image, ImagePullPolicy: v1.PullIfNotPresent, Ports: []v1.ContainerPort{ { @@ -352,7 +352,6 @@ func arangodbexporterContainer(image string, imagePullPolicy v1.PullPolicy, args if livenessProbe != nil { c.LivenessProbe = livenessProbe.Create() } - return c } @@ -442,6 +441,7 @@ type ArangodbExporterContainerConf struct { Args []string Env map[string]EnvValue LivenessProbe *HTTPProbeConfig + Image string } // CreateArangodPod creates a Pod that runs `arangod`. @@ -490,7 +490,7 @@ func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deploy // Add arangodb exporter container if exporter != nil { - c = arangodbexporterContainer(image, imagePullPolicy, exporter.Args, exporter.Env, exporter.LivenessProbe) + c = arangodbexporterContainer(exporter.Image, imagePullPolicy, exporter.Args, exporter.Env, exporter.LivenessProbe) p.Spec.Containers = append(p.Spec.Containers, c) }