Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #172 from camilamacedo86/AEROGEAR-9767
Browse files Browse the repository at this point in the history
feat(resources) : Add resource requests/limits to MSS & MSS operator AEROGEAR-9767)
  • Loading branch information
camilamacedo86 committed Aug 23, 2019
2 parents 5d796c2 + f5a7872 commit a628bdd
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
- Change/Add Memory and CPU resources requested and limits for MSS, Oauth and Operator [#172](https://github.com/aerogear/mobile-security-service-operator/pull/172)

## [0.4.0] - 2019-08-13
- Remove MobileSecurityServicePodCount since it was considered duplicated [#157](https://github.com/aerogear/mobile-security-service-operator/pull/157)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ spec:

image: "quay.io/aerogear/mobile-security-service:0.2.2"
containerName: "application"
memoryLimit: "512Mi"
memoryRequest: "512Mi"
memoryLimit: "128Mi"
memoryRequest: "64Mi"
resourceCpuLimit: "20m"
resourceCpu: "10m"
# Use the following spec if you would like to define the image pull policy
# containerImagePullPolicy: "IfNotPresent"

Expand All @@ -50,6 +52,13 @@ spec:

oAuthImage: "docker.io/openshift/oauth-proxy:v1.1.0"
oAuthContainerName: "oauth-proxy"
oAuthMemoryLimit: "64Mi"
oAuthMemoryRequest: "32Mi"
oAuthResourceCpuLimit: "20m"
oAuthResourceCpu: "10m"

# Use the following spec if you would like to define the image policy
# oAuthContainerImagePullPolicy: "IfNotPresent"



Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,30 @@ spec:
description: 'Oauth image:tag E.g docker.io/openshift/oauth-proxy:v1.1.0
More info: https://github.com/openshift/oauth-proxy'
type: string
oAuthMemoryLimit:
description: Limit of Memory which will be available for the OAuth container
type: string
oAuthMemoryRequest:
description: Limit of Memory Request which will be available for the
OAuth container
type: string
oAuthResourceCpu:
description: CPU resource which will be available for the OAuth container
type: string
oAuthResourceCpuLimit:
description: Limit of CPU which will be available for the OAuth container
type: string
port:
description: 'Value for the Service Environment Variable (PORT) More
info: https://github.com/aerogear/mobile-security-service-operator#changing-the-environment-variables-values'
format: int32
type: integer
resourceCpu:
description: CPU resource which will be available for the Service container
type: string
resourceCpuLimit:
description: Limit of CPU which will be available for the Service container
type: string
routeName:
description: The name of the route which will vbe created to expose
the Service
Expand Down
7 changes: 7 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ spec:
command:
- mobile-security-service-operator
imagePullPolicy: Always
resources:
limits:
cpu: 60m
memory: 128Mi
requests:
cpu: 30m
memory: 64Mi
env:
- name: WATCH_NAMESPACE
valueFrom:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ type MobileSecurityServiceSpec struct {
MemoryLimit string `json:"memoryLimit,omitempty"`
// Limit of Memory Request which will be available for the Service container
MemoryRequest string `json:"memoryRequest,omitempty"`
// Limit of CPU which will be available for the Service container
ResourceCpuLimit string `json:"resourceCpuLimit,omitempty"`
// CPU resource which will be available for the Service container
ResourceCpu string `json:"resourceCpu,omitempty"`
// Limit of Memory which will be available for the OAuth container
OAuthMemoryLimit string `json:"oAuthMemoryLimit,omitempty"`
// Limit of Memory Request which will be available for the OAuth container
OAuthMemoryRequest string `json:"oAuthMemoryRequest,omitempty"`
// Limit of CPU which will be available for the OAuth container
OAuthResourceCpuLimit string `json:"oAuthResourceCpuLimit,omitempty"`
// CPU resource which will be available for the OAuth container
OAuthResourceCpu string `json:"oAuthResourceCpu,omitempty"`
// Oauth image:tag E.g docker.io/openshift/oauth-proxy:v1.1.0
// More info: https://github.com/openshift/oauth-proxy
OAuthImage string `json:"oAuthImage,omitempty"`
Expand Down
44 changes: 43 additions & 1 deletion pkg/apis/mobilesecurityservice/v1alpha1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func schema_pkg_apis_mobilesecurityservice_v1alpha1_MobileSecurityServiceSpec(re
},
"image": {
SchemaProps: spec.SchemaProps{
Description: "Service image:tag E.g quay.io/aerogear/mobile-security-service:0.2.2",
Description: "Service image:tag E.g quay.io/aerogear/mobile-security-service:0.1.0",
Type: []string{"string"},
Format: "",
},
Expand Down Expand Up @@ -768,6 +768,48 @@ func schema_pkg_apis_mobilesecurityservice_v1alpha1_MobileSecurityServiceSpec(re
Format: "",
},
},
"resourceCpuLimit": {
SchemaProps: spec.SchemaProps{
Description: "Limit of CPU which will be available for the Service container",
Type: []string{"string"},
Format: "",
},
},
"resourceCpu": {
SchemaProps: spec.SchemaProps{
Description: "CPU resource which will be available for the Service container",
Type: []string{"string"},
Format: "",
},
},
"oAuthMemoryLimit": {
SchemaProps: spec.SchemaProps{
Description: "Limit of Memory which will be available for the OAuth container",
Type: []string{"string"},
Format: "",
},
},
"oAuthMemoryRequest": {
SchemaProps: spec.SchemaProps{
Description: "Limit of Memory Request which will be available for the OAuth container",
Type: []string{"string"},
Format: "",
},
},
"oAuthResourceCpuLimit": {
SchemaProps: spec.SchemaProps{
Description: "Limit of CPU which will be available for the OAuth container",
Type: []string{"string"},
Format: "",
},
},
"oAuthResourceCpu": {
SchemaProps: spec.SchemaProps{
Description: "CPU resource which will be available for the OAuth container",
Type: []string{"string"},
Format: "",
},
},
"oAuthImage": {
SchemaProps: spec.SchemaProps{
Description: "Oauth image:tag E.g docker.io/openshift/oauth-proxy:v1.1.0 More info: https://github.com/openshift/oauth-proxy",
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/mobilesecurityservice/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestReconcileMobileSecurityService_update(t *testing.T) {
},
}

// Add const values for mandatory specs
addMandatorySpecsDefinitions(tt.fields.instanceToUpdate)

res, err := r.Reconcile(req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/mobilesecurityservice/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func buildOAuthContainer(mss *mobilesecurityservicev1alpha1.MobileSecurityServic
Args: getOAuthArgsMap(mss),
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: "File",
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(mss.Spec.OAuthMemoryLimit),
corev1.ResourceCPU: resource.MustParse(mss.Spec.OAuthResourceCpuLimit),
},
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(mss.Spec.OAuthMemoryRequest),
corev1.ResourceCPU: resource.MustParse(mss.Spec.OAuthResourceCpu),
},
},
}
}

Expand Down Expand Up @@ -119,9 +129,11 @@ func buildApplicationContainer(mss *mobilesecurityservicev1alpha1.MobileSecurity
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(mss.Spec.MemoryLimit),
corev1.ResourceCPU: resource.MustParse(mss.Spec.ResourceCpuLimit),
},
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(mss.Spec.MemoryRequest),
corev1.ResourceCPU: resource.MustParse(mss.Spec.ResourceCpu),
},
},
}
Expand Down
32 changes: 31 additions & 1 deletion pkg/controller/mobilesecurityservice/mandatory_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const (
size = 1
clusterProtocol = "http"
memoryLimit = "512Mi"
memoryRequest = "512Mi"
memoryRequest = "128Mi"
resourceCpuLimit = "20m"
resourceCpu = "10m"
oAuthMemoryLimit = "64Mi"
oAuthMemoryRequest = "32Mi"
oAuthResourceCpuLimit = "20m"
oAuthResourceCpu = "10m"
image = "quay.io/aerogear/mobile-security-service:0.2.2"
containerName = "application"
oAuthImage = "docker.io/openshift/oauth-proxy:v1.1.0"
Expand Down Expand Up @@ -96,6 +102,30 @@ func addMandatorySpecsDefinitions(mss *mobilesecurityservicev1alpha1.MobileSecur
mss.Spec.MemoryRequest = memoryRequest
}

if mss.Spec.ResourceCpu == "" {
mss.Spec.ResourceCpu = resourceCpu
}

if mss.Spec.ResourceCpuLimit == "" {
mss.Spec.ResourceCpuLimit = resourceCpuLimit
}

if mss.Spec.OAuthMemoryLimit == "" {
mss.Spec.OAuthMemoryLimit = oAuthMemoryLimit
}

if mss.Spec.OAuthMemoryRequest == "" {
mss.Spec.OAuthMemoryRequest = oAuthMemoryRequest
}

if mss.Spec.OAuthResourceCpu == "" {
mss.Spec.OAuthResourceCpu = oAuthResourceCpu
}

if mss.Spec.OAuthResourceCpuLimit == "" {
mss.Spec.OAuthResourceCpuLimit = oAuthResourceCpuLimit
}

if mss.Spec.RouteName == "" {
mss.Spec.RouteName = routeName
}
Expand Down

0 comments on commit a628bdd

Please sign in to comment.