Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable resource requirements for APIManager components #454

Merged
merged 5 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
356 changes: 356 additions & 0 deletions deploy/crds/apps.3scale.net_apimanagers_crd.yaml

Large diffs are not rendered by default.

50 changes: 49 additions & 1 deletion doc/apimanager-reference.md

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions doc/operator-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [PostgreSQL Installation](#postgresql-installation)
* [Enabling Pod Disruption Budgets](#enabling-pod-disruption-budgets)
* [Setting custom affinity and tolerations](#setting-custom-affinity-and-tolerations)
* [Setting custom compute resource requirements at component level](#setting-custom-compute-resource-requirements-at-component-level)
* [Enabling monitoring resources](operator-monitoring-resources.md)
* [Reconciliation](#reconciliation)
* [Upgrading 3scale](#upgrading-3scale)
Expand Down Expand Up @@ -442,6 +443,54 @@ spec:
See [APIManager reference](apimanager-reference.md) for a full list of
attributes related to affinity and tolerations.

#### Setting custom compute resource requirements at component level

Kubernetes [Compute Resource Requirements](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)
can be customized in a 3scale API Management solution through APIManager
CR attributes in order to customize compute resource requirements (this is, CPU
and Memory) assigned to a specific APIManager's component.

For example, setting custom compute resource requirements for system-master's
system-provider container, for backend-listener and for zync-database can be
done in the following way:

```yaml
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
name: example-apimanager
spec:
backend:
listenerSpec:
resources:
requests:
memory: "150Mi"
cpu: "300m"
limits:
memory: "500Mi"
cpu: "1000m"
system:
appSpec:
providerContainerResources:
requests:
memory: "111Mi"
cpu: "222m"
limits:
memory: "333Mi"
cpu: "444m"
zync:
databaseResources:
requests:
memory: "111Mi"
cpu: "222m"
limits:
memory: "333Mi"
cpu: "444m"
```

See [APIManager reference](apimanager-reference.md) for a full list of
attributes related to compute resource requirements.

### Reconciliation
After 3scale API Management solution has been installed, 3scale Operator enables updating a given set
of parameters from the custom resource in order to modify system configuration options.
Expand Down
12 changes: 12 additions & 0 deletions pkg/3scale/amp/operator/apicast_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func (a *ApicastOptionsProvider) setResourceRequirementsOptions() {
a.apicastOptions.ProductionResourceRequirements = v1.ResourceRequirements{}
a.apicastOptions.StagingResourceRequirements = v1.ResourceRequirements{}
}

// DeploymentConfig-level ResourceRequirements CR fields have priority over
// spec.resourceRequirementsEnabled, overwriting that setting when they are
// defined
if a.apimanager.Spec.Apicast.ProductionSpec.Resources != nil {
miguelsorianod marked this conversation as resolved.
Show resolved Hide resolved
a.apicastOptions.ProductionResourceRequirements = *a.apimanager.Spec.Apicast.ProductionSpec.Resources
}

if a.apimanager.Spec.Apicast.StagingSpec.Resources != nil {
a.apicastOptions.StagingResourceRequirements = *a.apimanager.Spec.Apicast.StagingSpec.Resources
}

}

func (a *ApicastOptionsProvider) setNodeAffinityAndTolerationsOptions() {
Expand Down
57 changes: 56 additions & 1 deletion pkg/3scale/amp/operator/apicast_options_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ func testApicastProductionTolerations() []v1.Toleration {
return getTestTolerations("apicast-production")
}

func testApicastStagingCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("123m"),
v1.ResourceMemory: resource.MustParse("456Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("789m"),
v1.ResourceMemory: resource.MustParse("111Mi"),
},
}
}

func testApicastProductionCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("222m"),
v1.ResourceMemory: resource.MustParse("333Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("444m"),
v1.ResourceMemory: resource.MustParse("555Mi"),
},
}
}

func basicApimanagerTestApicastOptions() *appsv1alpha1.APIManager {
tmpApicastManagementAPI := apicastManagementAPI
tmpOpenSSLVerify := openSSLVerify
Expand Down Expand Up @@ -139,7 +165,7 @@ func TestGetApicastOptionsProvider(t *testing.T) {
expectedOptionsFactory func() *component.ApicastOptions
}{
{"Default", basicApimanagerTestApicastOptions, defaultApicastOptions},
{"WithoutResourceRequirements",
{"WithGlobalResourceRequirementsDisabled",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestApicastOptions()
apimanager.Spec.ResourceRequirementsEnabled = &falseValue
Expand Down Expand Up @@ -180,6 +206,35 @@ func TestGetApicastOptionsProvider(t *testing.T) {
return opts
},
},
{"WithAPIcastCustomResourceRequirements",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestApicastOptions()
apimanager.Spec.Apicast.ProductionSpec.Resources = testApicastProductionCustomResourceRequirements()
apimanager.Spec.Apicast.StagingSpec.Resources = testApicastStagingCustomResourceRequirements()
return apimanager
},
func() *component.ApicastOptions {
opts := defaultApicastOptions()
opts.ProductionResourceRequirements = *testApicastProductionCustomResourceRequirements()
opts.StagingResourceRequirements = *testApicastStagingCustomResourceRequirements()
return opts
},
},
{"WithAPIcastCustomResourceRequirementsAndGlobalResourceRequirementsDisabled",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestApicastOptions()
apimanager.Spec.ResourceRequirementsEnabled = &falseValue
apimanager.Spec.Apicast.ProductionSpec.Resources = testApicastProductionCustomResourceRequirements()
apimanager.Spec.Apicast.StagingSpec.Resources = testApicastStagingCustomResourceRequirements()
return apimanager
},
func() *component.ApicastOptions {
opts := defaultApicastOptions()
opts.ProductionResourceRequirements = *testApicastProductionCustomResourceRequirements()
opts.StagingResourceRequirements = *testApicastStagingCustomResourceRequirements()
return opts
},
},
}

for _, tc := range cases {
Expand Down
13 changes: 13 additions & 0 deletions pkg/3scale/amp/operator/backend_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ func (o *OperatorBackendOptionsProvider) setResourceRequirementsOptions() {
o.backendOptions.WorkerResourceRequirements = v1.ResourceRequirements{}
o.backendOptions.CronResourceRequirements = v1.ResourceRequirements{}
}

// DeploymentConfig-level ResourceRequirements CR fields have priority over
// spec.resourceRequirementsEnabled, overwriting that setting when they are
// defined
if o.apimanager.Spec.Backend.ListenerSpec.Resources != nil {
miguelsorianod marked this conversation as resolved.
Show resolved Hide resolved
o.backendOptions.ListenerResourceRequirements = *o.apimanager.Spec.Backend.ListenerSpec.Resources
}
if o.apimanager.Spec.Backend.WorkerSpec.Resources != nil {
o.backendOptions.WorkerResourceRequirements = *o.apimanager.Spec.Backend.WorkerSpec.Resources
}
if o.apimanager.Spec.Backend.CronSpec.Resources != nil {
o.backendOptions.CronResourceRequirements = *o.apimanager.Spec.Backend.CronSpec.Resources
}
}

func (o *OperatorBackendOptionsProvider) setNodeAffinityAndTolerationsOptions() {
Expand Down
74 changes: 74 additions & 0 deletions pkg/3scale/amp/operator/backend_options_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,45 @@ func testBackendCronTolerations() []v1.Toleration {
return getTestTolerations("backend-cron")
}

func testBackendListenerCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("123m"),
v1.ResourceMemory: resource.MustParse("456Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("789m"),
v1.ResourceMemory: resource.MustParse("111Mi"),
},
}
}

func testBackendWorkerCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("222m"),
v1.ResourceMemory: resource.MustParse("333Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("444m"),
v1.ResourceMemory: resource.MustParse("555Mi"),
},
}
}

func testBackendCronCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("666m"),
v1.ResourceMemory: resource.MustParse("777Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("888m"),
v1.ResourceMemory: resource.MustParse("999Mi"),
},
}
}

func getInternalSecret() *v1.Secret {
data := map[string]string{
component.BackendSecretInternalApiUsernameFieldName: "someUserName",
Expand Down Expand Up @@ -284,6 +323,41 @@ func TestGetBackendOptionsProvider(t *testing.T) {
return opts
},
},
{"WithBackendCustomResourceRequirements", nil, nil, nil,
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestBackendOptions()
apimanager.Spec.Backend.ListenerSpec.Resources = testBackendListenerCustomResourceRequirements()
apimanager.Spec.Backend.WorkerSpec.Resources = testBackendWorkerCustomResourceRequirements()
apimanager.Spec.Backend.CronSpec.Resources = testBackendCronCustomResourceRequirements()
return apimanager
},
func(in *component.BackendOptions) *component.BackendOptions {
opts := defaultBackendOptions(in)

opts.ListenerResourceRequirements = *testBackendListenerCustomResourceRequirements()
opts.WorkerResourceRequirements = *testBackendWorkerCustomResourceRequirements()
opts.CronResourceRequirements = *testBackendCronCustomResourceRequirements()
return opts
},
},
{"WithBackendCustomResourceRequirementsAndGlobalResourceRequirementsDisabled", nil, nil, nil,
func() *appsv1alpha1.APIManager {
apimanager := basicApimanagerTestBackendOptions()
apimanager.Spec.ResourceRequirementsEnabled = &falseValue
apimanager.Spec.Backend.ListenerSpec.Resources = testBackendListenerCustomResourceRequirements()
apimanager.Spec.Backend.WorkerSpec.Resources = testBackendWorkerCustomResourceRequirements()
apimanager.Spec.Backend.CronSpec.Resources = testBackendCronCustomResourceRequirements()
return apimanager
},
func(in *component.BackendOptions) *component.BackendOptions {
opts := defaultBackendOptions(in)

opts.ListenerResourceRequirements = *testBackendListenerCustomResourceRequirements()
opts.WorkerResourceRequirements = *testBackendWorkerCustomResourceRequirements()
opts.CronResourceRequirements = *testBackendCronCustomResourceRequirements()
return opts
},
},
}

