11import { V1OwnerReference } from '@kubernetes/client-node' ;
2+
3+ import * as kubernetesApiWrappers from './kuberenetes-api-wrappers' ;
24import { k8sApi } from './cluster' ;
35import { IKubeObjectMetadata , WorkloadKind } from './types' ;
46
@@ -8,8 +10,8 @@ type IWorkloadReaderFunc = (
810) => Promise < IKubeObjectMetadata | undefined > ;
911
1012const deploymentReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
11- const deploymentResult = await k8sApi . appsClient . readNamespacedDeployment (
12- workloadName , namespace ) ;
13+ const deploymentResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
14+ ( ) => k8sApi . appsClient . readNamespacedDeployment ( workloadName , namespace ) ) ;
1315 const deployment = deploymentResult . body ;
1416
1517 if ( ! deployment . metadata || ! deployment . spec || ! deployment . spec . template . metadata ||
@@ -29,8 +31,8 @@ const deploymentReader: IWorkloadReaderFunc = async (workloadName, namespace) =>
2931} ;
3032
3133const replicaSetReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
32- const replicaSetResult = await k8sApi . appsClient . readNamespacedReplicaSet (
33- workloadName , namespace ) ;
34+ const replicaSetResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
35+ ( ) => k8sApi . appsClient . readNamespacedReplicaSet ( workloadName , namespace ) ) ;
3436 const replicaSet = replicaSetResult . body ;
3537
3638 if ( ! replicaSet . metadata || ! replicaSet . spec || ! replicaSet . spec . template ||
@@ -50,8 +52,8 @@ const replicaSetReader: IWorkloadReaderFunc = async (workloadName, namespace) =>
5052} ;
5153
5254const statefulSetReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
53- const statefulSetResult = await k8sApi . appsClient . readNamespacedStatefulSet (
54- workloadName , namespace ) ;
55+ const statefulSetResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
56+ ( ) => k8sApi . appsClient . readNamespacedStatefulSet ( workloadName , namespace ) ) ;
5557 const statefulSet = statefulSetResult . body ;
5658
5759 if ( ! statefulSet . metadata || ! statefulSet . spec || ! statefulSet . spec . template . metadata ||
@@ -71,8 +73,8 @@ const statefulSetReader: IWorkloadReaderFunc = async (workloadName, namespace) =
7173} ;
7274
7375const daemonSetReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
74- const daemonSetResult = await k8sApi . appsClient . readNamespacedDaemonSet (
75- workloadName , namespace ) ;
76+ const daemonSetResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
77+ ( ) => k8sApi . appsClient . readNamespacedDaemonSet ( workloadName , namespace ) ) ;
7678 const daemonSet = daemonSetResult . body ;
7779
7880 if ( ! daemonSet . metadata || ! daemonSet . spec || ! daemonSet . spec . template . spec ||
@@ -92,8 +94,8 @@ const daemonSetReader: IWorkloadReaderFunc = async (workloadName, namespace) =>
9294} ;
9395
9496const jobReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
95- const jobResult = await k8sApi . batchClient . readNamespacedJob (
96- workloadName , namespace ) ;
97+ const jobResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
98+ ( ) => k8sApi . batchClient . readNamespacedJob ( workloadName , namespace ) ) ;
9799 const job = jobResult . body ;
98100
99101 if ( ! job . metadata || ! job . spec || ! job . spec . template . spec || ! job . spec . template . metadata ) {
@@ -114,8 +116,8 @@ const jobReader: IWorkloadReaderFunc = async (workloadName, namespace) => {
114116// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-versioning
115117// CronJobs will appear in v2 API, but for now there' only v2alpha1, so it's a bad idea to use it.
116118const cronJobReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
117- const cronJobResult = await k8sApi . batchUnstableClient . readNamespacedCronJob (
118- workloadName , namespace ) ;
119+ const cronJobResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
120+ ( ) => k8sApi . batchUnstableClient . readNamespacedCronJob ( workloadName , namespace ) ) ;
119121 const cronJob = cronJobResult . body ;
120122
121123 if ( ! cronJob . metadata || ! cronJob . spec || ! cronJob . spec . jobTemplate . metadata ||
@@ -134,8 +136,8 @@ const cronJobReader: IWorkloadReaderFunc = async (workloadName, namespace) => {
134136} ;
135137
136138const replicationControllerReader : IWorkloadReaderFunc = async ( workloadName , namespace ) => {
137- const replicationControllerResult = await k8sApi . coreClient . readNamespacedReplicationController (
138- workloadName , namespace ) ;
139+ const replicationControllerResult = await kubernetesApiWrappers . retryKubernetesApiRequest (
140+ ( ) => k8sApi . coreClient . readNamespacedReplicationController ( workloadName , namespace ) ) ;
139141 const replicationController = replicationControllerResult . body ;
140142
141143 if ( ! replicationController . metadata || ! replicationController . spec || ! replicationController . spec . template ||
0 commit comments