Kubernetes refactoring

pull/273/head
Frostebite 2021-06-06 21:32:24 +01:00
parent 045c4217d1
commit 8f79ef98f8
4 changed files with 148 additions and 142 deletions

View File

@ -46,10 +46,6 @@ jobs:
###########################
# Build #
###########################
# - uses: frostebite/File-To-Base64@master
# id: read-base64
# with:
# filePath: ~/.kube/config
- uses: ./
id: k8s-unity-build
with:

21
dist/index.js vendored
View File

@ -838,9 +838,7 @@ class Kubernetes {
core.info('Persistent Volume created, waiting for ready state...');
});
}
runJob(command, image) {
return __awaiter(this, void 0, void 0, function* () {
core.info('Creating build job');
getJobSpec(command, image) {
const job = new k8s.V1Job();
job.apiVersion = 'batch/v1';
job.kind = 'Job';
@ -963,9 +961,14 @@ class Kubernetes {
},
};
job.spec.backoffLimit = 1;
yield this.kubeClientBatch.createNamespacedJob(this.namespace, job);
core.info('Job created');
return job;
}
runJob(jobSpec) {
return __awaiter(this, void 0, void 0, function* () {
try {
core.info('Creating build job');
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
// 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.
@ -994,7 +997,7 @@ class Kubernetes {
}
runCloneJob() {
return __awaiter(this, void 0, void 0, function* () {
yield this.runJob([
yield this.runJob(this.getJobSpec([
'/bin/ash',
'-c',
`apk update;
@ -1008,12 +1011,12 @@ class Kubernetes {
git checkout $GITHUB_SHA;
ls
echo "end"`,
], 'alpine/git');
], 'alpine/git'));
});
}
runBuildJob() {
return __awaiter(this, void 0, void 0, function* () {
yield this.runJob([
yield this.runJob(this.getJobSpec([
'bin/bash',
'-c',
`ls
@ -1028,7 +1031,7 @@ class Kubernetes {
chmod -R +x /steps
/entrypoint.sh
`,
], this.baseImage.toString());
], this.baseImage.toString()));
});
}
watchPersistentVolumeClaimUntilReady() {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -125,8 +125,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
core.info('Persistent Volume created, waiting for ready state...');
}
async runJob(command: string[], image: string) {
core.info('Creating build job');
getJobSpec(command: string[], image: string) {
const job = new k8s.V1Job();
job.apiVersion = 'batch/v1';
job.kind = 'Job';
@ -249,10 +248,14 @@ class Kubernetes implements RemoteBuilderProviderInterface {
},
};
job.spec.backoffLimit = 1;
await this.kubeClientBatch.createNamespacedJob(this.namespace, job);
core.info('Job created');
return job;
}
async runJob(jobSpec: k8s.V1Job) {
try {
core.info('Creating build job');
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
// We watch the PVC first to allow some time for K8s to notice the job we created and setup a pod.
await this.watchPersistentVolumeClaimUntilReady();
@ -281,6 +284,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
async runCloneJob() {
await this.runJob(
this.getJobSpec(
[
'/bin/ash',
'-c',
@ -297,11 +301,13 @@ class Kubernetes implements RemoteBuilderProviderInterface {
echo "end"`,
],
'alpine/git',
),
);
}
async runBuildJob() {
await this.runJob(
this.getJobSpec(
[
'bin/bash',
'-c',
@ -319,6 +325,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
`,
],
this.baseImage.toString(),
),
);
}