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

chore: Support running smoke tests against non-minikube clusters #7812

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion open-lens/integration/__tests__/cluster-pages.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
({ window, cleanup } = await utils.start());
await utils.clickWelcomeButton(window);

frame = await utils.launchMinikubeClusterFromCatalog(window);
frame = await utils.launchClusterFromCatalog(window);
}, 10 * 60 * 1000);

afterEach(async () => {
Expand Down
28 changes: 28 additions & 0 deletions open-lens/integration/helpers/minikube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,36 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { spawnSync } from "child_process";
import { clusterName, kubeConfigPath } from "./utils";

export function minikubeReady(testNamespace: string): boolean {
if (clusterName !== "minikube") {
console.log("Not running against minikube");

{
const { status } = spawnSync(`kubectl --kubeconfig "${kubeConfigPath}" get namespace ${testNamespace}`, { shell: true });

if (status === 0) {
console.warn(`Removing existing ${testNamespace} namespace`);

const { status, stdout, stderr } = spawnSync(
`kubectl --kubeconfig "${kubeConfigPath}" delete namespace ${testNamespace}`,
{ shell: true },
);

if (status !== 0) {
console.warn(`Error removing ${testNamespace} namespace: ${stderr.toString()}`);

return false;
}

console.log(stdout.toString());
}
}

return true;
}

// determine if minikube is running
{
const { status } = spawnSync("minikube status", { shell: true });
Expand Down
28 changes: 21 additions & 7 deletions open-lens/integration/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { createHash } from "crypto";
import { mkdirp, remove } from "fs-extra";
import { mkdirp, remove, writeJson } from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as uuid from "uuid";
Expand Down Expand Up @@ -56,13 +56,27 @@ async function getMainWindow(app: ElectronApplication, timeout = 50_000): Promis
});
}

export const kubeConfigPath = process.env.LENS_INTEGRATION_TEST_KUBECONFIG || path.join(os.homedir(), ".kube", "config");
export const clusterName = process.env.LENS_INTEGRATION_TEST_CLUSTER_NAME || "minikube";

async function attemptStart() {
const CICD = path.join(os.tmpdir(), "lens-integration-testing", uuid.v4());

// Make sure that the directory is clear
await remove(CICD).catch(noop);
await mkdirp(CICD);

if (process.env.LENS_INTEGRATION_TEST_KUBECONFIG) {
await mkdirp(path.join(CICD, "OpenLens"));
await writeJson(path.join(CICD, "OpenLens", "lens-user-store.json"), {
preferences: {
syncKubeconfigEntries: [{
filePath: kubeConfigPath,
}]
}
});
}

const app = await electron.launch({
args: ["--integration-testing"], // this argument turns off the blocking of quit
executablePath: appPaths[process.platform],
Expand Down Expand Up @@ -109,22 +123,22 @@ export async function clickWelcomeButton(window: Page) {
await window.click("[data-testid=welcome-menu-container] li a");
}

function minikubeEntityId() {
return createHash("md5").update(`${path.join(os.homedir(), ".kube", "config")}:minikube`).digest("hex");
function entityId() {
return createHash("md5").update(`${kubeConfigPath}:${clusterName}`).digest("hex");
}

/**
* From the catalog, click the minikube entity and wait for it to connect, returning its frame
*/
export async function launchMinikubeClusterFromCatalog(window: Page): Promise<Frame> {
await window.click("div.TableCell >> text='minikube'");
export async function launchClusterFromCatalog(window: Page): Promise<Frame> {
await window.click(`div.TableCell >> text='${clusterName}'`);

const minikubeFrame = await window.waitForSelector(`#cluster-frame-${minikubeEntityId()}`);
const minikubeFrame = await window.waitForSelector(`#cluster-frame-${entityId()}`);

const frame = await minikubeFrame.contentFrame();

if (!frame) {
throw new Error("No iframe for minikube found");
throw new Error(`No iframe for "${clusterName}" found`);
}

await frame.waitForSelector("[data-testid=cluster-sidebar]");
Expand Down