Skip to content

Commit 58205a3

Browse files
author
lamai93
committed
Merge remote-tracking branch 'origin/master' into feature/volume-claim-templates
2 parents 105e9a6 + 1c75b2a commit 58205a3

File tree

17 files changed

+7612
-11806
lines changed

17 files changed

+7612
-11806
lines changed

dashboard/package-lock.json

Lines changed: 7174 additions & 11772 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"semantic-ui-react": "^0.81.3"
1616
},
1717
"devDependencies": {
18-
"react-scripts": "^2.1.3"
18+
"react-scripts": "^3.0.0"
1919
},
2020
"browserslist": "",
2121
"proxy": "https://192.168.140.212:8528",

pkg/apis/deployment/v1alpha/deployment_spec.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type DeploymentSpec struct {
6161
TLS TLSSpec `json:"tls"`
6262
Sync SyncSpec `json:"sync"`
6363
License LicenseSpec `json:"license"`
64+
Metrics MetricsSpec `json:"metrics"`
6465

6566
Single ServerGroupSpec `json:"single"`
6667
Agents ServerGroupSpec `json:"agents"`
@@ -189,6 +190,7 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
189190
s.Coordinators.SetDefaults(ServerGroupCoordinators, s.GetMode().HasCoordinators(), s.GetMode())
190191
s.SyncMasters.SetDefaults(ServerGroupSyncMasters, s.Sync.IsEnabled(), s.GetMode())
191192
s.SyncWorkers.SetDefaults(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode())
193+
s.Metrics.SetDefaults(deploymentName+"-exporter-jwt-token", s.Authentication.IsAuthenticated())
192194
s.Chaos.SetDefaults()
193195
s.Bootstrap.SetDefaults(deploymentName)
194196
}
@@ -228,6 +230,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
228230
s.Coordinators.SetDefaultsFrom(source.Coordinators)
229231
s.SyncMasters.SetDefaultsFrom(source.SyncMasters)
230232
s.SyncWorkers.SetDefaultsFrom(source.SyncWorkers)
233+
s.Metrics.SetDefaultsFrom(source.Metrics)
231234
s.Chaos.SetDefaultsFrom(source.Chaos)
232235
s.Bootstrap.SetDefaultsFrom(source.Bootstrap)
233236
}
@@ -283,6 +286,9 @@ func (s *DeploymentSpec) Validate() error {
283286
if err := s.SyncWorkers.Validate(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode(), s.GetEnvironment()); err != nil {
284287
return maskAny(err)
285288
}
289+
if err := s.Metrics.Validate(); err != nil {
290+
return maskAny(errors.Wrap(err, "spec.metrics"))
291+
}
286292
if err := s.Chaos.Validate(); err != nil {
287293
return maskAny(errors.Wrap(err, "spec.chaos"))
288294
}
@@ -352,5 +358,8 @@ func (s DeploymentSpec) ResetImmutableFields(target *DeploymentSpec) []string {
352358
if l := s.SyncWorkers.ResetImmutableFields(ServerGroupSyncWorkers, "syncworkers", &target.SyncWorkers); l != nil {
353359
resetFields = append(resetFields, l...)
354360
}
361+
if l := s.Metrics.ResetImmutableFields("metrics", &target.Metrics); l != nil {
362+
resetFields = append(resetFields, l...)
363+
}
355364
return resetFields
356365
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
//
21+
22+
package v1alpha
23+
24+
import (
25+
"github.com/arangodb/kube-arangodb/pkg/util"
26+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
27+
)
28+
29+
// MetricsAuthenticationSpec contains spec for authentication with arangodb
30+
type MetricsAuthenticationSpec struct {
31+
// JWTTokenSecretName contains the name of the JWT kubernetes secret used for authentication
32+
JWTTokenSecretName *string `json:"jwtTokenSecretName,omitempty"`
33+
}
34+
35+
// MetricsSpec contains spec for arangodb exporter
36+
type MetricsSpec struct {
37+
Enabled *bool `json:"enabled,omitempty"`
38+
Image *string `json:"image,omitempty"`
39+
Authentication MetricsAuthenticationSpec `json:"authentication,omitempty"`
40+
}
41+
42+
// IsEnabled returns whether metrics are enabled or not
43+
func (s *MetricsSpec) IsEnabled() bool {
44+
return util.BoolOrDefault(s.Enabled, false)
45+
}
46+
47+
// HasImage returns whether a image was specified or not
48+
func (s *MetricsSpec) HasImage() bool {
49+
return s.Image != nil
50+
}
51+
52+
// GetImage returns the Image or empty string
53+
func (s *MetricsSpec) GetImage() string {
54+
return util.StringOrDefault(s.Image)
55+
}
56+
57+
// SetDefaults sets default values
58+
func (s *MetricsSpec) SetDefaults(defaultTokenName string, isAuthenticated bool) {
59+
if s.Enabled == nil {
60+
s.Enabled = util.NewBool(false)
61+
}
62+
if s.GetJWTTokenSecretName() == "" {
63+
s.Authentication.JWTTokenSecretName = util.NewString(defaultTokenName)
64+
}
65+
}
66+
67+
// GetJWTTokenSecretName returns the token secret name or empty string
68+
func (s *MetricsSpec) GetJWTTokenSecretName() string {
69+
return util.StringOrDefault(s.Authentication.JWTTokenSecretName)
70+
}
71+
72+
// HasJWTTokenSecretName returns true if a secret name was specified
73+
func (s *MetricsSpec) HasJWTTokenSecretName() bool {
74+
return s.Authentication.JWTTokenSecretName != nil
75+
}
76+
77+
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
78+
func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) {
79+
if s.Enabled == nil {
80+
s.Enabled = util.NewBoolOrNil(source.Enabled)
81+
}
82+
if s.Image == nil {
83+
s.Image = util.NewStringOrNil(source.Image)
84+
}
85+
if s.Authentication.JWTTokenSecretName == nil {
86+
s.Authentication.JWTTokenSecretName = util.NewStringOrNil(source.Authentication.JWTTokenSecretName)
87+
}
88+
}
89+
90+
// Validate the given spec
91+
func (s *MetricsSpec) Validate() error {
92+
93+
if s.HasJWTTokenSecretName() {
94+
if err := k8sutil.ValidateResourceName(s.GetJWTTokenSecretName()); err != nil {
95+
return err
96+
}
97+
}
98+
99+
return nil
100+
}
101+
102+
// ResetImmutableFields replaces all immutable fields in the given target with values from the source spec.
103+
func (s MetricsSpec) ResetImmutableFields(fieldPrefix string, target *MetricsSpec) []string {
104+
return nil
105+
}

pkg/apis/deployment/v1alpha/server_group.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,13 @@ func (g ServerGroup) IsArangosync() bool {
130130
return false
131131
}
132132
}
133+
134+
// IsExportMetrics return true when the group can be used with the arangodbexporter
135+
func (g ServerGroup) IsExportMetrics() bool {
136+
switch g {
137+
case ServerGroupCoordinators, ServerGroupDBServers, ServerGroupSingle:
138+
return true
139+
default:
140+
return false
141+
}
142+
}

