Skip to content

Commit

Permalink
feat: Add Traefik gateway container CPU & RAM request/limit resources (
Browse files Browse the repository at this point in the history
…#1088)

Signed-off-by: Max Shaposhnik <mshaposh@redhat.com>
  • Loading branch information
mshaposhnik authored Sep 24, 2021
1 parent d7e925d commit f4d8016
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion controllers/devworkspace/solver/che_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"

"github.com/eclipse-che/che-operator/pkg/deploy/gateway"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"

dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/eclipse-che/che-operator/api/v2alpha1"
"github.com/eclipse-che/che-operator/controllers/devworkspace/defaults"
"github.com/eclipse-che/che-operator/controllers/devworkspace/sync"
"github.com/eclipse-che/che-operator/pkg/deploy"
"github.com/google/go-cmp/cmp/cmpopts"
routeV1 "github.com/openshift/api/route/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -162,13 +164,23 @@ func (c *CheRoutingSolver) provisionPodAdditions(objs *solvers.RoutingObjects, c
objs.PodAdditions.Containers = append(objs.PodAdditions.Containers, corev1.Container{
Name: wsGatewayName,
Image: cheCluster.Spec.Gateway.Image,
ImagePullPolicy: corev1.PullAlways,
ImagePullPolicy: corev1.PullPolicy(deploy.DefaultPullPolicyFromDockerImage(cheCluster.Spec.Gateway.Image)),
VolumeMounts: []corev1.VolumeMount{
{
Name: wsGatewayName,
MountPath: "/etc/traefik",
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("256Mi"),
corev1.ResourceCPU: resource.MustParse("0.5"),
},
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("64Mi"),
corev1.ResourceCPU: resource.MustParse("0.05"),
},
},
})

// Even though DefaultMode is optional in Kubernetes, DevWorkspace Controller needs it to be explicitly defined.
Expand Down
15 changes: 15 additions & 0 deletions controllers/devworkspace/solver/che_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ func TestCreateRelocatedObjectsK8S(t *testing.T) {
if len(objs.PodAdditions.Volumes) != 1 || objs.PodAdditions.Volumes[0].Name != wsGatewayName {
t.Error("expected Volume pod addition for workspace gateway. Got ", objs.PodAdditions)
}

if objs.PodAdditions.Containers[0].Resources.Requests.Memory() == nil {
t.Error("expected addition pod Container Memory request to be set")
}
if objs.PodAdditions.Containers[0].Resources.Requests.Cpu() == nil {
t.Error("expected addition po Container CPU request to be set")
}

if objs.PodAdditions.Containers[0].Resources.Limits.Memory() == nil {
t.Error("expected addition po Container Memory limit to be set")
}

if objs.PodAdditions.Containers[0].Resources.Limits.Cpu() == nil {
t.Error("expected addition po Container CPU limit to be set")
}
})

for i := range objs.Services {
Expand Down

0 comments on commit f4d8016

Please sign in to comment.