Skip to content

Commit

Permalink
Add configurable ResourceRequirements for System DeploymentConfigs
Browse files Browse the repository at this point in the history
DeploymentConfig-level ResourceRequirement attributes in the CR
have priority over spec.resourceRequirementsEnabled setting and
overwrite the values set by it
  • Loading branch information
miguelsorianod committed Aug 28, 2020
1 parent 988a1bc commit cd676ba
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 0 deletions.
178 changes: 178 additions & 0 deletions deploy/crds/apps.3scale.net_apimanagers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4829,6 +4829,66 @@ spec:
type: array
type: object
type: object
developerContainerResources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. More info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
masterContainerResources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. More info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
providerContainerResources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. More info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
replicas:
format: int64
type: integer
Expand Down Expand Up @@ -5544,6 +5604,26 @@ spec:
storageClassName:
type: string
type: object
resources:
description: ResourceRequirements describes the compute
resource requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of
compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount
of compute resources required. If Requests is omitted
for a container, it defaults to Limits if that is
explicitly specified, otherwise to an implementation-defined
value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
tolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -6994,6 +7074,26 @@ spec:
type: object
type: array
type: object
resources:
description: ResourceRequirements describes the compute
resource requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of
compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount
of compute resources required. If Requests is omitted
for a container, it defaults to Limits if that is
explicitly specified, otherwise to an implementation-defined
value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
tolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -7687,6 +7787,25 @@ spec:
type: object
memcachedImage:
type: string
memcachedResources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
memcachedTolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -8332,6 +8451,25 @@ spec:
storageClassName:
type: string
type: object
redisResources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
redisTolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -9002,6 +9140,26 @@ spec:
replicas:
format: int64
type: integer
resources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. More info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
tolerations:
items:
description: The pod this Toleration is attached to tolerates
Expand Down Expand Up @@ -9672,6 +9830,26 @@ spec:
type: array
type: object
type: object
resources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. More info:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
tolerations:
items:
description: The pod this Toleration is attached to tolerates
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
3 changes: 3 additions & 0 deletions pkg/3scale/amp/operator/redis_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func (r *RedisOptionsProvider) setResourceRequirementsOptions() {
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
39 changes: 39 additions & 0 deletions pkg/3scale/amp/operator/redis_options_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ func testBackendRedisCustomResourceRequirements() *v1.ResourceRequirements {
}
}

func testSystemRedisCustomResourceRequirements() *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 defaultRedisOptions() *component.RedisOptions {
tmpInsecure := insecureImportPolicy
return &component.RedisOptions{
Expand Down Expand Up @@ -288,6 +301,32 @@ func TestGetRedisOptionsProvider(t *testing.T) {
return opts
},
},
{"WithSystemRedisCustomResourceRequirements",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanager()
apimanager.Spec.Backend.RedisResources = testSystemRedisCustomResourceRequirements()
return apimanager
},
func() *component.RedisOptions {
opts := defaultRedisOptions()
opts.BackendRedisContainerResourceRequirements = testSystemRedisCustomResourceRequirements()
return opts
},
},
{"WithSystemRedisCustomResourceRequirementsAndGlobalResourceRequirementsDisabled",
func() *appsv1alpha1.APIManager {
apimanager := basicApimanager()
apimanager.Spec.ResourceRequirementsEnabled = &tmpFalseValue
apimanager.Spec.System.RedisResources = testSystemRedisCustomResourceRequirements()
return apimanager
},
func() *component.RedisOptions {
opts := defaultRedisOptions()
opts.BackendRedisContainerResourceRequirements = &v1.ResourceRequirements{}
opts.SystemRedisContainerResourceRequirements = testSystemRedisCustomResourceRequirements()
return opts
},
},
}

for _, tc := range cases {
Expand Down
9 changes: 9 additions & 0 deletions pkg/3scale/amp/operator/system_mysql_options_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (s *SystemMysqlOptionsProvider) setResourceRequirementsOptions() {
} else {
s.mysqlOptions.ContainerResourceRequirements = v1.ResourceRequirements{}
}

// DeploymentConfig-level ResourceRequirements CR fields have priority over
// spec.resourceRequirementsEnabled, overwriting that setting when they are
// defined
if s.apimanager.Spec.System.DatabaseSpec != nil &&
s.apimanager.Spec.System.DatabaseSpec.MySQL != nil &&
s.apimanager.Spec.System.DatabaseSpec.MySQL.Resources != nil {
s.mysqlOptions.ContainerResourceRequirements = *s.apimanager.Spec.System.DatabaseSpec.MySQL.Resources
}
}

func (s *SystemMysqlOptionsProvider) setPersistentVolumeClaimOptions() {
Expand Down
Loading

0 comments on commit cd676ba

Please sign in to comment.