@@ -24,7 +24,6 @@ package v1alpha
2424import (
2525 "github.com/arangodb/kube-arangodb/pkg/util"
2626 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
27- "github.com/pkg/errors"
2827)
2928
3029// MetricsAuthenticationSpec contains spec for authentication with arangodb
@@ -33,44 +32,11 @@ type MetricsAuthenticationSpec struct {
3332 JWTTokenSecretName * string `json:"jwtTokenSecretName,omitempty"`
3433}
3534
36- // MetricsMonitorResourceMode specifies the type of ServiceMonitor resource to be installed
37- type MetricsMonitorResourceMode string
38-
39- const (
40- // MetricsMonitorResourceModeAuto detects if the CRD for ServiceMonitor is available and creates the resource if so (default)
41- MetricsMonitorResourceModeAuto MetricsMonitorResourceMode = "Auto"
42- // MetricsMonitorResourceModeNone never creates the resource
43- MetricsMonitorResourceModeNone MetricsMonitorResourceMode = "None"
44- // MetricsMonitorResourceModeAlways always creates the resource and fails if the CRD is not available
45- MetricsMonitorResourceModeAlways MetricsMonitorResourceMode = "Always"
46- )
47-
48- // IsAuto returns true if mode is MetricsMonitorResourceModeAuto
49- func (t MetricsMonitorResourceMode ) IsAuto () bool {
50- return t == MetricsMonitorResourceModeAuto
51- }
52-
53- // IsNone returns true if mode is MetricsMonitorResourceModeNone
54- func (t MetricsMonitorResourceMode ) IsNone () bool {
55- return t == MetricsMonitorResourceModeNone
56- }
57-
58- // IsAlways returns true if mode is MetricsMonitorResourceModeAlways
59- func (t MetricsMonitorResourceMode ) IsAlways () bool {
60- return t == MetricsMonitorResourceModeAlways
61- }
62-
63- // MetricsPrometheusSpec contains metrics for prometheus
64- type MetricsPrometheusSpec struct {
65- MonitorResource * MetricsMonitorResourceMode `json:"monitorResource,omitempty"`
66- }
67-
6835// MetricsSpec contains spec for arangodb exporter
6936type MetricsSpec struct {
7037 Enabled * bool `json:"enabled,omitempty"`
7138 Image * string `json:"image,omitempty"`
7239 Authentication MetricsAuthenticationSpec `json:"authentication,omitempty"`
73- Prometheus MetricsPrometheusSpec `json:"prometheus,omitempty"`
7440}
7541
7642// IsEnabled returns whether metrics are enabled or not
@@ -96,7 +62,6 @@ func (s *MetricsSpec) SetDefaults(defaultTokenName string, isAuthenticated bool)
9662 if s .GetJWTTokenSecretName () == "" {
9763 s .Authentication .JWTTokenSecretName = util .NewString (defaultTokenName )
9864 }
99- s .Prometheus .SetDefaults ()
10065}
10166
10267// GetJWTTokenSecretName returns the token secret name or empty string
@@ -120,7 +85,6 @@ func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) {
12085 if s .Authentication .JWTTokenSecretName == nil {
12186 s .Authentication .JWTTokenSecretName = util .NewStringOrNil (source .Authentication .JWTTokenSecretName )
12287 }
123- s .Prometheus .SetDefaultsFrom (source .Prometheus )
12488}
12589
12690// Validate the given spec
@@ -132,73 +96,10 @@ func (s *MetricsSpec) Validate() error {
13296 }
13397 }
13498
135- if err := s .Prometheus .Validate (); err != nil {
136- return err
137- }
138-
13999 return nil
140100}
141101
142102// ResetImmutableFields replaces all immutable fields in the given target with values from the source spec.
143103func (s MetricsSpec ) ResetImmutableFields (fieldPrefix string , target * MetricsSpec ) []string {
144104 return nil
145105}
146-
147- // SetDefaults sets default values
148- func (p * MetricsPrometheusSpec ) SetDefaults () {
149- }
150-
151- // SetDefaultsFrom fills unspecified fields with a value from given source spec.
152- func (p * MetricsPrometheusSpec ) SetDefaultsFrom (source MetricsPrometheusSpec ) {
153- if p .MonitorResource == nil {
154- p .MonitorResource = NewMetricsMonitorResourceModeOrNil (source .MonitorResource )
155- }
156- }
157-
158- // Validate the given spec
159- func (p * MetricsPrometheusSpec ) Validate () error {
160- if p .MonitorResource != nil {
161- return p .MonitorResource .Validate ()
162- }
163- return nil
164- }
165-
166- // Validate the given spec
167- func (t MetricsMonitorResourceMode ) Validate () error {
168- switch t {
169- case MetricsMonitorResourceModeAuto , MetricsMonitorResourceModeNone , MetricsMonitorResourceModeAlways :
170- return nil
171- default :
172- return maskAny (errors .Wrapf (ValidationError , "Unknown monitor resource mode: '%s'" , string (t )))
173- }
174- }
175-
176- // NewMetricsMonitorResourceMode returns a reference to a string with given value.
177- func NewMetricsMonitorResourceMode (input MetricsMonitorResourceMode ) * MetricsMonitorResourceMode {
178- return & input
179- }
180-
181- // NewMetricsMonitorResourceModeOrNil returns nil if input is nil, otherwise returns a clone of the given value.
182- func NewMetricsMonitorResourceModeOrNil (input * MetricsMonitorResourceMode ) * MetricsMonitorResourceMode {
183- if input == nil {
184- return nil
185- }
186-
187- return NewMetricsMonitorResourceMode (* input )
188- }
189-
190- // MetricsMonitorResourceModeOrDefault returns the default value (or empty string) if input is nil, otherwise returns the referenced value.
191- func MetricsMonitorResourceModeOrDefault (input * MetricsMonitorResourceMode , defaultValue ... MetricsMonitorResourceMode ) MetricsMonitorResourceMode {
192- if input == nil {
193- if len (defaultValue ) > 0 {
194- return defaultValue [0 ]
195- }
196- return ""
197- }
198- return * input
199- }
200-
201- // GetMode returns the given mode or the default value if it is nil
202- func (t * MetricsMonitorResourceMode ) GetMode () MetricsMonitorResourceMode {
203- return MetricsMonitorResourceModeOrDefault (t , MetricsMonitorResourceModeAuto )
204- }
0 commit comments