@@ -411,6 +411,109 @@ func Test_buildPodInfo(t *testing.T) {
411411 PodIP : "192.168.1.1" ,
412412 },
413413 },
414+ {
415+ name : "standard case - with ENIInfo" ,
416+ args : args {
417+ pod : & corev1.Pod {
418+ ObjectMeta : metav1.ObjectMeta {
419+ Namespace : "my-ns" ,
420+ Name : "pod-1" ,
421+ UID : "pod-uuid" ,
422+ Annotations : map [string ]string {
423+ "vpc.amazonaws.com/pod-eni" : `[{"eniId":"eni-06a712e1622fda4a0","ifAddress":"02:34:a5:25:0b:63","privateIp":"192.168.219.103","vlanId":3,"subnetCidr":"192.168.192.0/19"}]` ,
424+ },
425+ },
426+ Spec : corev1.PodSpec {
427+ Containers : []corev1.Container {
428+ {
429+ Ports : []corev1.ContainerPort {
430+ {
431+ Name : "ssh" ,
432+ ContainerPort : 22 ,
433+ },
434+ {
435+ Name : "http" ,
436+ ContainerPort : 8080 ,
437+ },
438+ },
439+ },
440+ {
441+ Ports : []corev1.ContainerPort {
442+ {
443+ Name : "https" ,
444+ ContainerPort : 8443 ,
445+ },
446+ },
447+ },
448+ },
449+ ReadinessGates : []corev1.PodReadinessGate {
450+ {
451+ ConditionType : "ingress.k8s.aws/cond-1" ,
452+ },
453+ {
454+ ConditionType : "ingress.k8s.aws/cond-2" ,
455+ },
456+ },
457+ },
458+ Status : corev1.PodStatus {
459+ Conditions : []corev1.PodCondition {
460+ {
461+ Type : corev1 .ContainersReady ,
462+ Status : corev1 .ConditionFalse ,
463+ },
464+ {
465+ Type : "ingress.k8s.aws/cond-2" ,
466+ Status : corev1 .ConditionTrue ,
467+ },
468+ },
469+ PodIP : "192.168.1.1" ,
470+ },
471+ },
472+ },
473+ want : PodInfo {
474+ Key : types.NamespacedName {Namespace : "my-ns" , Name : "pod-1" },
475+ UID : "pod-uuid" ,
476+ ContainerPorts : []corev1.ContainerPort {
477+ {
478+ Name : "ssh" ,
479+ ContainerPort : 22 ,
480+ },
481+ {
482+ Name : "http" ,
483+ ContainerPort : 8080 ,
484+ },
485+ {
486+ Name : "https" ,
487+ ContainerPort : 8443 ,
488+ },
489+ },
490+ ReadinessGates : []corev1.PodReadinessGate {
491+ {
492+ ConditionType : "ingress.k8s.aws/cond-1" ,
493+ },
494+ {
495+ ConditionType : "ingress.k8s.aws/cond-2" ,
496+ },
497+ },
498+ Conditions : []corev1.PodCondition {
499+ {
500+ Type : corev1 .ContainersReady ,
501+ Status : corev1 .ConditionFalse ,
502+ },
503+ {
504+ Type : "ingress.k8s.aws/cond-2" ,
505+ Status : corev1 .ConditionTrue ,
506+ },
507+ },
508+ PodIP : "192.168.1.1" ,
509+ ENIInfos : []PodENIInfo {
510+ {
511+ ENIID : "eni-06a712e1622fda4a0" ,
512+ PrivateIP : "192.168.219.103" ,
513+ },
514+ },
515+ },
516+ },
414517 }
415518 for _ , tt := range tests {
416519 t .Run (tt .name , func (t * testing.T ) {
@@ -427,24 +530,27 @@ func Test_buildPodENIInfo(t *testing.T) {
427530 tests := []struct {
428531 name string
429532 args args
430- want * PodENIInfo
533+ want [] PodENIInfo
431534 wantErr error
432535 }{
433- //{
434- // name: "pod-eni annotation exists and valid",
435- // args: args{
436- // pod: &corev1.Pod{
437- // ObjectMeta: metav1.ObjectMeta{
438- // Annotations: map[string]string{
439- // "vpc.amazonaws.com/pod-eni": `[{"eniId":"eni-04df112df841b9465","ifAddress":"02:2d:47:ec:a5:e3","privateIp":"192.168.129.175","vlanId":1,"subnetCidr":"192.168.128.0/19"}]`,
440- // },
441- // },
442- // },
443- // },
444- // want: &PodENIInfo{
445- // ENIID: "eni-04df112df841b9465",
446- // },
447- //},
536+ {
537+ name : "pod-eni annotation exists and valid" ,
538+ args : args {
539+ pod : & corev1.Pod {
540+ ObjectMeta : metav1.ObjectMeta {
541+ Annotations : map [string ]string {
542+ "vpc.amazonaws.com/pod-eni" : `[{"eniId":"eni-06a712e1622fda4a0","ifAddress":"02:34:a5:25:0b:63","privateIp":"192.168.219.103","vlanId":3,"subnetCidr":"192.168.192.0/19"}]` ,
543+ },
544+ },
545+ },
546+ },
547+ want : []PodENIInfo {
548+ {
549+ ENIID : "eni-06a712e1622fda4a0" ,
550+ PrivateIP : "192.168.219.103" ,
551+ },
552+ },
553+ },
448554 {
449555 name : "pod-eni annotation didn't exist" ,
450556 args : args {
@@ -472,7 +578,7 @@ func Test_buildPodENIInfo(t *testing.T) {
472578 }
473579 for _ , tt := range tests {
474580 t .Run (tt .name , func (t * testing.T ) {
475- got , err := buildPodENIInfo (tt .args .pod )
581+ got , err := buildPodENIInfos (tt .args .pod )
476582 if tt .wantErr != nil {
477583 assert .EqualError (t , err , tt .wantErr .Error ())
478584 } else {
0 commit comments