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

Fix k8s import/export #186

Merged
merged 2 commits into from
Jul 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions hack/e2e.test.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { AppsV1Api, CoreV1Api, KubeConfig } from "@kubernetes/client-node";
import { k8s } from "../dist/lib.js";
import test from "ava";
import { execSync, spawn } from "child_process";
import { promises as fs } from "fs";
import { resolve } from "path";

const { AppsV1Api, CoreV1Api, KubeConfig } = k8s;

const kc = new KubeConfig();
kc.loadFromDefault();

Expand Down Expand Up @@ -42,7 +44,7 @@ test.before(async t => {

test.serial("E2E: `pepr init`", t => {
try {
const peprAlias = "file:pepr-0.0.0-development.tgz"
const peprAlias = "file:pepr-0.0.0-development.tgz";
execSync(`TEST_MODE=true npx --yes ${peprAlias} init`, { stdio: "inherit" });
t.pass();
} catch (e) {
Expand Down Expand Up @@ -171,9 +173,8 @@ test.serial("E2E: `pepr deploy`", async t => {
stdio: "inherit",
});


// Check the controller logs
const logs = await getPodLogs("pepr-system", "app=pepr-static-test")
const logs = await getPodLogs("pepr-system", "app=pepr-static-test");
t.is(logs.includes("File hash matches, running module"), true);
t.is(logs.includes("Capability hello-pepr registered"), true);
t.is(logs.includes("CM with label 'change=by-label' was deleted."), true);
Expand Down Expand Up @@ -202,7 +203,7 @@ test.serial("E2E: `pepr metrics`", async t => {
try {
const cmd = await new Promise(peprDev);

const metrics = await testMetrics()
const metrics = await testMetrics();
t.is(metrics.includes("pepr_summary_count"), true);
t.is(metrics.includes("pepr_errors"), true);
t.is(metrics.includes("pepr_alerts"), true);
Expand Down Expand Up @@ -349,12 +350,18 @@ function delay2Secs() {
return new Promise(resolve => setTimeout(resolve, 2000));
}


async function getPodLogs(namespace, labelSelector) {
let allLogs = '';
let allLogs = "";

try {
const res = await k8sCoreApi.listNamespacedPod(namespace, undefined, undefined, undefined, undefined, labelSelector);
const res = await k8sCoreApi.listNamespacedPod(
namespace,
undefined,
undefined,
undefined,
undefined,
labelSelector
);
const pods = res.body.items;

for (const pod of pods) {
Expand All @@ -363,7 +370,7 @@ async function getPodLogs(namespace, labelSelector) {
allLogs += log.body;
}
} catch (err) {
console.error('Error: ', err);
console.error("Error: ", err);
}

return allLogs;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import k8s from "@kubernetes/client-node";
import * as k8s from "@kubernetes/client-node";
import { StatusCodes as fetchStatus } from "http-status-codes";
import * as utils from "ramda";
import { Capability } from "./lib/capability";
Expand Down