Run build with input commands
parent
821b9eeddf
commit
fce88635b8
|
|
@ -1005,27 +1005,26 @@ class Kubernetes {
|
|||
}
|
||||
});
|
||||
}
|
||||
static watchPodUntilReadyAndRead(statusFilter) {
|
||||
var _a, _b, _c;
|
||||
static watchPodUntilRunningAndRead() {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let ready = false;
|
||||
while (!ready) {
|
||||
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const pods = yield this.kubeClient.listNamespacedPod(this.namespace);
|
||||
for (let index = 0; index < pods.body.items.length; index++) {
|
||||
const element = pods.body.items[index];
|
||||
const jobname = (_b = (_a = element.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['job-name'];
|
||||
const phase = (_c = element.status) === null || _c === void 0 ? void 0 : _c.phase;
|
||||
if (jobname === this.jobName && phase !== statusFilter) {
|
||||
core.info('Pod no longer pending');
|
||||
if (phase === 'Failure') {
|
||||
core.error('Kubernetes job failed');
|
||||
}
|
||||
else {
|
||||
ready = true;
|
||||
return element;
|
||||
}
|
||||
}
|
||||
const pod = (_a = (yield this.kubeClient.readNamespacedPod(this.name, this.namespace))) === null || _a === void 0 ? void 0 : _a.body;
|
||||
if (pod === undefined) {
|
||||
throw new Error('no pod found');
|
||||
}
|
||||
const phase = (_b = pod.status) === null || _b === void 0 ? void 0 : _b.phase;
|
||||
if (phase === 'Running') {
|
||||
core.info('Pod no longer pending');
|
||||
}
|
||||
if (phase !== 'Pending') {
|
||||
core.error('Kubernetes job failed');
|
||||
}
|
||||
else {
|
||||
ready = true;
|
||||
return pod;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1034,9 +1033,9 @@ class Kubernetes {
|
|||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
|
||||
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`);
|
||||
yield Kubernetes.streamLogs(((_b = pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace);
|
||||
const pod = yield Kubernetes.watchPodUntilRunningAndRead();
|
||||
core.info(`Watching build job ${(_a = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`);
|
||||
yield Kubernetes.streamLogs(((_b = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace);
|
||||
}
|
||||
catch (error) {
|
||||
core.error('Failed while watching build job');
|
||||
|
|
@ -1092,6 +1091,7 @@ class Kubernetes {
|
|||
}
|
||||
static cleanup() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info('cleaning up');
|
||||
yield this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
|
||||
yield this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace);
|
||||
yield this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -292,34 +292,33 @@ class Kubernetes {
|
|||
}
|
||||
}
|
||||
|
||||
static async watchPodUntilReadyAndRead(statusFilter: string) {
|
||||
static async watchPodUntilRunningAndRead() {
|
||||
let ready = false;
|
||||
|
||||
while (!ready) {
|
||||
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const pods = await this.kubeClient.listNamespacedPod(this.namespace);
|
||||
for (let index = 0; index < pods.body.items.length; index++) {
|
||||
const element = pods.body.items[index];
|
||||
const jobname = element.metadata?.labels?.['job-name'];
|
||||
const phase = element.status?.phase;
|
||||
if (jobname === this.jobName && phase !== statusFilter) {
|
||||
core.info('Pod no longer pending');
|
||||
if (phase === 'Failure') {
|
||||
core.error('Kubernetes job failed');
|
||||
} else {
|
||||
ready = true;
|
||||
return element;
|
||||
}
|
||||
}
|
||||
const pod = (await this.kubeClient.readNamespacedPod(this.name, this.namespace))?.body;
|
||||
if (pod === undefined) {
|
||||
throw new Error('no pod found');
|
||||
}
|
||||
const phase = pod.status?.phase;
|
||||
if (phase === 'Running') {
|
||||
core.info('Pod no longer pending');
|
||||
}
|
||||
if (phase !== 'Pending') {
|
||||
core.error('Kubernetes job failed');
|
||||
} else {
|
||||
ready = true;
|
||||
return pod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async watchBuildJobUntilFinished() {
|
||||
try {
|
||||
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
|
||||
core.info(`Watching build job ${pod.metadata?.name}`);
|
||||
await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace);
|
||||
const pod = await Kubernetes.watchPodUntilRunningAndRead();
|
||||
core.info(`Watching build job ${pod?.metadata?.name}`);
|
||||
await Kubernetes.streamLogs(pod?.metadata?.name || '', this.namespace);
|
||||
} catch (error) {
|
||||
core.error('Failed while watching build job');
|
||||
throw error;
|
||||
|
|
@ -380,6 +379,7 @@ class Kubernetes {
|
|||
}
|
||||
|
||||
static async cleanup() {
|
||||
core.info('cleaning up');
|
||||
await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
|
||||
await this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace);
|
||||
await this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace);
|
||||
|
|
|
|||
Loading…
Reference in New Issue