@@ -74,6 +74,46 @@ func testPod(namespace, name string) *v1.Pod {
7474 }
7575 return p
7676}
77+
78+ func testPodWithPodLevelResources (namespace , name string ) * v1.Pod {
79+ restartAlways := v1 .ContainerRestartPolicyAlways
80+ p := & v1.Pod {
81+ ObjectMeta : metav1.ObjectMeta {
82+ Namespace : namespace ,
83+ Name : name ,
84+ },
85+ Status : v1.PodStatus {
86+ Phase : v1 .PodPending ,
87+ },
88+ Spec : v1.PodSpec {
89+ Resources : & v1.ResourceRequirements {
90+ Requests : v1.ResourceList {
91+ v1 .ResourceCPU : resource .MustParse ("10" ),
92+ v1 .ResourceMemory : resource .MustParse ("12Gi" ),
93+ },
94+ },
95+ InitContainers : []v1.Container {
96+ {
97+ Image : "normalinit" ,
98+ Name : "container" ,
99+ },
100+ {
101+ Image : "sidecar" ,
102+ Name : "container" ,
103+ RestartPolicy : & restartAlways ,
104+ },
105+ },
106+ Containers : []v1.Container {
107+ {
108+ Image : "test-image" ,
109+ Name : "container" ,
110+ },
111+ },
112+ },
113+ }
114+ return p
115+ }
116+
77117func TestNewPod (t * testing.T ) {
78118 pod := testPod ("default" , "mypod" )
79119 pod .Spec .NodeName = "mynode"
@@ -100,6 +140,15 @@ func TestNewPod(t *testing.T) {
100140 if exp , got := resource .MustParse ("2Gi" ), p .Requested ()[v1 .ResourceMemory ]; exp .Cmp (got ) != 0 {
101141 t .Errorf ("expected Memory = %s, got %s" , exp .String (), got .String ())
102142 }
143+
144+ podWithPodLevelResources := testPodWithPodLevelResources ("default" , "mypod" )
145+ pWithPodLevelResources := model .NewPod (podWithPodLevelResources )
146+ if exp , got := resource .MustParse ("10" ), pWithPodLevelResources .Requested ()[v1 .ResourceCPU ]; exp .Cmp (got ) != 0 {
147+ t .Errorf ("expected CPU = %s, got %s" , exp .String (), got .String ())
148+ }
149+ if exp , got := resource .MustParse ("12Gi" ), pWithPodLevelResources .Requested ()[v1 .ResourceMemory ]; exp .Cmp (got ) != 0 {
150+ t .Errorf ("expected Memory = %s, got %s" , exp .String (), got .String ())
151+ }
103152}
104153
105154func TestPodUpdate (t * testing.T ) {
0 commit comments