Skip to content

Commit

Permalink
One more attempt at fixing integration test for podman
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Jan 23, 2023
1 parent a9c4a4e commit 5ce3198
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: ${PROJECT_SOURCE}
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
workingDir: ${PROJECT_SOURCE}
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
workingDir: ${PROJECT_SOURCE}
id: test
components:
- container:
args:
- tail
- -f
- /dev/null
endpoints:
- name: http-node
targetPort: 3000
- exposure: none
name: debug
targetPort: 5858
env:
- name: DEBUG_PORT
value: "5858"
image: registry.access.redhat.com/ubi8/nodejs-16:latest
memoryLimit: 1024Mi
mountSources: true
attributes:
container-overrides:
securityContext:
runAsUser: 1001
runAsGroup: 1001
name: runtime
- kubernetes:
inlined: |
apiVersion: v1
kind: ServiceAccount
metadata:
name: new-service-account
name: service-account
metadata:
description: Stack with Node.js 16
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: JavaScript
name: my-node-app
projectType: Node.js
tags:
- Node.js
- Express
- ubi8
version: 2.1.1
schemaVersion: 2.1.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
49 changes: 31 additions & 18 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"

"github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/remotecmd"
Expand Down Expand Up @@ -3210,35 +3212,46 @@ CMD ["npm", "start"]
}
}

for _, podman := range []bool{true, false} {
podman := podman
Context("Devfile contains pod-overrides and container-overrides attributes", helper.LabelPodmanIf(podman, func() {
const (
// hard coded from Devfile
podServiceAccountName = "new-service-account"
)
for _, ctx := range []struct {
devfile string
checkFunc func(podOut *corev1.Pod)
podman bool
}{
{
devfile: "devfile-pod-container-overrides.yaml",
checkFunc: func(podOut *corev1.Pod) {
Expect(podOut.Spec.Containers[0].Resources.Limits.Memory().String()).To(ContainSubstring("512Mi"))
Expect(podOut.Spec.Containers[0].Resources.Limits.Cpu().String()).To(ContainSubstring("250m"))
Expect(podOut.Spec.ServiceAccountName).To(ContainSubstring("new-service-account"))
},
podman: false,
},
{
devfile: "devfile-container-override-on-podman.yaml",
checkFunc: func(podOut *corev1.Pod) {
Expect(podOut.Spec.Containers[0].SecurityContext.RunAsUser).To(Equal(pointer.Int64(1001)))
Expect(podOut.Spec.Containers[0].SecurityContext.RunAsGroup).To(Equal(pointer.Int64(1001)))
},
podman: true,
},
} {
ctx := ctx
Context("Devfile contains pod-overrides and container-overrides attributes", helper.LabelPodmanIf(ctx.podman, func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-pod-container-overrides.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"), helper.DevfileMetadataNameSetter(cmpName))
if podman {
// podman running on CI does not contain cpu cgroup controller and hence fails to start the container
helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "cpu: \"250m\"", "")
}
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", ctx.devfile), filepath.Join(commonVar.Context, "devfile.yaml"), helper.DevfileMetadataNameSetter(cmpName))
})
It("should override the content in the pod it creates for the component on the cluster", func() {
err := helper.RunDevMode(helper.DevSessionOpts{
RunOnPodman: podman,
RunOnPodman: ctx.podman,
}, func(session *gexec.Session, outContents, _ []byte, _ map[string]string) {
component := helper.NewComponent(cmpName, "app", labels.ComponentDevMode, commonVar.Project, commonVar.CliRunner)
podOut := component.GetPodDef()
Expect(podOut.Spec.Containers[0].Resources.Limits.Memory().String()).To(ContainSubstring("512Mi"))
if !podman {
Expect(podOut.Spec.Containers[0].Resources.Limits.Cpu().String()).To(ContainSubstring("250m"))
Expect(podOut.Spec.ServiceAccountName).To(ContainSubstring(podServiceAccountName))
}
ctx.checkFunc(podOut)
})
Expect(err).To(BeNil())
})
}))

}
})

0 comments on commit 5ce3198

Please sign in to comment.