@@ -141,14 +141,9 @@ func logPodResources(podIdx int, pr *kubeletpodresourcesv1.PodResources) {
141
141
142
142
type podResMap map [string ]map [string ]kubeletpodresourcesv1.ContainerResources
143
143
144
- func getPodResourcesValues (ctx context.Context , cli kubeletpodresourcesv1.PodResourcesListerClient ) (podResMap , error ) {
145
- resp , err := cli .List (ctx , & kubeletpodresourcesv1.ListPodResourcesRequest {})
146
- if err != nil {
147
- return nil , err
148
- }
149
-
144
+ func convertToMap (podsResources []* kubeletpodresourcesv1.PodResources ) podResMap {
150
145
res := make (map [string ]map [string ]kubeletpodresourcesv1.ContainerResources )
151
- for idx , podResource := range resp . GetPodResources () {
146
+ for idx , podResource := range podsResources {
152
147
// to make troubleshooting easier
153
148
logPodResources (idx , podResource )
154
149
@@ -158,7 +153,15 @@ func getPodResourcesValues(ctx context.Context, cli kubeletpodresourcesv1.PodRes
158
153
}
159
154
res [podResource .GetName ()] = cnts
160
155
}
161
- return res , nil
156
+ return res
157
+ }
158
+
159
+ func getPodResourcesValues (ctx context.Context , cli kubeletpodresourcesv1.PodResourcesListerClient ) (podResMap , error ) {
160
+ resp , err := cli .List (ctx , & kubeletpodresourcesv1.ListPodResourcesRequest {})
161
+ if err != nil {
162
+ return nil , err
163
+ }
164
+ return convertToMap (resp .GetPodResources ()), nil
162
165
}
163
166
164
167
type testPodData struct {
@@ -568,6 +571,53 @@ func podresourcesGetAllocatableResourcesTests(ctx context.Context, cli kubeletpo
568
571
}
569
572
}
570
573
574
+ func podresourcesGetTests (ctx context.Context , f * framework.Framework , cli kubeletpodresourcesv1.PodResourcesListerClient ) {
575
+ //var err error
576
+ ginkgo .By ("checking the output when no pods are present" )
577
+ expected := []podDesc {}
578
+ resp , err := cli .Get (ctx , & kubeletpodresourcesv1.GetPodResourcesRequest {PodName : "test" , PodNamespace : f .Namespace .Name })
579
+ podResourceList := []* kubeletpodresourcesv1.PodResources {resp .GetPodResources ()}
580
+ framework .ExpectError (err , "pod not found" )
581
+ res := convertToMap (podResourceList )
582
+ err = matchPodDescWithResources (expected , res )
583
+ framework .ExpectNoError (err , "matchPodDescWithResources() failed err %v" , err )
584
+
585
+ tpd := newTestPodData ()
586
+ ginkgo .By ("checking the output when only pods which don't require resources are present" )
587
+ expected = []podDesc {
588
+ {
589
+ podName : "pod-00" ,
590
+ cntName : "cnt-00" ,
591
+ },
592
+ }
593
+ tpd .createPodsForTest (ctx , f , expected )
594
+ resp , err = cli .Get (ctx , & kubeletpodresourcesv1.GetPodResourcesRequest {PodName : "pod-00" , PodNamespace : f .Namespace .Name })
595
+ framework .ExpectNoError (err , "Get() call failed for pod %s/%s" , f .Namespace .Name , "pod-00" )
596
+ podResourceList = []* kubeletpodresourcesv1.PodResources {resp .GetPodResources ()}
597
+ res = convertToMap (podResourceList )
598
+ err = matchPodDescWithResources (expected , res )
599
+ framework .ExpectNoError (err , "matchPodDescWithResources() failed err %v" , err )
600
+ tpd .deletePodsForTest (ctx , f )
601
+
602
+ tpd = newTestPodData ()
603
+ ginkgo .By ("checking the output when only pod require CPU" )
604
+ expected = []podDesc {
605
+ {
606
+ podName : "pod-01" ,
607
+ cntName : "cnt-00" ,
608
+ cpuRequest : 2000 ,
609
+ },
610
+ }
611
+ tpd .createPodsForTest (ctx , f , expected )
612
+ resp , err = cli .Get (ctx , & kubeletpodresourcesv1.GetPodResourcesRequest {PodName : "pod-01" , PodNamespace : f .Namespace .Name })
613
+ framework .ExpectNoError (err , "Get() call failed for pod %s/%s" , f .Namespace .Name , "pod-01" )
614
+ podResourceList = []* kubeletpodresourcesv1.PodResources {resp .GetPodResources ()}
615
+ res = convertToMap (podResourceList )
616
+ err = matchPodDescWithResources (expected , res )
617
+ framework .ExpectNoError (err , "matchPodDescWithResources() failed err %v" , err )
618
+ tpd .deletePodsForTest (ctx , f )
619
+ }
620
+
571
621
// Serial because the test updates kubelet configuration.
572
622
var _ = SIGDescribe ("POD Resources [Serial] [Feature:PodResources][NodeFeature:PodResources]" , func () {
573
623
f := framework .NewDefaultFramework ("podresources-test" )
@@ -686,6 +736,10 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
686
736
cpus := reservedSystemCPUs .String ()
687
737
framework .Logf ("configurePodResourcesInKubelet: using reservedSystemCPUs=%q" , cpus )
688
738
initialConfig .ReservedSystemCPUs = cpus
739
+ if initialConfig .FeatureGates == nil {
740
+ initialConfig .FeatureGates = make (map [string ]bool )
741
+ }
742
+ initialConfig .FeatureGates [string (kubefeatures .KubeletPodResourcesGet )] = true
689
743
})
690
744
691
745
ginkgo .It ("should return the expected responses" , func (ctx context.Context ) {
@@ -701,6 +755,7 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
701
755
702
756
podresourcesListTests (ctx , f , cli , nil )
703
757
podresourcesGetAllocatableResourcesTests (ctx , cli , nil , onlineCPUs , reservedSystemCPUs )
758
+ podresourcesGetTests (ctx , f , cli )
704
759
})
705
760
})
706
761
})
@@ -742,6 +797,23 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
742
797
framework .ExpectError (err , "With feature gate disabled, the call must fail" )
743
798
})
744
799
})
800
+
801
+ ginkgo .Context ("with disabled KubeletPodResourcesGet feature gate" , func () {
802
+
803
+ ginkgo .It ("should return the expected error with the feature gate disabled" , func (ctx context.Context ) {
804
+ endpoint , err := util .LocalEndpoint (defaultPodResourcesPath , podresources .Socket )
805
+ framework .ExpectNoError (err , "LocalEndpoint() faild err %v" , err )
806
+
807
+ cli , conn , err := podresources .GetV1Client (endpoint , defaultPodResourcesTimeout , defaultPodResourcesMaxSize )
808
+ framework .ExpectNoError (err , "GetV1Client() failed err %v" , err )
809
+ defer conn .Close ()
810
+
811
+ ginkgo .By ("checking Get fail if the feature gate is not enabled" )
812
+ getRes , err := cli .Get (ctx , & kubeletpodresourcesv1.GetPodResourcesRequest {PodName : "test" , PodNamespace : f .Namespace .Name })
813
+ framework .Logf ("Get result: %v, err: %v" , getRes , err )
814
+ framework .ExpectError (err , "With feature gate disabled, the call must fail" )
815
+ })
816
+ })
745
817
})
746
818
747
819
ginkgo .Context ("with a topology-unaware device plugin, which reports resources w/o hardware topology" , func () {
@@ -824,6 +896,12 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
824
896
})
825
897
826
898
ginkgo .Context ("when querying /metrics [NodeConformance]" , func () {
899
+ tempSetCurrentKubeletConfig (f , func (ctx context.Context , initialConfig * kubeletconfig.KubeletConfiguration ) {
900
+ if initialConfig .FeatureGates == nil {
901
+ initialConfig .FeatureGates = make (map [string ]bool )
902
+ }
903
+ initialConfig .FeatureGates [string (kubefeatures .KubeletPodResourcesGet )] = true
904
+ })
827
905
ginkgo .BeforeEach (func (ctx context.Context ) {
828
906
// ensure APIs have been called at least once
829
907
endpoint , err := util .LocalEndpoint (defaultPodResourcesPath , podresources .Socket )
@@ -838,6 +916,25 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
838
916
839
917
_ , err = cli .GetAllocatableResources (ctx , & kubeletpodresourcesv1.AllocatableResourcesRequest {})
840
918
framework .ExpectNoError (err , "GetAllocatableResources() failed err %v" , err )
919
+
920
+ desc := podDesc {
921
+ podName : "pod-01" ,
922
+ cntName : "cnt-01" ,
923
+ }
924
+ tpd := newTestPodData ()
925
+ tpd .createPodsForTest (ctx , f , []podDesc {
926
+ desc ,
927
+ })
928
+ expectPodResources (ctx , 1 , cli , []podDesc {desc })
929
+
930
+ expected := []podDesc {}
931
+ resp , err := cli .Get (ctx , & kubeletpodresourcesv1.GetPodResourcesRequest {PodName : "pod-01" , PodNamespace : f .Namespace .Name })
932
+ framework .ExpectNoError (err , "Get() call failed for pod %s/%s" , f .Namespace .Name , "pod-01" )
933
+ podResourceList := []* kubeletpodresourcesv1.PodResources {resp .GetPodResources ()}
934
+ res := convertToMap (podResourceList )
935
+ err = matchPodDescWithResources (expected , res )
936
+ framework .ExpectNoError (err , "matchPodDescWithResources() failed err %v" , err )
937
+ tpd .deletePodsForTest (ctx , f )
841
938
})
842
939
843
940
ginkgo .It ("should report the values for the podresources metrics" , func (ctx context.Context ) {
@@ -855,6 +952,9 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
855
952
"kubelet_pod_resources_endpoint_requests_get_allocatable" : gstruct .MatchAllElements (nodeID , gstruct.Elements {
856
953
"" : timelessSampleAtLeast (1 ),
857
954
}),
955
+ "kubelet_pod_resources_endpoint_requests_get" : gstruct .MatchAllElements (nodeID , gstruct.Elements {
956
+ "" : timelessSampleAtLeast (1 ),
957
+ }),
858
958
// not checking errors: the calls don't have non-catastrophic (e.g. out of memory) error conditions yet.
859
959
})
860
960
0 commit comments