Kubernetes refactor

pull/273/head
Frostebite 2021-06-06 20:43:26 +01:00
parent 9309e3aa91
commit 3c511811db
3 changed files with 13 additions and 11 deletions

10
dist/index.js vendored
View File

@ -946,7 +946,7 @@ class Kubernetes {
// We watch the PVC first to allow some time for K8s to notice the job we created and setup a pod.
yield this.watchPersistentVolumeClaimUntilReady();
// TODO: Wait for something more reliable so we don't potentially get the pod before k8s has created it based on the job.
yield this.getPodAndCache();
this.setPodNameAndContainerName(yield this.getPod());
yield this.watchUntilPodRunning();
yield this.streamLogs();
}
@ -958,11 +958,10 @@ class Kubernetes {
}
});
}
getPodAndCache() {
getPod() {
return __awaiter(this, void 0, void 0, function* () {
if (this.podName === undefined) {
const pod = (yield this.kubeClient.listNamespacedPod(this.namespace)).body.items.find((x) => { var _a, _b; return ((_b = (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['job-name']) === this.jobName; });
this.setPod(pod);
return pod;
}
else {
@ -983,7 +982,8 @@ class Kubernetes {
git clone https://github.com/webbertakken/unity-builder.git builder;
cd repo;
git checkout $GITHUB_SHA;
ls`,
ls
echo "end"`,
], 'alpine/git');
});
}
@ -1042,7 +1042,7 @@ class Kubernetes {
}
});
}
setPod(pod) {
setPodNameAndContainerName(pod) {
var _a, _b, _c;
this.podName = ((_a = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _a === void 0 ? void 0 : _a.name) || '';
this.containerName = ((_c = (_b = pod === null || pod === void 0 ? void 0 : pod.status) === null || _b === void 0 ? void 0 : _b.containerStatuses) === null || _c === void 0 ? void 0 : _c[0].name) || '';

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -235,8 +235,10 @@ class Kubernetes implements RemoteBuilderProviderInterface {
try {
// We watch the PVC first to allow some time for K8s to notice the job we created and setup a pod.
await this.watchPersistentVolumeClaimUntilReady();
// TODO: Wait for something more reliable so we don't potentially get the pod before k8s has created it based on the job.
await this.getPodAndCache();
this.setPodNameAndContainerName(await this.getPod());
await this.watchUntilPodRunning();
await this.streamLogs();
} catch (error) {
@ -246,12 +248,11 @@ class Kubernetes implements RemoteBuilderProviderInterface {
}
}
async getPodAndCache() {
async getPod() {
if (this.podName === undefined) {
const pod = (await this.kubeClient.listNamespacedPod(this.namespace)).body.items.find(
(x) => x.metadata?.labels?.['job-name'] === this.jobName,
);
this.setPod(pod);
return pod;
} else {
return (await this.kubeClient.readNamespacedPod(this.podName, this.namespace)).body;
@ -271,7 +272,8 @@ class Kubernetes implements RemoteBuilderProviderInterface {
git clone https://github.com/webbertakken/unity-builder.git builder;
cd repo;
git checkout $GITHUB_SHA;
ls`,
ls
echo "end"`,
],
'alpine/git',
);
@ -331,7 +333,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
}
}
setPod(pod: k8s.V1Pod | any) {
setPodNameAndContainerName(pod: k8s.V1Pod | any) {
this.podName = pod?.metadata?.name || '';
this.containerName = pod?.status?.containerStatuses?.[0].name || '';
}