Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kubernetes client #388

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/kubernetes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@walmartlabs/cookie-cutter-kubernetes",
"version": "1.6.0-beta.0",
"version": "1.6.0-beta.1",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -13,7 +13,7 @@
"url": "https://github.com/walmartlabs/cookie-cutter/issues"
},
"dependencies": {
"@kubernetes/client-node": "0.15.1",
"@kubernetes/client-node": "0.16.3",
"body-parser": "1.20.0",
"express": "4.18.1",
"express-async-handler": "1.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
MessageRef,
} from "@walmartlabs/cookie-cutter-core";
import * as bodyParser from "body-parser";
import * as express from "express";
import * as asyncHandler from "express-async-handler";
import express from "express";
import asyncHandler from "express-async-handler";
import { RequestHandler } from "express-serve-static-core";
import * as jsonpatch from "fast-json-patch";
import * as https from "https";
Expand Down
10 changes: 5 additions & 5 deletions packages/kubernetes/src/KubernetesPollSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This source code is licensed under the Apache 2.0 license found in the
LICENSE file in the root directory of this source tree.
*/

import * as k8s from "@kubernetes/client-node";
import { ApiextensionsV1Api, KubeConfig } from "@kubernetes/client-node";
import {
IComponentContext,
IInputSource,
Expand All @@ -17,7 +17,7 @@ import {
timeout,
} from "@walmartlabs/cookie-cutter-core";
import * as _ from "lodash";
import * as request from "request";
import request from "request";
import { IK8sQueryProvider, IK8sWatchConfiguration, IWatchQueryParams } from ".";
import { KubernetesBase } from "./KubernetesBaseSource";

Expand Down Expand Up @@ -62,7 +62,7 @@ export class KubernetesPollSource
public async *start(): AsyncIterableIterator<MessageRef> {
this.running = true;

const kubeConfig = new k8s.KubeConfig();
const kubeConfig = new KubeConfig();
if (this.config.configFilePath) {
kubeConfig.loadFromFile(this.config.configFilePath);
} else {
Expand All @@ -74,7 +74,7 @@ export class KubernetesPollSource
this.currentContext = kubeConfig.getCurrentContext();

if (this.queryProvider) {
const client = kubeConfig.makeApiClient(k8s.ApiextensionsV1beta1Api);
const client = kubeConfig.makeApiClient(ApiextensionsV1Api);
const config = await this.queryProvider.getQueryConfig(client);
if (config.queryPath) {
this.queryPath = config.queryPath;
Expand Down Expand Up @@ -175,7 +175,7 @@ export class KubernetesPollSource
}
}

public poll(kubeConfig: k8s.KubeConfig, path: string, queryParams: any): Promise<any> {
public poll(kubeConfig: KubeConfig, path: string, queryParams: any): Promise<any> {
return new Promise<any>((resolve, reject) => {
const cluster = kubeConfig.getCurrentCluster();
if (!cluster) {
Expand Down
10 changes: 5 additions & 5 deletions packages/kubernetes/src/KubernetesWatchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This source code is licensed under the Apache 2.0 license found in the
LICENSE file in the root directory of this source tree.
*/

import k8s = require("@kubernetes/client-node");
import { KubeConfig, ApiextensionsV1Api, Watch } from "@kubernetes/client-node";
import {
BoundedPriorityQueue,
IComponentContext,
Expand Down Expand Up @@ -57,7 +57,7 @@ export class KubernetesWatchSource
}

public async *start(): AsyncIterableIterator<MessageRef> {
const kubeConfig = new k8s.KubeConfig();
const kubeConfig = new KubeConfig();
if (this.config.configFilePath) {
kubeConfig.loadFromFile(this.config.configFilePath);
} else {
Expand All @@ -69,7 +69,7 @@ export class KubernetesWatchSource
this.currentContext = kubeConfig.getCurrentContext();

if (this.queryProvider) {
const client = kubeConfig.makeApiClient(k8s.ApiextensionsV1beta1Api);
const client = kubeConfig.makeApiClient(ApiextensionsV1Api);
const config = await this.queryProvider.getQueryConfig(client);
if (config.queryPath) {
this.queryPath = config.queryPath;
Expand All @@ -88,7 +88,7 @@ export class KubernetesWatchSource
await this.abort();
}

private startWatch(kubeConfig: k8s.KubeConfig) {
private startWatch(kubeConfig: KubeConfig) {
if (this.done) {
return;
}
Expand All @@ -101,7 +101,7 @@ export class KubernetesWatchSource

const RESTART_MSG = `watch didn't receive any items for ${this.reconnectTimeout}ms`;

const watch = new k8s.Watch(kubeConfig);
const watch = new Watch(kubeConfig);
const watchPromise = new Promise<string>((resolve, reject) => {
let pendingEnqueue: Promise<boolean>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ This source code is licensed under the Apache 2.0 license found in the
LICENSE file in the root directory of this source tree.
*/

import k8s = require("@kubernetes/client-node");
import {
V1Deployment,
V1DeploymentStatus,
V1DeploymentStrategy,
V1LabelSelector,
V1ObjectMeta,
V1PodTemplateSpec,
} from "@kubernetes/client-node";
import {
Application,
CancelablePromise,
Expand All @@ -15,7 +22,7 @@ import {
} from "@walmartlabs/cookie-cutter-core";
import * as fs from "fs";
import * as path from "path";
import * as rp from "request-promise-native";
import rp from "request-promise-native";
import {
IK8sAdmissionReviewResponse,
k8sAdmissionControllerSource,
Expand Down Expand Up @@ -46,21 +53,21 @@ function testApp(handler: any, emptyCreds?: boolean): CancelablePromise<void> {
}

describe("KubernetesAdmissionControllerSource", () => {
const testResource: k8s.V1Deployment = {
const testResource: V1Deployment = {
apiVersion: "deployment/v1",
kind: "Deployment",
metadata: new k8s.V1ObjectMeta(),
metadata: new V1ObjectMeta(),
spec: {
minReadySeconds: 0,
paused: false,
progressDeadlineSeconds: 0,
replicas: 1,
revisionHistoryLimit: 0,
selector: new k8s.V1LabelSelector(),
strategy: new k8s.V1DeploymentStrategy(),
template: new k8s.V1PodTemplateSpec(),
selector: new V1LabelSelector(),
strategy: new V1DeploymentStrategy(),
template: new V1PodTemplateSpec(),
},
status: new k8s.V1DeploymentStatus(),
status: new V1DeploymentStatus(),
};
const testUid = "testUID";
const testRequestBody = {
Expand Down Expand Up @@ -134,8 +141,8 @@ describe("KubernetesAdmissionControllerSource", () => {
msg: K8sAdmissionReviewRequest,
__: IDispatchContext
): Promise<IK8sAdmissionReviewResponse> => {
const mutation: k8s.V1Deployment = msg.request.object;
mutation.metadata = new k8s.V1ObjectMeta();
const mutation: V1Deployment = msg.request.object;
mutation.metadata = new V1ObjectMeta();
mutation.metadata.annotations = { new_annotation: "new" };
mutation.spec.replicas = 2;
delete mutation.spec.revisionHistoryLimit;
Expand Down
4 changes: 2 additions & 2 deletions packages/kubernetes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This source code is licensed under the Apache 2.0 license found in the
LICENSE file in the root directory of this source tree.
*/

import * as k8s from "@kubernetes/client-node";
import { ApiextensionsV1Api } from "@kubernetes/client-node";
import { config, IInputSource } from "@walmartlabs/cookie-cutter-core";
import { KubernetesAdmissionControllerSource } from "./KubernetesAdmissionControllerSource";
import { K8sResourceAdded, K8sResourceDeleted, K8sResourceModified } from "./KubernetesBaseSource";
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface IK8sWatchConfiguration {

export interface IK8sQueryProvider {
readonly getQueryConfig: (
client: k8s.ApiextensionsV1beta1Api
client: ApiextensionsV1Api
) => Promise<{ readonly queryPath: string; readonly queryParams?: IWatchQueryParams }>;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/kubernetes/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
"rootDir": "./src",
"esModuleInterop": true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
"exclude": ["node_modules", "dist"],
"include": ["src/**/*.ts"]
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@kubernetes/client-node@0.15.1":
version "0.15.1"
resolved "https://registry.yarnpkg.com/@kubernetes/client-node/-/client-node-0.15.1.tgz#617357873d20de348a99227f3b699c2adb765152"
integrity sha512-j3o5K4TWkdrX2yDndbEZcDxhgea6O2JKnesWoYCJ64WtMn2GbQXGBOnkn2i0WT2MugGbLR+qCm8Y3oHWBApaTA==
"@kubernetes/client-node@0.16.3":
version "0.16.3"
resolved "https://registry.yarnpkg.com/@kubernetes/client-node/-/client-node-0.16.3.tgz#a26a5abbd6e45603b4f75f0baff00e19853e5be7"
integrity sha512-L7IckuyuPfhd+/Urib8MRas9D6sfKEq8IaITYcaE6LlU+Y8MeD7MTbuW6Yb2WdeRuFN8HPSS47mxPnOUNYBXEg==
dependencies:
"@types/js-yaml" "^4.0.1"
"@types/node" "^10.12.0"
Expand All @@ -1651,9 +1651,9 @@
openid-client "^4.1.1"
request "^2.88.0"
rfc4648 "^1.3.0"
shelljs "^0.8.4"
shelljs "^0.8.5"
stream-buffers "^3.0.2"
tar "^6.0.2"
tar "^6.1.11"
tmp-promise "^3.0.2"
tslib "^1.9.3"
underscore "^1.9.1"
Expand Down Expand Up @@ -10107,7 +10107,7 @@ shell-quote@1.7.2:
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==

shelljs@^0.8.4:
shelljs@^0.8.4, shelljs@^0.8.5:
version "0.8.5"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
Expand Down Expand Up @@ -10641,7 +10641,7 @@ tar-stream@^1.5.2:
to-buffer "^1.1.1"
xtend "^4.0.0"

tar@^6.0.2, tar@^6.1.11:
tar@^6.1.11:
version "6.1.11"
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621"
integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==
Expand Down