4141import java .util .Arrays ;
4242import java .util .List ;
4343import java .util .Map ;
44+ import java .util .Optional ;
4445import java .util .concurrent .CancellationException ;
4546import java .util .concurrent .CountDownLatch ;
4647import java .util .concurrent .Future ;
7980public class GenericKubernetesApi <
8081 ApiType extends KubernetesObject , ApiListType extends KubernetesListObject > {
8182
83+ private static final String PARTIAL_OBJECT_METADATA_HEADER =
84+ "application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json" ;
85+
86+ private static final String PARTIAL_OBJECT_METADATA_LIST_HEADER =
87+ "application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json" ;
88+
8289 // TODO(yue9944882): supports status operations..
8390 // TODO(yue9944882): supports generic sub-resource operations..
8491 // TODO(yue9944882): supports delete-collections..
@@ -453,8 +460,23 @@ public KubernetesApiResponse<ApiType> get(String name, final GetOptions getOptio
453460
454461 private CallBuilder makeClusterGetCallBuilder (String name , final GetOptions getOptions ) {
455462 return () ->
456- customObjectsApi .getClusterCustomObjectCall (
457- this .apiGroup , this .apiVersion , this .resourcePlural , name , null );
463+ adaptGetCall (
464+ customObjectsApi .getApiClient (),
465+ customObjectsApi .getClusterCustomObjectCall (
466+ this .apiGroup , this .apiVersion , this .resourcePlural , name , null ),
467+ getOptions );
468+ }
469+
470+ private Call adaptGetCall (ApiClient apiClient , Call call , GetOptions getOptions ) {
471+ if (Optional .ofNullable (getOptions )
472+ .map (GetOptions ::isPartialObjectMetadataRequest )
473+ .orElse (Boolean .FALSE )) {
474+ Request request = call .request ();
475+ return apiClient
476+ .getHttpClient ()
477+ .newCall (request .newBuilder ().header ("Accept" , PARTIAL_OBJECT_METADATA_HEADER ).build ());
478+ }
479+ return call ;
458480 }
459481
460482 /**
@@ -504,8 +526,11 @@ public KubernetesApiResponse<ApiType> get(
504526 private CallBuilder makeNamespacedGetCallBuilder (
505527 String namespace , String name , final GetOptions getOptions ) {
506528 return () ->
507- customObjectsApi .getNamespacedCustomObjectCall (
508- this .apiGroup , this .apiVersion , namespace , this .resourcePlural , name , null );
529+ adaptGetCall (
530+ customObjectsApi .getApiClient (),
531+ customObjectsApi .getNamespacedCustomObjectCall (
532+ this .apiGroup , this .apiVersion , namespace , this .resourcePlural , name , null ),
533+ getOptions );
509534 }
510535
511536 /**
@@ -548,21 +573,37 @@ public KubernetesApiResponse<ApiListType> list(final ListOptions listOptions) {
548573
549574 private CallBuilder makeClusterListCallBuilder (final ListOptions listOptions ) {
550575 return () ->
551- customObjectsApi .listClusterCustomObjectCall (
552- this .apiGroup ,
553- this .apiVersion ,
554- this .resourcePlural ,
555- null ,
556- false ,
557- listOptions .getContinue (),
558- listOptions .getFieldSelector (),
559- listOptions .getLabelSelector (),
560- listOptions .getLimit (),
561- listOptions .getResourceVersion (),
562- null ,
563- listOptions .getTimeoutSeconds (),
564- false ,
565- null );
576+ adaptListCall (
577+ customObjectsApi .getApiClient (),
578+ customObjectsApi .listClusterCustomObjectCall (
579+ this .apiGroup ,
580+ this .apiVersion ,
581+ this .resourcePlural ,
582+ null ,
583+ false ,
584+ listOptions .getContinue (),
585+ listOptions .getFieldSelector (),
586+ listOptions .getLabelSelector (),
587+ listOptions .getLimit (),
588+ listOptions .getResourceVersion (),
589+ null ,
590+ listOptions .getTimeoutSeconds (),
591+ false ,
592+ null ),
593+ listOptions );
594+ }
595+
596+ private Call adaptListCall (ApiClient apiClient , Call call , ListOptions listOptions ) {
597+ if (Optional .ofNullable (listOptions )
598+ .map (ListOptions ::isPartialObjectMetadataListRequest )
599+ .orElse (Boolean .FALSE )) {
600+ Request request = call .request ();
601+ return apiClient
602+ .getHttpClient ()
603+ .newCall (
604+ request .newBuilder ().header ("Accept" , PARTIAL_OBJECT_METADATA_LIST_HEADER ).build ());
605+ }
606+ return call ;
566607 }
567608
568609 /**
@@ -585,22 +626,25 @@ public KubernetesApiResponse<ApiListType> list(String namespace, final ListOptio
585626 private CallBuilder makeNamespacedListCallBuilder (
586627 String namespace , final ListOptions listOptions ) {
587628 return () ->
588- customObjectsApi .listNamespacedCustomObjectCall (
589- this .apiGroup ,
590- this .apiVersion ,
591- namespace ,
592- this .resourcePlural ,
593- null ,
594- null ,
595- listOptions .getContinue (),
596- listOptions .getFieldSelector (),
597- listOptions .getLabelSelector (),
598- listOptions .getLimit (),
599- listOptions .getResourceVersion (),
600- null ,
601- listOptions .getTimeoutSeconds (),
602- false ,
603- null );
629+ adaptListCall (
630+ customObjectsApi .getApiClient (),
631+ customObjectsApi .listNamespacedCustomObjectCall (
632+ this .apiGroup ,
633+ this .apiVersion ,
634+ namespace ,
635+ this .resourcePlural ,
636+ null ,
637+ null ,
638+ listOptions .getContinue (),
639+ listOptions .getFieldSelector (),
640+ listOptions .getLabelSelector (),
641+ listOptions .getLimit (),
642+ listOptions .getResourceVersion (),
643+ null ,
644+ listOptions .getTimeoutSeconds (),
645+ false ,
646+ null ),
647+ listOptions );
604648 }
605649
606650 /**
0 commit comments