catch setup resource errors
parent
ebfa50648e
commit
aa15eda155
|
|
@ -1303,10 +1303,15 @@ class Kubernetes {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
defaultSecretsArray) {
|
defaultSecretsArray) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
this.pvcName = `unity-builder-pvc-${buildUid}`;
|
try {
|
||||||
this.cleanupCronJobName = `unity-builder-cronjob-${buildUid}`;
|
this.pvcName = `unity-builder-pvc-${buildUid}`;
|
||||||
yield kubernetes_storage_1.default.createPersistentVolumeClaim(buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
this.cleanupCronJobName = `unity-builder-cronjob-${buildUid}`;
|
||||||
yield kubernetes_cleanup_cronjob_1.default.createCleanupCronJob(this.kubeClientBatchBeta, this.cleanupCronJobName, this.namespace);
|
yield kubernetes_storage_1.default.createPersistentVolumeClaim(buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
||||||
|
yield kubernetes_cleanup_cronjob_1.default.createCleanupCronJob(this.kubeClientBatchBeta, this.cleanupCronJobName, this.namespace);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
runBuildTask(buildId, image, commands, mountdir, workingdir, environment, secrets) {
|
runBuildTask(buildId, image, commands, mountdir, workingdir, environment, secrets) {
|
||||||
|
|
@ -1406,43 +1411,48 @@ class KubernetesCleanupCronJob {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static createCleanupCronJob(kubeClientBatch, name, namespace) {
|
static createCleanupCronJob(kubeClientBatch, name, namespace) {
|
||||||
const batchJob = new client_node_1.V1beta1CronJob();
|
try {
|
||||||
batchJob.kind = 'CronJob';
|
const batchJob = new client_node_1.V1beta1CronJob();
|
||||||
batchJob.metadata = {
|
batchJob.kind = 'CronJob';
|
||||||
name,
|
batchJob.metadata = {
|
||||||
labels: {
|
name,
|
||||||
app: 'unity-builder',
|
labels: {
|
||||||
},
|
app: 'unity-builder',
|
||||||
};
|
|
||||||
const cronInstance = new cron_converter_1.Cron();
|
|
||||||
const date = Date.now() + 1000 * 60 * 60;
|
|
||||||
const spec = {
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: 'main',
|
|
||||||
image: 'bitnami/kubectl',
|
|
||||||
imagePullPolicy: '',
|
|
||||||
command: ['/bin/sh'],
|
|
||||||
args: [
|
|
||||||
'-c',
|
|
||||||
`
|
|
||||||
echo "delete the kubernetes resources"
|
|
||||||
kubectl get pods
|
|
||||||
`,
|
|
||||||
],
|
|
||||||
restartPolicy: '',
|
|
||||||
},
|
},
|
||||||
],
|
};
|
||||||
};
|
const cronInstance = new cron_converter_1.Cron();
|
||||||
batchJob.spec = {
|
const date = Date.now() + 1000 * 60 * 60;
|
||||||
schedule: cronInstance.schedule(new Date(date)).toString(),
|
const spec = {
|
||||||
jobTemplate: {
|
containers: [
|
||||||
spec: {
|
{
|
||||||
template: { spec },
|
name: 'main',
|
||||||
|
image: 'bitnami/kubectl',
|
||||||
|
imagePullPolicy: '',
|
||||||
|
command: ['/bin/sh'],
|
||||||
|
args: [
|
||||||
|
'-c',
|
||||||
|
`
|
||||||
|
echo "delete the kubernetes resources"
|
||||||
|
kubectl get pods
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
restartPolicy: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
batchJob.spec = {
|
||||||
|
schedule: cronInstance.schedule(new Date(date)).toString(),
|
||||||
|
jobTemplate: {
|
||||||
|
spec: {
|
||||||
|
template: { spec },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
kubeClientBatch.createNamespacedCronJob(namespace, batchJob);
|
||||||
kubeClientBatch.createNamespacedCronJob(namespace, batchJob);
|
}
|
||||||
|
catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.default = KubernetesCleanupCronJob;
|
exports.default = KubernetesCleanupCronJob;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -46,14 +46,23 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
||||||
) {
|
) {
|
||||||
this.pvcName = `unity-builder-pvc-${buildUid}`;
|
try {
|
||||||
this.cleanupCronJobName = `unity-builder-cronjob-${buildUid}`;
|
this.pvcName = `unity-builder-pvc-${buildUid}`;
|
||||||
await KubernetesStorage.createPersistentVolumeClaim(buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
this.cleanupCronJobName = `unity-builder-cronjob-${buildUid}`;
|
||||||
await KubernetesCleanupCronJob.createCleanupCronJob(
|
await KubernetesStorage.createPersistentVolumeClaim(
|
||||||
this.kubeClientBatchBeta,
|
buildParameters,
|
||||||
this.cleanupCronJobName,
|
this.pvcName,
|
||||||
this.namespace,
|
this.kubeClient,
|
||||||
);
|
this.namespace,
|
||||||
|
);
|
||||||
|
await KubernetesCleanupCronJob.createCleanupCronJob(
|
||||||
|
this.kubeClientBatchBeta,
|
||||||
|
this.cleanupCronJobName,
|
||||||
|
this.namespace,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async runBuildTask(
|
async runBuildTask(
|
||||||
|
|
|
||||||
|
|
@ -5,44 +5,48 @@ class KubernetesCleanupCronJob {
|
||||||
await api.deleteNamespacedCronJob('name', namespace);
|
await api.deleteNamespacedCronJob('name', namespace);
|
||||||
}
|
}
|
||||||
static createCleanupCronJob(kubeClientBatch: BatchV1beta1Api, name: string, namespace: string) {
|
static createCleanupCronJob(kubeClientBatch: BatchV1beta1Api, name: string, namespace: string) {
|
||||||
const batchJob = new V1beta1CronJob();
|
try {
|
||||||
batchJob.kind = 'CronJob';
|
const batchJob = new V1beta1CronJob();
|
||||||
batchJob.metadata = {
|
batchJob.kind = 'CronJob';
|
||||||
name,
|
batchJob.metadata = {
|
||||||
labels: {
|
name,
|
||||||
app: 'unity-builder',
|
labels: {
|
||||||
},
|
app: 'unity-builder',
|
||||||
};
|
|
||||||
const cronInstance = new Cron();
|
|
||||||
const date = Date.now() + 1000 * 60 * 60;
|
|
||||||
const spec = {
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: 'main',
|
|
||||||
image: 'bitnami/kubectl',
|
|
||||||
imagePullPolicy: '',
|
|
||||||
command: ['/bin/sh'],
|
|
||||||
args: [
|
|
||||||
'-c',
|
|
||||||
`
|
|
||||||
echo "delete the kubernetes resources"
|
|
||||||
kubectl get pods
|
|
||||||
`,
|
|
||||||
],
|
|
||||||
restartPolicy: '',
|
|
||||||
},
|
},
|
||||||
],
|
};
|
||||||
};
|
const cronInstance = new Cron();
|
||||||
batchJob.spec = {
|
const date = Date.now() + 1000 * 60 * 60;
|
||||||
schedule: cronInstance.schedule(new Date(date)).toString(),
|
const spec = {
|
||||||
jobTemplate: {
|
containers: [
|
||||||
spec: {
|
{
|
||||||
template: { spec },
|
name: 'main',
|
||||||
|
image: 'bitnami/kubectl',
|
||||||
|
imagePullPolicy: '',
|
||||||
|
command: ['/bin/sh'],
|
||||||
|
args: [
|
||||||
|
'-c',
|
||||||
|
`
|
||||||
|
echo "delete the kubernetes resources"
|
||||||
|
kubectl get pods
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
restartPolicy: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
batchJob.spec = {
|
||||||
|
schedule: cronInstance.schedule(new Date(date)).toString(),
|
||||||
|
jobTemplate: {
|
||||||
|
spec: {
|
||||||
|
template: { spec },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
|
||||||
kubeClientBatch.createNamespacedCronJob(namespace, batchJob);
|
kubeClientBatch.createNamespacedCronJob(namespace, batchJob);
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default KubernetesCleanupCronJob;
|
export default KubernetesCleanupCronJob;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue