Skip to content

Commit

Permalink
Add suppport for cpuLimit, cpuRequest and memoryRequest (#5252)
Browse files Browse the repository at this point in the history
* update Devfile library and api

Signed-off-by: anandrkskd <[email protected]>

* resolve problem occured by update

Signed-off-by: anandrkskd <[email protected]>

* add test for cpuLimit,cpuRequest,memoryRequest

Signed-off-by: anandrkskd <[email protected]>

* resolve branch conflicts

Signed-off-by: anandrkskd <[email protected]>

* update schema version to 2.2.0 for test devfiles

Signed-off-by: anandrkskd <[email protected]>

* revert - update schema version to 2.2.0 for test devfiles

Signed-off-by: anandrkskd <[email protected]>

* downgrade devfile library

Signed-off-by: anandrkskd <[email protected]>

* update test, remove duplication

Signed-off-by: anandrkskd <[email protected]>

* replace oc with kubectl

Signed-off-by: anandrkskd <[email protected]>

* restructure when

Signed-off-by: anandrkskd <[email protected]>

* force push

Signed-off-by: anandrkskd <[email protected]>

* rebase and update the test to use cliRunner

Signed-off-by: anandrkskd <[email protected]>

* remove golint issues

Signed-off-by: anandrkskd <[email protected]>
  • Loading branch information
anandrkskd authored Dec 8, 2021
1 parent 8601ff4 commit 0e42e99
Show file tree
Hide file tree
Showing 25 changed files with 1,780 additions and 61 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/Netflix/go-expect v0.0.0-20201125194554-85d881c3777e
github.com/Xuanwo/go-locale v1.0.0
github.com/blang/semver v3.5.1+incompatible
github.com/devfile/api/v2 v2.0.0-20211116183836-dfec9a4d3b63
github.com/devfile/library v1.2.0
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f
github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2
github.com/fatih/color v1.10.0
Expand Down
17 changes: 6 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,13 @@ github.com/deislabs/oras v0.8.1/go.mod h1:Mx0rMSbBNaNfY9hjpccEnxkOqJL6KGjtxNHPLC
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
github.com/devfile/api/v2 v2.0.0-20210910153124-da620cd1a7a1/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed h1:OXF9l+MlJrirXAqKN6EZUVaHB0FKm7nh0EjpktwnBig=
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/api/v2 v2.0.0-20211116183836-dfec9a4d3b63 h1:apVyqTxjZ2hVDwjkWpMVOiiDSMfHY6g/I167fH8T3hQ=
github.com/devfile/api/v2 v2.0.0-20211116183836-dfec9a4d3b63/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3 h1:G7TIrgpGx5lcZ3X7bpQeVCeeeO7tv6SAzPPvB9ThHXE=
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/library v1.1.1-0.20210910214722-7c5ff63711ec/go.mod h1:svPWwWb+BP15SXCHl0dyOeE4Sohrjl5a2BaOzc/riLc=
github.com/devfile/library v1.2.0 h1:OT1Irwg5EZhlCpsAFkjIzd3bqyzbLG0JmFPMHeE1e7M=
github.com/devfile/library v1.2.0/go.mod h1:gyiQS+ZImnM4/d+wFUl3gJmIozOSXMenl0WX8cx4zu4=
github.com/devfile/registry-support/index/generator v0.0.0-20210916150157-08b31e03fdf0 h1:F2OkuW0ASrSz5d06tJxWfweUNYTnsOCyiGTEORisokE=
github.com/devfile/registry-support/index/generator v0.0.0-20210916150157-08b31e03fdf0/go.mod h1:bLGagbW2SFn7jo5+kUPlCMehIGqWkRtLKc5O0OyJMJM=
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84 h1:9Tce6BIw9PCdA1AopHxVo0gheU+dP3jfl2MgBKLnMRQ=
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84/go.mod h1:qSS0cLIKTyysdkvGr4cMlTOHO0zkoobFcfvAVPtoq5Y=
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f h1:fKNUmoOPh7yAs69uMRZWHvev+m3e7T4jBL/hOXZB9ys=
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f/go.mod h1:bLGagbW2SFn7jo5+kUPlCMehIGqWkRtLKc5O0OyJMJM=
github.com/devfile/registry-support/registry-library v0.0.0-20210928163805-b0916a4f1aca h1:MioKDSUEwwYCGEjGioWYO1vodYAutS+ESkZBGCPtx/U=
github.com/devfile/registry-support/registry-library v0.0.0-20210928163805-b0916a4f1aca/go.mod h1:AMc98EiYtcL3XDv1f/dmMzNwuhLY2hFdWm6iOr18bZ4=
github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2 h1:Rwuc0bdx8xSZWdIwXjAxaKYnZIWHneJmDAAZ6a5jXzY=
github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2/go.mod h1:P9ivpg3NdJR7/atzW6Jo7Qs0NbrLjwxoknhQN+lFyAc=
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down Expand Up @@ -644,6 +637,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
6 changes: 5 additions & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp
PodSelectorLabels: selectorLabels,
}

deployment := generator.GetDeployment(deployParams)
deployment, err := generator.GetDeployment(a.Devfile, deployParams)
if err != nil {
return err
}

if deployment.Annotations == nil {
deployment.Annotations = make(map[string]string)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/kclient/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func createFakeDeployment(fkclient *Client, fkclientset *FakeClientset, podName
ObjectMeta: objectMeta,
Containers: containers,
}
deploy := generator.GetDeployment(deploymentParams)

deploy, _ := generator.GetDeployment(devObj, deploymentParams)
fkclientset.Kubernetes.PrependReactor("patch", "deployments", func(action ktesting.Action) (bool, runtime.Object, error) {
if podName == "" {
return true, nil, errors.Errorf("deployment name is empty")
Expand Down Expand Up @@ -234,8 +233,7 @@ func TestUpdateDeployment(t *testing.T) {
ObjectMeta: objectMeta,
Containers: containers,
}
deploy := generator.GetDeployment(deploymentParams)

deploy, _ := generator.GetDeployment(devObj, deploymentParams)
fkclientset.Kubernetes.PrependReactor("patch", "deployments", func(action ktesting.Action) (bool, runtime.Object, error) {
if tt.deploymentName == "" {
return true, nil, errors.Errorf("deployment name is empty")
Expand Down
3 changes: 2 additions & 1 deletion pkg/occlient/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/generator"
routev1 "github.com/openshift/api/route/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *Client) CreateRoute(name string, serviceName string, portNumber intstr.
},
}

route := generator.GetRoute(routeParams)
route := generator.GetRoute(v1.Endpoint{}, routeParams)

route.SetOwnerReferences(append(route.GetOwnerReferences(), ownerReference))

Expand Down
3 changes: 2 additions & 1 deletion pkg/testingutil/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testingutil
import (
"fmt"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/generator"
routev1 "github.com/openshift/api/route/v1"
applabels "github.com/redhat-developer/odo/pkg/application/labels"
Expand Down Expand Up @@ -50,7 +51,7 @@ func GetSingleRoute(urlName string, port int, componentName, applicationName str

// GetSingleSecureRoute returns a secure route generated with the given parameters
func GetSingleSecureRoute(urlName string, port int, componentName, applicationName string) routev1.Route {
generatedRoute := *generator.GetRoute(generator.RouteParams{
generatedRoute := *generator.GetRoute(v1.Endpoint{}, generator.RouteParams{
ObjectMeta: metav1.ObjectMeta{
Name: urlName,
Labels: map[string]string{
Expand Down
3 changes: 2 additions & 1 deletion pkg/unions/kubernetes_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unions
import (
"fmt"

v1alpha2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/generator"
"github.com/redhat-developer/odo/pkg/odogenerator"
"k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -37,7 +38,7 @@ func NewGeneratedKubernetesIngress() *KubernetesIngress {
func NewKubernetesIngressFromParams(ingressParams generator.IngressParams) *KubernetesIngress {
ki := NewGeneratedKubernetesIngress()
ki.NetworkingV1Ingress = odogenerator.GetNetworkingV1Ingress(ingressParams)
ki.ExtensionV1Beta1Ingress = generator.GetIngress(ingressParams)
ki.ExtensionV1Beta1Ingress = generator.GetIngress(v1alpha2.Endpoint{}, ingressParams)
return ki
}

Expand Down
53 changes: 53 additions & 0 deletions tests/examples/source/devfiles/nodejs/devfile-with-MR-CL-CR.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
schemaVersion: 2.2.0
metadata:
name: nodejs
projectType: nodejs
language: nodejs
starterProjects:
- name: nodejs-starter
git:
remotes:
origin: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
- name: runtime
container:
image: registry.access.redhat.com/ubi8/nodejs-12:1-36
memoryLimit: 1024Mi
memoryRequest: 512Mi
cpuLimit: '1'
cpuRequest: 200m
endpoints:
- name: "3000-tcp"
targetPort: 3000
mountSources: true
commands:
- id: devbuild
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
isDefault: true
- id: build
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
- id: devrun
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
isDefault: true
- id: run
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
51 changes: 51 additions & 0 deletions tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,57 @@ var _ = Describe("odo devfile push command tests", func() {
Context("odo push (without -f) is executed", func() {
ensureFilesSyncedTest(commonVar.Project, false)
})

When("node-js application is created and pushed with devfile schema 2.2.0", func() {

var output string
BeforeEach(func() {
helper.Cmd("odo", "create", "--project", commonVar.Project, cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-with-MR-CL-CR.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
output = helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
})

ensureResource := func(output, cpulimit, cpurequest, memoryrequest string) {
By("check for cpuLimit", func() {
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
bufferOutput := commonVar.CliRunner.Run("get", "pods", podName, "-o", "jsonpath='{.spec.containers[0].resources.limits.cpu}'").Out.Contents()
output = string(bufferOutput)
Expect(output).To(ContainSubstring(cpulimit))
})

By("check for cpuRequests", func() {
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
bufferOutput := commonVar.CliRunner.Run("get", "pods", podName, "-o", "jsonpath='{.spec.containers[0].resources.requests.cpu}'").Out.Contents()
output = string(bufferOutput)
Expect(output).To(ContainSubstring(cpurequest))
})

By("check for memoryRequests", func() {
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
bufferOutput := commonVar.CliRunner.Run("get", "pods", podName, "-o", "jsonpath='{.spec.containers[0].resources.requests.memory}'").Out.Contents()
output = string(bufferOutput)
Expect(output).To(ContainSubstring(memoryrequest))
})
}

It("should check cpuLimit,cpuRequests,memoryRequests", func() {
ensureResource(output, "1", "200m", "512Mi")
})

When("Update the devfile.yaml, do odo push", func() {

BeforeEach(func() {
helper.ReplaceString("devfile.yaml", "cpuLimit: \"1\"", "cpuLimit: 700m")
helper.ReplaceString("devfile.yaml", "cpuRequest: 200m", "cpuRequest: 250m")
helper.ReplaceString("devfile.yaml", "memoryRequest: 512Mi", "memoryRequest: 550Mi")
output = helper.Cmd("odo", "push", "--project", commonVar.Project).ShouldPass().Out()
})

It("should check cpuLimit,cpuRequests,memoryRequests", func() {
ensureResource(output, "700m", "250m", "550Mi")
})
})
})
})

When("creating nodejs component, doing odo push and run command has dev.odo.push.path attribute", func() {
Expand Down
35 changes: 35 additions & 0 deletions vendor/github.com/devfile/api/v2/pkg/validation/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/github.com/devfile/api/v2/pkg/validation/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e42e99

Please sign in to comment.