Skip to content

Commit 113c96e

Browse files
committed
fix: upgrade kubernetes-client to 1.0.0
1 parent df5b42e commit 113c96e

18 files changed

+358
-473
lines changed

src/supervisor/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ async function getSnykMonitorDeploymentUid(
2121
): Promise<string | undefined> {
2222
try {
2323
const attemptedApiCall = await retryKubernetesApiRequestIndefinitely(
24-
() => k8sApi.appsClient.readNamespacedDeployment(name, namespace),
24+
() => k8sApi.appsClient.readNamespacedDeployment({ name, namespace }),
2525
config.MAX_RETRY_BACKOFF_DURATION_SECONDS,
2626
);
27-
return attemptedApiCall.body.metadata?.uid;
27+
return attemptedApiCall.metadata?.uid;
2828
} catch (error) {
2929
logger.error(
3030
{ error, namespace, deploymentName: name },

src/supervisor/watchers/handlers/argo-rollout.ts

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { IncomingMessage } from 'http';
21
import { deleteWorkload } from './workload';
32
import { WorkloadKind } from '../../types';
43
import {
@@ -20,10 +19,7 @@ import { trimWorkload } from '../../workload-sanitization';
2019

2120
export async function paginatedNamespacedArgoRolloutList(
2221
namespace: string,
23-
): Promise<{
24-
response: IncomingMessage;
25-
body: V1alpha1RolloutList;
26-
}> {
22+
): Promise<V1alpha1RolloutList> {
2723
const rolloutList = new V1alpha1RolloutList();
2824
rolloutList.apiVersion = 'argoproj.io/v1alpha1';
2925
rolloutList.kind = 'RolloutList';
@@ -32,26 +28,26 @@ export async function paginatedNamespacedArgoRolloutList(
3228
return await paginatedNamespacedList(
3329
namespace,
3430
rolloutList,
35-
async (
36-
namespace: string,
37-
pretty?: string,
38-
_allowWatchBookmarks?: boolean,
39-
_continue?: string,
40-
fieldSelector?: string,
41-
labelSelector?: string,
42-
limit?: number,
43-
) =>
44-
k8sApi.customObjectsClient.listNamespacedCustomObject(
45-
'argoproj.io',
46-
'v1alpha1',
47-
namespace,
48-
'rollouts',
49-
pretty,
50-
false,
51-
_continue,
52-
fieldSelector,
53-
labelSelector,
54-
limit,
31+
async (batchRequest: {
32+
namespace: string;
33+
pretty?: string;
34+
_allowWatchBookmarks?: boolean;
35+
_continue?: string;
36+
fieldSelector?: string;
37+
labelSelector?: string;
38+
limit?: number;
39+
}) =>
40+
k8sApi.customObjectsClient.listNamespacedCustomObject({
41+
group: 'argoproj.io',
42+
version: 'v1alpha1',
43+
namespace: namespace,
44+
plural: 'rollouts',
45+
pretty: batchRequest.pretty,
46+
allowWatchBookmarks: false,
47+
_continue: batchRequest._continue,
48+
fieldSelector: batchRequest.fieldSelector,
49+
labelSelector: batchRequest.labelSelector,
50+
limit: batchRequest.limit,
5551
/**
5652
* The K8s client's listNamespacedCustomObject() doesn't allow to specify
5753
* the type of the response body and returns the generic "object" type,
@@ -61,40 +57,37 @@ export async function paginatedNamespacedArgoRolloutList(
6157
* Type 'Promise<{ response: IncomingMessage; ***body: object;*** }>' is not assignable to type
6258
* 'Promise<{ response: IncomingMessage; ***body: KubernetesListObject<...>;*** }>'
6359
*/
64-
) as any,
60+
}) as any,
6561
);
6662
}
6763

68-
export async function paginatedClusterArgoRolloutList(): Promise<{
69-
response: IncomingMessage;
70-
body: V1alpha1RolloutList;
71-
}> {
64+
export async function paginatedClusterArgoRolloutList(): Promise<V1alpha1RolloutList> {
7265
const rolloutList = new V1alpha1RolloutList();
7366
rolloutList.apiVersion = 'argoproj.io/v1';
7467
rolloutList.kind = 'RolloutList';
7568
rolloutList.items = new Array<V1alpha1Rollout>();
7669

7770
return await paginatedClusterList(
7871
rolloutList,
79-
async (
80-
_allowWatchBookmarks?: boolean,
81-
_continue?: string,
82-
fieldSelector?: string,
83-
labelSelector?: string,
84-
limit?: number,
85-
pretty?: string,
86-
) =>
87-
k8sApi.customObjectsClient.listClusterCustomObject(
88-
'argoproj.io',
89-
'v1alpha1',
90-
'rollouts',
91-
pretty,
92-
false,
93-
_continue,
94-
fieldSelector,
95-
labelSelector,
96-
limit,
97-
) as any,
72+
async (clusterRequest: {
73+
_allowWatchBookmarks?: boolean;
74+
_continue?: string;
75+
fieldSelector?: string;
76+
labelSelector?: string;
77+
limit?: number;
78+
pretty?: string;
79+
}) =>
80+
k8sApi.customObjectsClient.listClusterCustomObject({
81+
group: 'argoproj.io',
82+
version: 'v1alpha1',
83+
plural: 'rollouts',
84+
pretty: clusterRequest.pretty,
85+
allowWatchBookmarks: false,
86+
_continue: clusterRequest._continue,
87+
fieldSelector: clusterRequest.fieldSelector,
88+
labelSelector: clusterRequest.labelSelector,
89+
limit: clusterRequest.limit,
90+
}) as any,
9891
);
9992
}
10093

@@ -109,23 +102,32 @@ export async function argoRolloutWatchHandler(
109102
// Perform lookup for known supported kinds: https://github.com/argoproj/argo-rollouts/blob/master/rollout/templateref.go#L40-L52
110103
case 'Deployment': {
111104
const deployResult = await retryKubernetesApiRequest(() =>
112-
k8sApi.appsClient.readNamespacedDeployment(workloadName, namespace),
105+
k8sApi.appsClient.readNamespacedDeployment({
106+
name: workloadName,
107+
namespace,
108+
}),
113109
);
114-
rollout.spec.template = deployResult.body.spec?.template;
110+
rollout.spec.template = deployResult.spec?.template;
115111
break;
116112
}
117113
case 'ReplicaSet': {
118114
const replicaSetResult = await retryKubernetesApiRequest(() =>
119-
k8sApi.appsClient.readNamespacedReplicaSet(workloadName, namespace),
115+
k8sApi.appsClient.readNamespacedReplicaSet({
116+
name: workloadName,
117+
namespace,
118+
}),
120119
);
121-
rollout.spec.template = replicaSetResult.body.spec?.template;
120+
rollout.spec.template = replicaSetResult.spec?.template;
122121
break;
123122
}
124123
case 'PodTemplate': {
125124
const podTemplateResult = await retryKubernetesApiRequest(() =>
126-
k8sApi.coreClient.readNamespacedPodTemplate(workloadName, namespace),
125+
k8sApi.coreClient.readNamespacedPodTemplate({
126+
name: workloadName,
127+
namespace,
128+
}),
127129
);
128-
rollout.spec.template = podTemplateResult.body.template;
130+
rollout.spec.template = podTemplateResult.template;
129131
break;
130132
}
131133
default:
@@ -186,21 +188,20 @@ export async function isNamespacedArgoRolloutSupported(
186188
const resourceVersion = undefined; // List anything in the cluster
187189
const timeoutSeconds = 10; // Don't block the snyk-monitor indefinitely
188190
const attemptedApiCall = await retryKubernetesApiRequest(() =>
189-
k8sApi.customObjectsClient.listNamespacedCustomObject(
190-
'argoproj.io',
191-
'v1alpha1',
192-
namespace,
193-
'rollouts',
194-
pretty,
195-
false,
196-
continueToken,
197-
fieldSelector,
198-
labelSelector,
199-
limit,
200-
resourceVersion,
201-
undefined,
202-
timeoutSeconds,
203-
),
191+
k8sApi.customObjectsClient.listNamespacedCustomObject({
192+
group: 'argoproj.io',
193+
version: 'v1alpha1',
194+
namespace: namespace,
195+
plural: 'rollouts',
196+
pretty: pretty,
197+
allowWatchBookmarks: false,
198+
_continue: continueToken,
199+
fieldSelector: fieldSelector,
200+
labelSelector: labelSelector,
201+
limit: limit,
202+
resourceVersion: resourceVersion,
203+
timeoutSeconds: timeoutSeconds,
204+
}),
204205
);
205206
return (
206207
attemptedApiCall !== undefined &&
@@ -228,20 +229,19 @@ export async function isClusterArgoRolloutSupported(): Promise<boolean> {
228229
const resourceVersion = undefined; // List anything in the cluster
229230
const timeoutSeconds = 10; // Don't block the snyk-monitor indefinitely
230231
const attemptedApiCall = await retryKubernetesApiRequest(() =>
231-
k8sApi.customObjectsClient.listClusterCustomObject(
232-
'argoproj.io',
233-
'v1alpha1',
234-
'rollouts',
235-
pretty,
236-
false,
237-
continueToken,
238-
fieldSelector,
239-
labelSelector,
240-
limit,
241-
resourceVersion,
242-
undefined,
243-
timeoutSeconds,
244-
),
232+
k8sApi.customObjectsClient.listClusterCustomObject({
233+
group: 'argoproj.io',
234+
version: 'v1alpha1',
235+
plural: 'rollouts',
236+
pretty: pretty,
237+
allowWatchBookmarks: false,
238+
_continue: continueToken,
239+
fieldSelector: fieldSelector,
240+
labelSelector: labelSelector,
241+
limit: limit,
242+
resourceVersion: resourceVersion,
243+
timeoutSeconds: timeoutSeconds,
244+
}),
245245
);
246246
return (
247247
attemptedApiCall !== undefined &&

src/supervisor/watchers/handlers/cron-job.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { V1CronJob, V1CronJobList } from '@kubernetes/client-node';
22
import { deleteWorkload } from './workload';
33
import { WorkloadKind } from '../../types';
44
import { FALSY_WORKLOAD_NAME_MARKER } from './types';
5-
import { IncomingMessage } from 'http';
65
import { k8sApi } from '../../cluster';
76
import { paginatedClusterList, paginatedNamespacedList } from './pagination';
87
import {
@@ -15,10 +14,7 @@ import { deleteWorkloadFromScanQueue } from './queue';
1514

1615
export async function paginatedNamespacedCronJobList(
1716
namespace: string,
18-
): Promise<{
19-
response: IncomingMessage;
20-
body: V1CronJobList;
21-
}> {
17+
): Promise<V1CronJobList> {
2218
const v1CronJobList = new V1CronJobList();
2319
v1CronJobList.apiVersion = 'batch/v1';
2420
v1CronJobList.kind = 'CronJobList';
@@ -31,10 +27,7 @@ export async function paginatedNamespacedCronJobList(
3127
);
3228
}
3329

34-
export async function paginatedClusterCronJobList(): Promise<{
35-
response: IncomingMessage;
36-
body: V1CronJobList;
37-
}> {
30+
export async function paginatedClusterCronJobList(): Promise<V1CronJobList> {
3831
const v1CronJobList = new V1CronJobList();
3932
v1CronJobList.apiVersion = 'batch/v1';
4033
v1CronJobList.kind = 'CronJobList';

src/supervisor/watchers/handlers/daemon-set.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { V1DaemonSet, V1DaemonSetList } from '@kubernetes/client-node';
22
import { deleteWorkload } from './workload';
33
import { WorkloadKind } from '../../types';
44
import { FALSY_WORKLOAD_NAME_MARKER } from './types';
5-
import { IncomingMessage } from 'http';
65
import { k8sApi } from '../../cluster';
76
import { paginatedClusterList, paginatedNamespacedList } from './pagination';
87
import {
@@ -15,10 +14,7 @@ import { deleteWorkloadFromScanQueue } from './queue';
1514

1615
export async function paginatedNamespacedDaemonSetList(
1716
namespace: string,
18-
): Promise<{
19-
response: IncomingMessage;
20-
body: V1DaemonSetList;
21-
}> {
17+
): Promise<V1DaemonSetList> {
2218
const v1DaemonSetList = new V1DaemonSetList();
2319
v1DaemonSetList.apiVersion = 'apps/v1';
2420
v1DaemonSetList.kind = 'DaemonSetList';
@@ -31,10 +27,7 @@ export async function paginatedNamespacedDaemonSetList(
3127
);
3228
}
3329

34-
export async function paginatedClusterDaemonSetList(): Promise<{
35-
response: IncomingMessage;
36-
body: V1DaemonSetList;
37-
}> {
30+
export async function paginatedClusterDaemonSetList(): Promise<V1DaemonSetList> {
3831
const v1DaemonSetList = new V1DaemonSetList();
3932
v1DaemonSetList.apiVersion = 'apps/v1';
4033
v1DaemonSetList.kind = 'DaemonSetList';

0 commit comments

Comments
 (0)