1 package podmandev
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8 "github.com/devfile/library/v2/pkg/devfile/parser"
9 "github.com/devfile/library/v2/pkg/devfile/parser/data"
10 "github.com/golang/mock/gomock"
11 "github.com/google/go-cmp/cmp"
12 "github.com/google/go-cmp/cmp/cmpopts"
13
14 "github.com/redhat-developer/odo/pkg/api"
15 "github.com/redhat-developer/odo/pkg/labels"
16 "github.com/redhat-developer/odo/pkg/libdevfile/generator"
17 odocontext "github.com/redhat-developer/odo/pkg/odo/context"
18 "github.com/redhat-developer/odo/pkg/podman"
19 "github.com/redhat-developer/odo/pkg/version"
20
21 corev1 "k8s.io/api/core/v1"
22 "k8s.io/apimachinery/pkg/api/resource"
23 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/utils/pointer"
25 )
26
27 var (
28 devfileName = "mycmp"
29 appName = "app"
30
31 command = generator.GetExecCommand(generator.ExecCommandParams{
32 Id: "run",
33 Component: "mycomponent",
34 CommandLine: "./run",
35 IsDefault: pointer.Bool(true),
36 Kind: v1alpha2.RunCommandGroupKind,
37 })
38
39 baseComponent = generator.GetContainerComponent(generator.ContainerComponentParams{
40 Name: "mycomponent",
41 Container: v1alpha2.Container{
42 Image: "myimage",
43 Args: []string{"-f", "/dev/null"},
44 Command: []string{"tail"},
45 },
46 })
47
48 volume = generator.GetVolumeComponent(generator.VolumeComponentParams{
49 Name: "myvolume",
50 })
51 )
52
53 func buildBasePod(withPfContainer bool) *corev1.Pod {
54 basePod := corev1.Pod{
55 TypeMeta: v1.TypeMeta{
56 APIVersion: "v1",
57 Kind: "Pod",
58 },
59 ObjectMeta: v1.ObjectMeta{
60 Name: "mycmp-app",
61 Labels: map[string]string{
62 "app": appName,
63 "app.kubernetes.io/instance": devfileName,
64 "app.kubernetes.io/managed-by": "odo",
65 "app.kubernetes.io/managed-by-version": version.VERSION,
66 "app.kubernetes.io/part-of": appName,
67 "component": devfileName,
68 "odo.dev/mode": labels.ComponentDevMode,
69 "odo.dev/project-type": "Not available",
70 },
71 },
72 Spec: corev1.PodSpec{
73 Containers: []corev1.Container{
74 {
75 Args: []string{"-f", "/dev/null"},
76 Command: []string{"tail"},
77 Env: []corev1.EnvVar{
78 {
79 Name: "PROJECTS_ROOT",
80 Value: "/projects",
81 },
82 {
83 Name: "PROJECT_SOURCE",
84 Value: "/projects",
85 },
86 },
87 Image: "myimage",
88 ImagePullPolicy: "Always",
89 Name: "mycomponent",
90 VolumeMounts: []corev1.VolumeMount{
91 {
92 MountPath: "/projects",
93 Name: "odo-projects",
94 },
95 {
96 MountPath: "/opt/odo/",
97 Name: "odo-shared-data",
98 },
99 },
100 },
101 },
102 Volumes: []corev1.Volume{
103 {
104 Name: "odo-projects",
105 VolumeSource: corev1.VolumeSource{
106 PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
107 ClaimName: "odo-projects-mycmp-app",
108 },
109 },
110 },
111 {
112 Name: "odo-shared-data",
113 VolumeSource: corev1.VolumeSource{
114 PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
115 ClaimName: "odo-shared-data-mycmp-app",
116 },
117 },
118 },
119 },
120 },
121 }
122 if withPfContainer {
123 basePod.Spec.Containers = append(basePod.Spec.Containers, corev1.Container{
124 Args: []string{"-f", "/dev/null"},
125 Command: []string{"tail"},
126 Image: portForwardingHelperImage,
127 Name: portForwardingHelperContainerName,
128 })
129 }
130 return &basePod
131 }
132
133 func Test_createPodFromComponent(t *testing.T) {
134
135 type args struct {
136 devfileObj func() parser.DevfileObj
137 componentName string
138 appName string
139 debug bool
140 buildCommand string
141 runCommand string
142 debugCommand string
143 forwardLocalhost bool
144 customForwardedPorts []api.ForwardedPort
145 customAddress string
146 }
147 tests := []struct {
148 name string
149 capabilities podman.Capabilities
150 args args
151 wantPod func(basePod *corev1.Pod) *corev1.Pod
152 wantFwPorts []api.ForwardedPort
153 wantErr bool
154 }{
155 {
156 name: "basic component without command / forwardLocalhost=false",
157 args: args{
158 devfileObj: func() parser.DevfileObj {
159 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
160 _ = data.AddCommands([]v1alpha2.Command{command})
161 _ = data.AddComponents([]v1alpha2.Component{baseComponent})
162 return parser.DevfileObj{
163 Data: data,
164 }
165 },
166 componentName: devfileName,
167 appName: appName,
168 },
169 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
170 return basePod.DeepCopy()
171 },
172 },
173 {
174 name: "basic component without command / forwardLocalhost=true",
175 args: args{
176 devfileObj: func() parser.DevfileObj {
177 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
178 _ = data.AddCommands([]v1alpha2.Command{command})
179 _ = data.AddComponents([]v1alpha2.Component{baseComponent})
180 return parser.DevfileObj{
181 Data: data,
182 }
183 },
184 componentName: devfileName,
185 appName: appName,
186 forwardLocalhost: true,
187 },
188 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
189 pod := basePod.DeepCopy()
190 return pod
191 },
192 },
193 {
194 name: "basic component with command / forwardLocalhost=false",
195 args: args{
196 devfileObj: func() parser.DevfileObj {
197 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
198 _ = data.AddCommands([]v1alpha2.Command{command})
199 cmp := baseComponent.DeepCopy()
200 cmp.Container.Command = []string{"./cmd"}
201 cmp.Container.Args = []string{"arg1", "arg2"}
202 _ = data.AddComponents([]v1alpha2.Component{*cmp})
203 return parser.DevfileObj{
204 Data: data,
205 }
206 },
207 componentName: devfileName,
208 appName: appName,
209 },
210 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
211 pod := basePod.DeepCopy()
212 pod.Spec.Containers[0].Command = []string{"./cmd"}
213 pod.Spec.Containers[0].Args = []string{"arg1", "arg2"}
214 return pod
215 },
216 },
217 {
218 name: "basic component with command / forwardLocalhost=true",
219 args: args{
220 devfileObj: func() parser.DevfileObj {
221 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
222 _ = data.AddCommands([]v1alpha2.Command{command})
223 cmp := baseComponent.DeepCopy()
224 cmp.Container.Command = []string{"./cmd"}
225 cmp.Container.Args = []string{"arg1", "arg2"}
226 _ = data.AddComponents([]v1alpha2.Component{*cmp})
227 return parser.DevfileObj{
228 Data: data,
229 }
230 },
231 componentName: devfileName,
232 appName: appName,
233 forwardLocalhost: true,
234 },
235 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
236 pod := basePod.DeepCopy()
237 pod.Spec.Containers[0].Command = []string{"./cmd"}
238 pod.Spec.Containers[0].Args = []string{"arg1", "arg2"}
239 return pod
240 },
241 },
242 {
243 name: "basic component + memory limit / forwardLocalhost=false, cgroup=v2",
244 capabilities: podman.Capabilities{
245 Cgroupv2: true,
246 },
247 args: args{
248 devfileObj: func() parser.DevfileObj {
249 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
250 _ = data.AddCommands([]v1alpha2.Command{command})
251 cmp := baseComponent.DeepCopy()
252 cmp.Container.MemoryLimit = "1Gi"
253 _ = data.AddComponents([]v1alpha2.Component{*cmp})
254 return parser.DevfileObj{
255 Data: data,
256 }
257 },
258 componentName: devfileName,
259 appName: appName,
260 },
261 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
262 pod := basePod.DeepCopy()
263 pod.Spec.Containers[0].Resources.Limits = corev1.ResourceList{
264 "memory": resource.MustParse("1Gi"),
265 }
266 return pod
267 },
268 },
269 {
270 name: "basic component + memory limit / forwardLocalhost=false, cgroup=v1",
271 capabilities: podman.Capabilities{
272 Cgroupv2: false,
273 },
274 args: args{
275 devfileObj: func() parser.DevfileObj {
276 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
277 _ = data.AddCommands([]v1alpha2.Command{command})
278 cmp := baseComponent.DeepCopy()
279 cmp.Container.MemoryLimit = "1Gi"
280 _ = data.AddComponents([]v1alpha2.Component{*cmp})
281 return parser.DevfileObj{
282 Data: data,
283 }
284 },
285 componentName: devfileName,
286 appName: appName,
287 },
288 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
289 pod := basePod.DeepCopy()
290 return pod
291 },
292 },
293 {
294 name: "basic component + memory limit / forwardLocalhost=true, cgroup=v2",
295 capabilities: podman.Capabilities{
296 Cgroupv2: true,
297 },
298 args: args{
299 devfileObj: func() parser.DevfileObj {
300 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
301 _ = data.AddCommands([]v1alpha2.Command{command})
302 cmp := baseComponent.DeepCopy()
303 cmp.Container.MemoryLimit = "1Gi"
304 _ = data.AddComponents([]v1alpha2.Component{*cmp})
305 return parser.DevfileObj{
306 Data: data,
307 }
308 },
309 componentName: devfileName,
310 appName: appName,
311 forwardLocalhost: true,
312 },
313 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
314 pod := basePod.DeepCopy()
315 pod.Spec.Containers[0].Resources.Limits = corev1.ResourceList{
316 "memory": resource.MustParse("1Gi"),
317 }
318 return pod
319 },
320 },
321 {
322 name: "basic component + application endpoint / forwardLocalhost=false",
323 args: args{
324 devfileObj: func() parser.DevfileObj {
325 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
326 _ = data.AddCommands([]v1alpha2.Command{command})
327 cmp := baseComponent.DeepCopy()
328 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
329 Name: "http",
330 TargetPort: 8080,
331 })
332 _ = data.AddComponents([]v1alpha2.Component{*cmp})
333 return parser.DevfileObj{
334 Data: data,
335 }
336 },
337 componentName: devfileName,
338 appName: appName,
339 },
340 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
341 pod := basePod.DeepCopy()
342 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
343 Name: "http",
344 ContainerPort: 8080,
345 HostPort: 20001,
346 Protocol: corev1.ProtocolTCP,
347 HostIP: "127.0.0.1",
348 })
349 return pod
350 },
351 wantFwPorts: []api.ForwardedPort{
352 {
353 Platform: "podman",
354 ContainerName: "mycomponent",
355 PortName: "http",
356 LocalAddress: "127.0.0.1",
357 LocalPort: 20001,
358 ContainerPort: 8080,
359 IsDebug: false,
360 },
361 },
362 },
363 {
364 name: "basic component + application endpoint / forwardLocalhost=true",
365 args: args{
366 devfileObj: func() parser.DevfileObj {
367 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
368 _ = data.AddCommands([]v1alpha2.Command{command})
369 cmp := baseComponent.DeepCopy()
370 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
371 Name: "http",
372 TargetPort: 8080,
373 })
374 _ = data.AddComponents([]v1alpha2.Component{*cmp})
375 return parser.DevfileObj{
376 Data: data,
377 }
378 },
379 componentName: devfileName,
380 appName: appName,
381 forwardLocalhost: true,
382 },
383 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
384 pod := basePod.DeepCopy()
385 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
386 Name: "http",
387 ContainerPort: 20001,
388 HostPort: 20001,
389 HostIP: "127.0.0.1",
390 })
391 return pod
392 },
393 wantFwPorts: []api.ForwardedPort{
394 {
395 Platform: "podman",
396 ContainerName: "mycomponent",
397 PortName: "http",
398 LocalAddress: "127.0.0.1",
399 LocalPort: 20001,
400 ContainerPort: 8080,
401 IsDebug: false,
402 },
403 },
404 },
405 {
406 name: "basic component + application endpoint + debug endpoint - without debug / forwardLocalhost=false",
407 args: args{
408 devfileObj: func() parser.DevfileObj {
409 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
410 _ = data.AddCommands([]v1alpha2.Command{command})
411 cmp := baseComponent.DeepCopy()
412 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
413 Name: "http",
414 TargetPort: 8080,
415 })
416 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
417 Name: "debug",
418 TargetPort: 5858,
419 })
420 _ = data.AddComponents([]v1alpha2.Component{*cmp})
421 return parser.DevfileObj{
422 Data: data,
423 }
424 },
425 componentName: devfileName,
426 appName: appName,
427 },
428 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
429 pod := basePod.DeepCopy()
430 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
431 Name: "http",
432 ContainerPort: 8080,
433 HostPort: 20001,
434 Protocol: corev1.ProtocolTCP,
435 HostIP: "127.0.0.1",
436 })
437 return pod
438 },
439 wantFwPorts: []api.ForwardedPort{
440 {
441 Platform: "podman",
442 ContainerName: "mycomponent",
443 PortName: "http",
444 LocalAddress: "127.0.0.1",
445 LocalPort: 20001,
446 ContainerPort: 8080,
447 IsDebug: false,
448 },
449 },
450 },
451 {
452 name: "basic component + application endpoint + debug endpoint - without debug / forwardLocalhost=true",
453 args: args{
454 devfileObj: func() parser.DevfileObj {
455 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
456 _ = data.AddCommands([]v1alpha2.Command{command})
457 cmp := baseComponent.DeepCopy()
458 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
459 Name: "http",
460 TargetPort: 8080,
461 })
462 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
463 Name: "debug",
464 TargetPort: 5858,
465 })
466 _ = data.AddComponents([]v1alpha2.Component{*cmp})
467 return parser.DevfileObj{
468 Data: data,
469 }
470 },
471 componentName: devfileName,
472 appName: appName,
473 forwardLocalhost: true,
474 },
475 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
476 pod := basePod.DeepCopy()
477 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
478 Name: "http",
479 ContainerPort: 20001,
480 HostPort: 20001,
481 HostIP: "127.0.0.1",
482 })
483 return pod
484 },
485 wantFwPorts: []api.ForwardedPort{
486 {
487 Platform: "podman",
488 ContainerName: "mycomponent",
489 PortName: "http",
490 LocalAddress: "127.0.0.1",
491 LocalPort: 20001,
492 ContainerPort: 8080,
493 IsDebug: false,
494 },
495 },
496 },
497 {
498 name: "basic component + application endpoint + debug endpoint - with debug / forwardLocalhost=false",
499 args: args{
500 devfileObj: func() parser.DevfileObj {
501 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
502 _ = data.AddCommands([]v1alpha2.Command{command})
503 cmp := baseComponent.DeepCopy()
504 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
505 Name: "http",
506 TargetPort: 8080,
507 })
508 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
509 Name: "debug",
510 TargetPort: 5858,
511 })
512 _ = data.AddComponents([]v1alpha2.Component{*cmp})
513 return parser.DevfileObj{
514 Data: data,
515 }
516 },
517 componentName: devfileName,
518 appName: appName,
519 debug: true,
520 },
521 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
522 pod := basePod.DeepCopy()
523 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
524 Name: "http",
525 ContainerPort: 8080,
526 HostPort: 20001,
527 Protocol: corev1.ProtocolTCP,
528 HostIP: "127.0.0.1",
529 })
530 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
531 Name: "debug",
532 ContainerPort: 5858,
533 HostPort: 20002,
534 Protocol: corev1.ProtocolTCP,
535 HostIP: "127.0.0.1",
536 })
537 return pod
538 },
539 wantFwPorts: []api.ForwardedPort{
540 {
541 Platform: "podman",
542 ContainerName: "mycomponent",
543 PortName: "http",
544 LocalAddress: "127.0.0.1",
545 LocalPort: 20001,
546 ContainerPort: 8080,
547 IsDebug: false,
548 },
549 {
550 Platform: "podman",
551 ContainerName: "mycomponent",
552 PortName: "debug",
553 LocalAddress: "127.0.0.1",
554 LocalPort: 20002,
555 ContainerPort: 5858,
556 IsDebug: true,
557 },
558 },
559 },
560 {
561 name: "basic component + application endpoint + debug endpoint - with debug / forwardLocalhost=true",
562 args: args{
563 devfileObj: func() parser.DevfileObj {
564 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
565 _ = data.AddCommands([]v1alpha2.Command{command})
566 cmp := baseComponent.DeepCopy()
567 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
568 Name: "http",
569 TargetPort: 8080,
570 })
571 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
572 Name: "debug",
573 TargetPort: 5858,
574 })
575 _ = data.AddComponents([]v1alpha2.Component{*cmp})
576 return parser.DevfileObj{
577 Data: data,
578 }
579 },
580 componentName: devfileName,
581 appName: appName,
582 debug: true,
583 forwardLocalhost: true,
584 },
585 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
586 pod := basePod.DeepCopy()
587 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
588 Name: "http",
589 ContainerPort: 20001,
590 HostPort: 20001,
591 HostIP: "127.0.0.1",
592 })
593 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
594 Name: "debug",
595 ContainerPort: 20002,
596 HostPort: 20002,
597 HostIP: "127.0.0.1",
598 })
599 return pod
600 },
601 wantFwPorts: []api.ForwardedPort{
602 {
603 Platform: "podman",
604 ContainerName: "mycomponent",
605 PortName: "http",
606 LocalAddress: "127.0.0.1",
607 LocalPort: 20001,
608 ContainerPort: 8080,
609 IsDebug: false,
610 },
611 {
612 Platform: "podman",
613 ContainerName: "mycomponent",
614 PortName: "debug",
615 LocalAddress: "127.0.0.1",
616 LocalPort: 20002,
617 ContainerPort: 5858,
618 IsDebug: true,
619 },
620 },
621 },
622 {
623 name: "basic component with volume mount / forwardLocalhost=false",
624 args: args{
625 devfileObj: func() parser.DevfileObj {
626 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
627 _ = data.AddCommands([]v1alpha2.Command{command})
628 _ = data.AddComponents([]v1alpha2.Component{baseComponent, volume})
629 _ = data.AddVolumeMounts(baseComponent.Name, []v1alpha2.VolumeMount{
630 {
631 Name: volume.Name,
632 Path: "/path/to/mount",
633 },
634 })
635
636 return parser.DevfileObj{
637 Data: data,
638 }
639 },
640 componentName: devfileName,
641 appName: appName,
642 },
643 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
644 pod := basePod.DeepCopy()
645 pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
646 Name: volume.Name,
647 VolumeSource: corev1.VolumeSource{
648 PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
649 ClaimName: volume.Name + "-" + devfileName + "-" + appName,
650 },
651 },
652 })
653 pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
654 Name: volume.Name,
655 MountPath: "/path/to/mount",
656 })
657 return pod
658 },
659 },
660 {
661 name: "basic component with volume mount / forwardLocalhost=true",
662 args: args{
663 devfileObj: func() parser.DevfileObj {
664 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
665 _ = data.AddCommands([]v1alpha2.Command{command})
666 _ = data.AddComponents([]v1alpha2.Component{baseComponent, volume})
667 _ = data.AddVolumeMounts(baseComponent.Name, []v1alpha2.VolumeMount{
668 {
669 Name: volume.Name,
670 Path: "/path/to/mount",
671 },
672 })
673
674 return parser.DevfileObj{
675 Data: data,
676 }
677 },
678 componentName: devfileName,
679 appName: appName,
680 forwardLocalhost: true,
681 },
682 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
683 pod := basePod.DeepCopy()
684 pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
685 Name: volume.Name,
686 VolumeSource: corev1.VolumeSource{
687 PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
688 ClaimName: volume.Name + "-" + devfileName + "-" + appName,
689 },
690 },
691 })
692 pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
693 Name: volume.Name,
694 MountPath: "/path/to/mount",
695 })
696 return pod
697 },
698 },
699 {
700 name: "basic component + application endpoint + debug endpoint + container ports known - with debug / forwardLocalhost=false",
701 args: args{
702 devfileObj: func() parser.DevfileObj {
703 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
704 _ = data.AddCommands([]v1alpha2.Command{command})
705 cmp := baseComponent.DeepCopy()
706 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
707 Name: "http",
708 TargetPort: 20001,
709 })
710 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
711 Name: "debug",
712 TargetPort: 20002,
713 })
714 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
715 Name: "debug-1",
716 TargetPort: 5858,
717 })
718 _ = data.AddComponents([]v1alpha2.Component{*cmp})
719 return parser.DevfileObj{
720 Data: data,
721 }
722 },
723 componentName: devfileName,
724 appName: appName,
725 debug: true,
726 },
727 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
728 pod := basePod.DeepCopy()
729 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
730 Name: "http",
731 ContainerPort: 20001,
732 HostPort: 20003,
733 Protocol: corev1.ProtocolTCP,
734 HostIP: "127.0.0.1",
735 })
736 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
737 Name: "debug",
738 ContainerPort: 20002,
739 HostPort: 20004,
740 Protocol: corev1.ProtocolTCP,
741 HostIP: "127.0.0.1",
742 })
743 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
744 Name: "debug-1",
745 ContainerPort: 5858,
746 HostPort: 20005,
747 Protocol: corev1.ProtocolTCP,
748 HostIP: "127.0.0.1",
749 })
750 return pod
751 },
752 wantFwPorts: []api.ForwardedPort{
753 {
754 Platform: "podman",
755 ContainerName: "mycomponent",
756 PortName: "http",
757 LocalAddress: "127.0.0.1",
758 LocalPort: 20003,
759 ContainerPort: 20001,
760 IsDebug: false,
761 },
762 {
763 Platform: "podman",
764 ContainerName: "mycomponent",
765 PortName: "debug",
766 LocalAddress: "127.0.0.1",
767 LocalPort: 20004,
768 ContainerPort: 20002,
769 IsDebug: true,
770 },
771 {
772 Platform: "podman",
773 ContainerName: "mycomponent",
774 PortName: "debug-1",
775 LocalAddress: "127.0.0.1",
776 LocalPort: 20005,
777 ContainerPort: 5858,
778 IsDebug: true,
779 },
780 },
781 },
782 {
783 name: "basic component + application endpoint + debug endpoint + container ports known - with debug / forwardLocalhost=true",
784 args: args{
785 devfileObj: func() parser.DevfileObj {
786 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
787 _ = data.AddCommands([]v1alpha2.Command{command})
788 cmp := baseComponent.DeepCopy()
789 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
790 Name: "http",
791 TargetPort: 20001,
792 })
793 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
794 Name: "debug",
795 TargetPort: 20002,
796 })
797 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
798 Name: "debug-1",
799 TargetPort: 5858,
800 })
801 _ = data.AddComponents([]v1alpha2.Component{*cmp})
802 return parser.DevfileObj{
803 Data: data,
804 }
805 },
806 componentName: devfileName,
807 appName: appName,
808 debug: true,
809 forwardLocalhost: true,
810 },
811 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
812 pod := basePod.DeepCopy()
813 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
814 Name: "http",
815 ContainerPort: 20003,
816 HostPort: 20003,
817 HostIP: "127.0.0.1",
818 })
819 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
820 Name: "debug",
821 ContainerPort: 20004,
822 HostPort: 20004,
823 HostIP: "127.0.0.1",
824 })
825 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
826 Name: "debug-1",
827 ContainerPort: 20005,
828 HostPort: 20005,
829 HostIP: "127.0.0.1",
830 })
831 return pod
832 },
833 wantFwPorts: []api.ForwardedPort{
834 {
835 Platform: "podman",
836 ContainerName: "mycomponent",
837 PortName: "http",
838 LocalAddress: "127.0.0.1",
839 LocalPort: 20003,
840 ContainerPort: 20001,
841 IsDebug: false,
842 },
843 {
844 Platform: "podman",
845 ContainerName: "mycomponent",
846 PortName: "debug",
847 LocalAddress: "127.0.0.1",
848 LocalPort: 20004,
849 ContainerPort: 20002,
850 IsDebug: true,
851 },
852 {
853 Platform: "podman",
854 ContainerName: "mycomponent",
855 PortName: "debug-1",
856 LocalAddress: "127.0.0.1",
857 LocalPort: 20005,
858 ContainerPort: 5858,
859 IsDebug: true,
860 },
861 },
862 },
863 {
864 name: "basic component + application endpoint + debug endpoint + container ports known - without debug / forwardLocalhost=false",
865 args: args{
866 devfileObj: func() parser.DevfileObj {
867 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
868 _ = data.AddCommands([]v1alpha2.Command{command})
869 cmp := baseComponent.DeepCopy()
870 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
871 Name: "http",
872 TargetPort: 20001,
873 })
874 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
875 Name: "debug",
876 TargetPort: 20002,
877 })
878 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
879 Name: "debug-1",
880 TargetPort: 5858,
881 })
882 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
883 Name: "http-1",
884 TargetPort: 8080,
885 })
886 _ = data.AddComponents([]v1alpha2.Component{*cmp})
887 return parser.DevfileObj{
888 Data: data,
889 }
890 },
891 componentName: devfileName,
892 appName: appName,
893 debug: false,
894 },
895 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
896 pod := basePod.DeepCopy()
897 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
898 Name: "http",
899 ContainerPort: 20001,
900 HostPort: 20002,
901 Protocol: corev1.ProtocolTCP,
902 HostIP: "127.0.0.1",
903 })
904 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
905 Name: "http-1",
906 ContainerPort: 8080,
907 HostPort: 20003,
908 Protocol: corev1.ProtocolTCP,
909 HostIP: "127.0.0.1",
910 })
911 return pod
912 },
913 wantFwPorts: []api.ForwardedPort{
914 {
915 Platform: "podman",
916 ContainerName: "mycomponent",
917 PortName: "http",
918 LocalAddress: "127.0.0.1",
919 LocalPort: 20002,
920 ContainerPort: 20001,
921 IsDebug: false,
922 },
923 {
924 Platform: "podman",
925 ContainerName: "mycomponent",
926 PortName: "http-1",
927 LocalAddress: "127.0.0.1",
928 LocalPort: 20003,
929 ContainerPort: 8080,
930 IsDebug: false,
931 },
932 },
933 },
934 {
935 name: "basic component + application endpoint + debug endpoint + container ports known - without debug / forwardLocalhost=true",
936 args: args{
937 devfileObj: func() parser.DevfileObj {
938 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
939 _ = data.AddCommands([]v1alpha2.Command{command})
940 cmp := baseComponent.DeepCopy()
941 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
942 Name: "http",
943 TargetPort: 20001,
944 })
945 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
946 Name: "debug",
947 TargetPort: 20002,
948 })
949 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
950 Name: "debug-1",
951 TargetPort: 5858,
952 })
953 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
954 Name: "http-1",
955 TargetPort: 8080,
956 })
957 _ = data.AddComponents([]v1alpha2.Component{*cmp})
958 return parser.DevfileObj{
959 Data: data,
960 }
961 },
962 componentName: devfileName,
963 appName: appName,
964 debug: false,
965 forwardLocalhost: true,
966 },
967 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
968 pod := basePod.DeepCopy()
969 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
970 Name: "http",
971 ContainerPort: 20002,
972 HostPort: 20002,
973 HostIP: "127.0.0.1",
974 })
975 pod.Spec.Containers[1].Ports = append(pod.Spec.Containers[1].Ports, corev1.ContainerPort{
976 Name: "http-1",
977 ContainerPort: 20003,
978 HostPort: 20003,
979 HostIP: "127.0.0.1",
980 })
981 return pod
982 },
983 wantFwPorts: []api.ForwardedPort{
984 {
985 Platform: "podman",
986 ContainerName: "mycomponent",
987 PortName: "http",
988 LocalAddress: "127.0.0.1",
989 LocalPort: 20002,
990 ContainerPort: 20001,
991 IsDebug: false,
992 },
993 {
994 Platform: "podman",
995 ContainerName: "mycomponent",
996 PortName: "http-1",
997 LocalAddress: "127.0.0.1",
998 LocalPort: 20003,
999 ContainerPort: 8080,
1000 IsDebug: false,
1001 },
1002 },
1003 },
1004
1005 {
1006 name: "basic component + application endpoint + debug endpoint - with debug / custom mapping for port forwarding with container name (customForwardedPorts)",
1007 args: args{
1008 devfileObj: func() parser.DevfileObj {
1009 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
1010 _ = data.AddCommands([]v1alpha2.Command{command})
1011 cmp := baseComponent.DeepCopy()
1012 cmp.Name = "runtime"
1013 cmp.Container.Endpoints = []v1alpha2.Endpoint{
1014 {
1015 Name: "http-8080",
1016 TargetPort: 8080,
1017 },
1018 {
1019 Name: "debug",
1020 TargetPort: 5858,
1021 },
1022 }
1023
1024 cmp2 := baseComponent.DeepCopy()
1025 cmp2.Name = "tools"
1026 cmp2.Container.Endpoints = []v1alpha2.Endpoint{
1027 {
1028 Name: "http-5000",
1029 TargetPort: 5000,
1030 },
1031 }
1032 _ = data.AddComponents([]v1alpha2.Component{*cmp, *cmp2})
1033 return parser.DevfileObj{
1034 Data: data,
1035 }
1036 },
1037 componentName: devfileName,
1038 appName: appName,
1039 debug: true,
1040 customForwardedPorts: []api.ForwardedPort{
1041 {
1042 ContainerName: "runtime",
1043 LocalPort: 8080,
1044 ContainerPort: 8080,
1045 },
1046 },
1047 },
1048 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
1049 pod := basePod.DeepCopy()
1050 pod.Spec.Containers[0].Name = "runtime"
1051 pod.Spec.Containers[0].Ports = []corev1.ContainerPort{
1052 {
1053 Name: "http-8080",
1054 ContainerPort: 8080,
1055 HostPort: 8080,
1056 Protocol: corev1.ProtocolTCP,
1057 HostIP: "127.0.0.1",
1058 },
1059 {
1060 Name: "debug",
1061 ContainerPort: 5858,
1062 HostPort: 20001,
1063 Protocol: corev1.ProtocolTCP,
1064 HostIP: "127.0.0.1",
1065 },
1066 }
1067 container2 := pod.Spec.Containers[0].DeepCopy()
1068 container2.Name = "tools"
1069 container2.Ports = []corev1.ContainerPort{
1070 {
1071 Name: "http-5000",
1072 ContainerPort: 5000,
1073 HostPort: 20002,
1074 Protocol: corev1.ProtocolTCP,
1075 HostIP: "127.0.0.1",
1076 },
1077 }
1078 pod.Spec.Containers = append(pod.Spec.Containers, *container2)
1079 return pod
1080 },
1081 wantFwPorts: []api.ForwardedPort{
1082 {
1083 Platform: "podman",
1084 ContainerName: "runtime",
1085 PortName: "http-8080",
1086 LocalAddress: "127.0.0.1",
1087 LocalPort: 8080,
1088 ContainerPort: 8080,
1089 IsDebug: false,
1090 },
1091 {
1092 Platform: "podman",
1093 ContainerName: "runtime",
1094 PortName: "debug",
1095 LocalAddress: "127.0.0.1",
1096 LocalPort: 20001,
1097 ContainerPort: 5858,
1098 IsDebug: true,
1099 },
1100 {
1101 Platform: "podman",
1102 ContainerName: "tools",
1103 PortName: "http-5000",
1104 LocalAddress: "127.0.0.1",
1105 LocalPort: 20002,
1106 ContainerPort: 5000,
1107 IsDebug: false,
1108 },
1109 },
1110 },
1111 {
1112 name: "basic component + application endpoint + debug endpoint - with debug / custom mapping for port forwarding without container name (customForwardedPorts)",
1113 args: args{
1114 devfileObj: func() parser.DevfileObj {
1115 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
1116 _ = data.AddCommands([]v1alpha2.Command{command})
1117 cmp := baseComponent.DeepCopy()
1118 cmp.Name = "runtime"
1119 cmp.Container.Endpoints = []v1alpha2.Endpoint{
1120 {
1121 Name: "http-8080",
1122
1123 TargetPort: 8080,
1124 },
1125 {
1126 Name: "debug",
1127 TargetPort: 5858,
1128 },
1129 }
1130 cmp2 := baseComponent.DeepCopy()
1131 cmp2.Name = "tools"
1132 cmp2.Container.Endpoints = []v1alpha2.Endpoint{
1133 {
1134 Name: "http-5000",
1135 TargetPort: 5000,
1136 },
1137 }
1138
1139 _ = data.AddComponents([]v1alpha2.Component{*cmp, *cmp2})
1140 return parser.DevfileObj{
1141 Data: data,
1142 }
1143 },
1144 componentName: devfileName,
1145 appName: appName,
1146 debug: true,
1147 customForwardedPorts: []api.ForwardedPort{
1148 {
1149 LocalPort: 8080,
1150 ContainerPort: 8080,
1151 },
1152 {
1153 LocalPort: 5000,
1154 ContainerPort: 5000,
1155 },
1156 },
1157 },
1158 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
1159 pod := basePod.DeepCopy()
1160 pod.Spec.Containers[0].Name = "runtime"
1161 pod.Spec.Containers[0].Ports = []corev1.ContainerPort{
1162 {
1163 Name: "http-8080",
1164 ContainerPort: 8080,
1165 HostPort: 8080,
1166 Protocol: corev1.ProtocolTCP,
1167 HostIP: "127.0.0.1",
1168 }, {
1169 Name: "debug",
1170 ContainerPort: 5858,
1171 HostPort: 20001,
1172 Protocol: corev1.ProtocolTCP,
1173 HostIP: "127.0.0.1",
1174 },
1175 }
1176 container2 := pod.Spec.Containers[0].DeepCopy()
1177 container2.Name = "tools"
1178 container2.Ports = []corev1.ContainerPort{
1179 {
1180 Name: "http-5000",
1181 ContainerPort: 5000,
1182 HostPort: 5000,
1183 Protocol: corev1.ProtocolTCP,
1184 HostIP: "127.0.0.1",
1185 },
1186 }
1187 pod.Spec.Containers = append(pod.Spec.Containers, *container2)
1188 return pod
1189 },
1190 wantFwPorts: []api.ForwardedPort{
1191 {
1192 Platform: "podman",
1193 ContainerName: "runtime",
1194 PortName: "http-8080",
1195 LocalAddress: "127.0.0.1",
1196 LocalPort: 8080,
1197 ContainerPort: 8080,
1198 IsDebug: false,
1199 },
1200 {
1201 Platform: "podman",
1202 ContainerName: "runtime",
1203 PortName: "debug",
1204 LocalAddress: "127.0.0.1",
1205 LocalPort: 20001,
1206 ContainerPort: 5858,
1207 IsDebug: true,
1208 },
1209 {
1210 Platform: "podman",
1211 ContainerName: "tools",
1212 PortName: "http-5000",
1213 LocalAddress: "127.0.0.1",
1214 LocalPort: 5000,
1215 ContainerPort: 5000,
1216 IsDebug: false,
1217 },
1218 },
1219 },
1220 {
1221 name: "basic component + application endpoint + debug endpoint - with debug / custom mapping for port forwarding with local port in ranged [20001-30001] ports (customForwardedPorts)",
1222 args: args{
1223 devfileObj: func() parser.DevfileObj {
1224 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
1225 _ = data.AddCommands([]v1alpha2.Command{command})
1226 cmp := baseComponent.DeepCopy()
1227 cmp.Name = "runtime"
1228 cmp.Container.Endpoints = []v1alpha2.Endpoint{
1229 {
1230 Name: "http-8080",
1231 TargetPort: 8080,
1232 },
1233 {
1234 Name: "debug",
1235 TargetPort: 5858,
1236 },
1237 }
1238
1239 cmp2 := baseComponent.DeepCopy()
1240 cmp2.Name = "tools"
1241 cmp2.Container.Endpoints = []v1alpha2.Endpoint{
1242 {
1243 Name: "http-9000",
1244 TargetPort: 9000,
1245 },
1246 {
1247 Name: "http-5000",
1248 TargetPort: 5000,
1249 },
1250 }
1251
1252 _ = data.AddComponents([]v1alpha2.Component{*cmp, *cmp2})
1253 return parser.DevfileObj{
1254 Data: data,
1255 }
1256 },
1257 componentName: devfileName,
1258 appName: appName,
1259 debug: true,
1260 customForwardedPorts: []api.ForwardedPort{
1261 {
1262 LocalPort: 20001,
1263 ContainerPort: 8080,
1264 },
1265 {
1266 LocalPort: 20002,
1267 ContainerPort: 9000,
1268 },
1269 {
1270 LocalPort: 5000,
1271 ContainerPort: 5000,
1272 },
1273 },
1274 },
1275 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
1276 pod := basePod.DeepCopy()
1277 pod.Spec.Containers[0].Name = "runtime"
1278 pod.Spec.Containers[0].Ports = []corev1.ContainerPort{
1279 {
1280 Name: "http-8080",
1281 ContainerPort: 8080,
1282 HostPort: 20001,
1283 Protocol: corev1.ProtocolTCP,
1284 HostIP: "127.0.0.1",
1285 },
1286 {
1287 Name: "debug",
1288 ContainerPort: 5858,
1289 HostPort: 20003,
1290 Protocol: corev1.ProtocolTCP,
1291 HostIP: "127.0.0.1",
1292 },
1293 }
1294 container2 := pod.Spec.Containers[0].DeepCopy()
1295 container2.Name = "tools"
1296 container2.Ports = []corev1.ContainerPort{
1297 {
1298 Name: "http-9000",
1299 ContainerPort: 9000,
1300 HostPort: 20002,
1301 Protocol: corev1.ProtocolTCP,
1302 HostIP: "127.0.0.1",
1303 },
1304 {
1305 Name: "http-5000",
1306 ContainerPort: 5000,
1307 HostPort: 5000,
1308 Protocol: corev1.ProtocolTCP,
1309 HostIP: "127.0.0.1",
1310 },
1311 }
1312 pod.Spec.Containers = append(pod.Spec.Containers, *container2)
1313 return pod
1314 },
1315 wantFwPorts: []api.ForwardedPort{
1316 {
1317 Platform: "podman",
1318 ContainerName: "runtime",
1319 PortName: "http-8080",
1320 LocalAddress: "127.0.0.1",
1321 LocalPort: 20001,
1322 ContainerPort: 8080,
1323 IsDebug: false,
1324 },
1325 {
1326 Platform: "podman",
1327 ContainerName: "runtime",
1328 PortName: "debug",
1329 LocalAddress: "127.0.0.1",
1330 LocalPort: 20003,
1331 ContainerPort: 5858,
1332 IsDebug: true,
1333 },
1334 {
1335 Platform: "podman",
1336 ContainerName: "tools",
1337 PortName: "http-9000",
1338 LocalAddress: "127.0.0.1",
1339 LocalPort: 20002,
1340 ContainerPort: 9000,
1341 IsDebug: false,
1342 },
1343 {
1344 Platform: "podman",
1345 ContainerName: "tools",
1346 PortName: "http-5000",
1347 LocalAddress: "127.0.0.1",
1348 LocalPort: 5000,
1349 ContainerPort: 5000,
1350 IsDebug: false,
1351 },
1352 },
1353 },
1354
1355 {
1356 name: "basic component + application endpoint + debug endpoint + container ports known - with debug / using customAddress",
1357 args: args{
1358 devfileObj: func() parser.DevfileObj {
1359 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
1360 _ = data.AddCommands([]v1alpha2.Command{command})
1361 cmp := baseComponent.DeepCopy()
1362 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
1363 Name: "http",
1364 TargetPort: 20001,
1365 })
1366 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
1367 Name: "debug",
1368 TargetPort: 20002,
1369 })
1370 cmp.Container.Endpoints = append(cmp.Container.Endpoints, v1alpha2.Endpoint{
1371 Name: "debug-1",
1372 TargetPort: 5858,
1373 })
1374 _ = data.AddComponents([]v1alpha2.Component{*cmp})
1375 return parser.DevfileObj{
1376 Data: data,
1377 }
1378 },
1379 componentName: devfileName,
1380 appName: appName,
1381 debug: true,
1382 customAddress: "192.168.0.1",
1383 },
1384 wantPod: func(basePod *corev1.Pod) *corev1.Pod {
1385 pod := basePod.DeepCopy()
1386 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
1387 Name: "http",
1388 ContainerPort: 20001,
1389 HostPort: 20003,
1390 Protocol: corev1.ProtocolTCP,
1391 HostIP: "192.168.0.1",
1392 })
1393 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
1394 Name: "debug",
1395 ContainerPort: 20002,
1396 HostPort: 20004,
1397 Protocol: corev1.ProtocolTCP,
1398 HostIP: "192.168.0.1",
1399 })
1400 pod.Spec.Containers[0].Ports = append(pod.Spec.Containers[0].Ports, corev1.ContainerPort{
1401 Name: "debug-1",
1402 ContainerPort: 5858,
1403 HostPort: 20005,
1404 Protocol: corev1.ProtocolTCP,
1405 HostIP: "192.168.0.1",
1406 })
1407 return pod
1408 },
1409 wantFwPorts: []api.ForwardedPort{
1410 {
1411 Platform: "podman",
1412 ContainerName: "mycomponent",
1413 PortName: "http",
1414 LocalAddress: "192.168.0.1",
1415 LocalPort: 20003,
1416 ContainerPort: 20001,
1417 IsDebug: false,
1418 },
1419 {
1420 Platform: "podman",
1421 ContainerName: "mycomponent",
1422 PortName: "debug",
1423 LocalAddress: "192.168.0.1",
1424 LocalPort: 20004,
1425 ContainerPort: 20002,
1426 IsDebug: true,
1427 },
1428 {
1429 Platform: "podman",
1430 ContainerName: "mycomponent",
1431 PortName: "debug-1",
1432 LocalAddress: "192.168.0.1",
1433 LocalPort: 20005,
1434 ContainerPort: 5858,
1435 IsDebug: true,
1436 },
1437 },
1438 },
1439 }
1440 for _, tt := range tests {
1441 t.Run(tt.name, func(t *testing.T) {
1442 ctx := context.Background()
1443 devfileObj := tt.args.devfileObj()
1444 ctx = odocontext.WithEffectiveDevfileObj(ctx, &devfileObj)
1445 ctx = odocontext.WithApplication(ctx, tt.args.appName)
1446 ctx = odocontext.WithComponentName(ctx, tt.args.componentName)
1447 ctx = odocontext.WithWorkingDirectory(ctx, "/tmp/dir")
1448 ctrl := gomock.NewController(t)
1449 podmanClient := podman.NewMockClient(ctrl)
1450 podmanClient.EXPECT().GetCapabilities().Return(tt.capabilities, nil)
1451 client := NewDevClient(
1452 nil, podmanClient, nil, nil, nil, nil, nil, nil,
1453 )
1454 got, gotFwPorts, err := client.createPodFromComponent(
1455 ctx,
1456 tt.args.debug,
1457 tt.args.buildCommand,
1458 tt.args.runCommand,
1459 tt.args.debugCommand,
1460 tt.args.forwardLocalhost,
1461 false,
1462 tt.args.customForwardedPorts,
1463 []int{20001, 20002, 20003, 20004, 20005},
1464 tt.args.customAddress,
1465 devfileObj,
1466 )
1467 if (err != nil) != tt.wantErr {
1468 t.Errorf("createPodFromComponent() error = %v, wantErr %v", err, tt.wantErr)
1469 return
1470 }
1471
1472 basePod := buildBasePod(tt.args.forwardLocalhost)
1473 if diff := cmp.Diff(tt.wantPod(basePod), got, cmpopts.EquateEmpty()); diff != "" {
1474 t.Errorf("createPodFromComponent() pod mismatch (-want +got):\n%s", diff)
1475 }
1476
1477 if diff := cmp.Diff(tt.wantFwPorts, gotFwPorts, cmpopts.EquateEmpty(), cmpopts.SortSlices(func(x, y api.ForwardedPort) bool { return x.ContainerName < y.ContainerName })); diff != "" {
1478 t.Errorf("createPodFromComponent() fwPorts mismatch (-want +got):\n%s", diff)
1479 }
1480 })
1481 }
1482 }
1483
View as plain text