for _, tc := range cases {
Expand Down
7 changes: 7 additions & 0 deletions pkg/3scale/amp/operator/memcached_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func (m *MemcachedOptionsProvider) setResourceRequirementsOptions() {
} else {
m.memcachedOptions.ResourceRequirements = v1.ResourceRequirements{}
}

// DeploymentConfig-level ResourceRequirements CR fields have priority over
// spec.resourceRequirementsEnabled, overwriting that setting when they are
// defined
if m.apimanager.Spec.System.MemcachedResources != nil {
m.memcachedOptions.ResourceRequirements = *m.apimanager.Spec.System.MemcachedResources
}
}

func (m *MemcachedOptionsProvider) setNodeAffinityAndTolerationsOptions() {
Expand Down
38 changes: 38 additions & 0 deletions pkg/3scale/amp/operator/memcached_options_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ func testMemcachedTolerations() []v1.Toleration {
return getTestTolerations("memcached")
}

func testSystemMemcachedCustomResourceRequirements() *v1.ResourceRequirements {
return &v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("111m"),
v1.ResourceMemory: resource.MustParse("222Mi"),
},
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("333m"),
v1.ResourceMemory: resource.MustParse("444Mi"),
},
}
}

func defaultMemcachedOptions() *component.MemcachedOptions {
return &component.MemcachedOptions{
ImageTag: product.ThreescaleRelease,
Expand Down Expand Up @@ -97,6 +110,31 @@ func TestMemcachedOptionsProvider(t *testing.T) {
return opts
},
},
{"WithSystemMemcachedCustomResourceRequirements",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanager()
apimanager.Spec.System.MemcachedResources = testSystemMemcachedCustomResourceRequirements()
return apimanager
},
func() *component.MemcachedOptions {
opts := defaultMemcachedOptions()
opts.ResourceRequirements = *testSystemMemcachedCustomResourceRequirements()
return opts
},
},
{"WithSystemMemcachedCustomResourceRequirementsAndGlobalResourceRequirementsDisabled",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanager()
apimanager.Spec.ResourceRequirementsEnabled = &falseValue
apimanager.Spec.System.MemcachedResources = testSystemMemcachedCustomResourceRequirements()
return apimanager
},
func() *component.MemcachedOptions {
opts := defaultMemcachedOptions()
opts.ResourceRequirements = *testSystemMemcachedCustomResourceRequirements()
return opts
},
},
}

for _, tc := range cases {
Expand Down
10 changes: 10 additions & 0 deletions pkg/3scale/amp/operator/redis_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func (r *RedisOptionsProvider) setResourceRequirementsOptions() {
r.options.BackendRedisContainerResourceRequirements = &v1.ResourceRequirements{}
r.options.SystemRedisContainerResourceRequirements = &v1.ResourceRequirements{}
}

// DeploymentConfig-level ResourceRequirements CR fields have priority over
// spec.resourceRequirementsEnabled, overwriting that setting when they are
// defined
if r.apimanager.Spec.Backend.RedisResources != nil {
r.options.BackendRedisContainerResourceRequirements = r.apimanager.Spec.Backend.RedisResources
}
if r.apimanager.Spec.System.RedisResources != nil {
r.options.SystemRedisContainerResourceRequirements = r.apimanager.Spec.System.RedisResources
}
}

func (r *RedisOptionsProvider) setPersistentVolumeClaimOptions() {
Expand Down
Loading