Skip to content

Commit 523e1a3

Browse files
informalictajanikow
authored andcommitted
Feature/resource requirements in sidecars (#505)
1 parent 5435cb5 commit 523e1a3

25 files changed

+917
-635
lines changed

pkg/apis/deployment/v1/deployment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type ArangoDeployment struct {
4949
Status DeploymentStatus `json:"status"`
5050
}
5151

52+
type ServerGroupFunc func(ServerGroup, ServerGroupSpec, *MemberStatusList) error
53+
5254
// AsOwner creates an OwnerReference for the given deployment
5355
func (d *ArangoDeployment) AsOwner() metav1.OwnerReference {
5456
trueVar := true
@@ -67,7 +69,7 @@ func (d *ArangoDeployment) AsOwner() metav1.OwnerReference {
6769
// If the callback returns an error, this error is returned and no other server
6870
// groups are processed.
6971
// Groups are processed in this order: agents, single, dbservers, coordinators, syncmasters, syncworkers
70-
func (d *ArangoDeployment) ForeachServerGroup(cb func(group ServerGroup, spec ServerGroupSpec, status *MemberStatusList) error, status *DeploymentStatus) error {
72+
func (d *ArangoDeployment) ForeachServerGroup(cb ServerGroupFunc, status *DeploymentStatus) error {
7173
if status == nil {
7274
status = &d.Status
7375
}

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type DeploymentSpec struct {
7070
Sync SyncSpec `json:"sync"`
7171
License LicenseSpec `json:"license"`
7272
Metrics MetricsSpec `json:"metrics"`
73+
Lifecycle LifecycleSpec `json:"lifecycle,omitempty"`
7374

7475
Single ServerGroupSpec `json:"single"`
7576
Agents ServerGroupSpec `json:"agents"`
@@ -278,6 +279,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
278279
s.SyncMasters.SetDefaultsFrom(source.SyncMasters)
279280
s.SyncWorkers.SetDefaultsFrom(source.SyncWorkers)
280281
s.Metrics.SetDefaultsFrom(source.Metrics)
282+
s.Lifecycle.SetDefaultsFrom(source.Lifecycle)
281283
s.Chaos.SetDefaultsFrom(source.Chaos)
282284
s.Bootstrap.SetDefaultsFrom(source.Bootstrap)
283285
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2019 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+
// Author Tomasz Mielech <tomasz@arangodb.com>
21+
//
22+
23+
package v1
24+
25+
import (
26+
v1 "k8s.io/api/core/v1"
27+
)
28+
29+
type LifecycleSpec struct {
30+
Resources v1.ResourceRequirements `json:"resources,omitempty"`
31+
}
32+
33+
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
34+
func (s *LifecycleSpec) SetDefaultsFrom(source LifecycleSpec) {
35+
setDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits)
36+
setDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests)
37+
}

pkg/apis/deployment/v1/metrics_spec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package v1
2424
import (
2525
"github.com/arangodb/kube-arangodb/pkg/util"
2626
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
27+
v1 "k8s.io/api/core/v1"
2728
)
2829

2930
// MetricsAuthenticationSpec contains spec for authentication with arangodb
@@ -37,6 +38,7 @@ type MetricsSpec struct {
3738
Enabled *bool `json:"enabled,omitempty"`
3839
Image *string `json:"image,omitempty"`
3940
Authentication MetricsAuthenticationSpec `json:"authentication,omitempty"`
41+
Resources v1.ResourceRequirements `json:"resources,omitempty"`
4042
}
4143

4244
// IsEnabled returns whether metrics are enabled or not
@@ -85,6 +87,8 @@ func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) {
8587
if s.Authentication.JWTTokenSecretName == nil {
8688
s.Authentication.JWTTokenSecretName = util.NewStringOrNil(source.Authentication.JWTTokenSecretName)
8789
}
90+
setDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits)
91+
setDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests)
8892
}
8993

9094
// Validate the given spec

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

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

pkg/apis/deployment/v1alpha/deployment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type ArangoDeployment struct {
4949
Status DeploymentStatus `json:"status"`
5050
}
5151

52+
type ServerGroupFunc func(ServerGroup, ServerGroupSpec, *MemberStatusList) error
53+
5254
// AsOwner creates an OwnerReference for the given deployment
5355
func (d *ArangoDeployment) AsOwner() metav1.OwnerReference {
5456
trueVar := true
@@ -67,7 +69,7 @@ func (d *ArangoDeployment) AsOwner() metav1.OwnerReference {
6769
// If the callback returns an error, this error is returned and no other server
6870
// groups are processed.
6971
// Groups are processed in this order: agents, single, dbservers, coordinators, syncmasters, syncworkers
70-
func (d *ArangoDeployment) ForeachServerGroup(cb func(group ServerGroup, spec ServerGroupSpec, status *MemberStatusList) error, status *DeploymentStatus) error {
72+
func (d *ArangoDeployment) ForeachServerGroup(cb ServerGroupFunc, status *DeploymentStatus) error {
7173
if status == nil {
7274
status = &d.Status
7375
}

pkg/apis/deployment/v1alpha/deployment_spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type DeploymentSpec struct {
7070
Sync SyncSpec `json:"sync"`
7171
License LicenseSpec `json:"license"`
7272
Metrics MetricsSpec `json:"metrics"`
73+
Lifecycle LifecycleSpec `json:"lifecycle,omitempty"`
7374

7475
Single ServerGroupSpec `json:"single"`
7576
Agents ServerGroupSpec `json:"agents"`
@@ -278,6 +279,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
278279
s.SyncMasters.SetDefaultsFrom(source.SyncMasters)
279280
s.SyncWorkers.SetDefaultsFrom(source.SyncWorkers)
280281
s.Metrics.SetDefaultsFrom(source.Metrics)
282+
s.Lifecycle.SetDefaultsFrom(source.Lifecycle)
281283
s.Chaos.SetDefaultsFrom(source.Chaos)
282284
s.Bootstrap.SetDefaultsFrom(source.Bootstrap)
283285
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2019 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+
// Author Tomasz Mielech <tomasz@arangodb.com>
21+
//
22+
23+
package v1alpha
24+
25+
import (
26+
v1 "k8s.io/api/core/v1"
27+
)
28+
29+
type LifecycleSpec struct {
30+
Resources v1.ResourceRequirements `json:"resources,omitempty"`
31+
}
32+
33+
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
34+
func (s *LifecycleSpec) SetDefaultsFrom(source LifecycleSpec) {
35+
setDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits)
36+
setDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests)
37+
}

pkg/apis/deployment/v1alpha/metrics_spec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package v1alpha
2424
import (
2525
"github.com/arangodb/kube-arangodb/pkg/util"
2626
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
27+
v1 "k8s.io/api/core/v1"
2728
)
2829

2930
// MetricsAuthenticationSpec contains spec for authentication with arangodb
@@ -37,6 +38,7 @@ type MetricsSpec struct {
3738
Enabled *bool `json:"enabled,omitempty"`
3839
Image *string `json:"image,omitempty"`
3940
Authentication MetricsAuthenticationSpec `json:"authentication,omitempty"`
41+
Resources v1.ResourceRequirements `json:"resources,omitempty"`
4042
}
4143

4244
// IsEnabled returns whether metrics are enabled or not
@@ -85,6 +87,8 @@ func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) {
8587
if s.Authentication.JWTTokenSecretName == nil {
8688
s.Authentication.JWTTokenSecretName = util.NewStringOrNil(source.Authentication.JWTTokenSecretName)
8789
}
90+
setDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits)
91+
setDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests)
8892
}
8993

9094
// Validate the given spec

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

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

0 commit comments

Comments
 (0)