pkg/apis/deployment/v1alpha/server_group_spec.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type ServerGroupSpec struct {
6262
PriorityClassName string `json:"priorityClassName,omitempty"`
6363
// VolumeClaimTemplate specifies a template for volume claims
6464
VolumeClaimTemplate *v1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
65+
// Sidecars specifies a list of additional containers to be started
66+
Sidecars []v1.Container `json:"sidecars,omitempty"`
6567
}
6668

6769
// ServerGroupProbesSpec contains specification for probes for pods of the server group
@@ -86,6 +88,11 @@ type ServerGroupProbesSpec struct {
8688
// return s.ReadinessProbeOverride != nil
8789
// }
8890

91+
// GetSidecars returns a list of sidecars the use wish to add
92+
func (s ServerGroupSpec) GetSidecars() []v1.Container {
93+
return s.Sidecars
94+
}
95+
8996
// IsLivenessProbeDisabled returns true if liveness probes are disabled
9097
func (s ServerGroupProbesSpec) IsLivenessProbeDisabled() bool {
9198
return util.BoolOrDefault(s.LivenessProbeDisabled)

pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/images.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"time"
3131

3232
"github.com/rs/zerolog"
33-
"k8s.io/api/core/v1"
33+
v1 "k8s.io/api/core/v1"
3434
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3535
"k8s.io/client-go/kubernetes"
3636

@@ -198,7 +198,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
198198
}
199199
}
200200
if err := k8sutil.CreateArangodPod(ib.KubeCli, true, ib.APIObject, role, id, podName, "", image, "", "", ib.Spec.GetImagePullPolicy(), "", false, terminationGracePeriod, args, env, nil, nil, nil,
201-
tolerations, serviceAccountName, "", "", "", nil, "", v1.ResourceRequirements{}, nil); err != nil {
201+
tolerations, serviceAccountName, "", "", "", nil, "", v1.ResourceRequirements{}, nil, nil, nil); err != nil {
202202
log.Debug().Err(err).Msg("Failed to create image ID pod")
203203
return true, maskAny(err)
204204
}

pkg/deployment/reconcile/plan_builder.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,24 @@ func podNeedsRotation(log zerolog.Logger, p v1.Pod, apiObject metav1.Object, spe
343343
return false, "Server Image not found"
344344
}
345345

346+
if group.IsExportMetrics() {
347+
e, hasExporter := k8sutil.GetContainerByName(&p, k8sutil.ExporterContainerName)
348+
349+
if spec.Metrics.IsEnabled() {
350+
if !hasExporter {
351+
return true, "Exporter configuration changed"
352+
}
353+
354+
if spec.Metrics.HasImage() {
355+
if e.Image != spec.Metrics.GetImage() {
356+
return true, "Exporter image changed"
357+
}
358+
}
359+
} else if hasExporter {
360+
return true, "Exporter was disabled"
361+
}
362+
}
363+
346364
// Check arguments
347365
expectedArgs := strings.Join(context.GetExpectedPodArguments(apiObject, spec, group, status.Members.Agents, id, podImageInfo.ArangoDBVersion), " ")
348366
actualArgs := strings.Join(getContainerArgs(c), " ")

0 commit comments

Comments
 (0)