test k8s on startup by listing namespaces to confirm kubeclient access
parent
c657d15029
commit
4ec9743235
|
|
@ -2955,15 +2955,13 @@ const core = __importStar(__nccwpck_require__(42186));
|
|||
const kubernetes_storage_1 = __importDefault(__nccwpck_require__(49043));
|
||||
const kubernetes_task_runner_1 = __importDefault(__nccwpck_require__(70801));
|
||||
const kubernetes_secret_1 = __importDefault(__nccwpck_require__(95875));
|
||||
const async_wait_until_1 = __importDefault(__nccwpck_require__(41299));
|
||||
const kubernetes_job_spec_factory_1 = __importDefault(__nccwpck_require__(3610));
|
||||
const kubernetes_service_account_1 = __importDefault(__nccwpck_require__(47319));
|
||||
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
||||
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
|
||||
class Kubernetes {
|
||||
constructor(
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
buildParameters) {
|
||||
constructor(buildParameters) {
|
||||
this.buildGuid = '';
|
||||
this.pvcName = '';
|
||||
this.secretName = '';
|
||||
|
|
@ -2972,6 +2970,11 @@ class Kubernetes {
|
|||
this.containerName = '';
|
||||
this.cleanupCronJobName = '';
|
||||
this.serviceAccountName = '';
|
||||
this.kubeConfig = new k8s.KubeConfig();
|
||||
this.kubeConfig.loadFromDefault();
|
||||
this.kubeClient = this.kubeConfig.makeApiClient(k8s.CoreV1Api);
|
||||
this.kubeClientBatch = this.kubeConfig.makeApiClient(k8s.BatchV1Api);
|
||||
cloud_runner_logger_1.default.log('Loaded default Kubernetes configuration for this environment');
|
||||
}
|
||||
listResources() {
|
||||
throw new Error('Method not implemented.');
|
||||
|
|
@ -3008,11 +3011,6 @@ class Kubernetes {
|
|||
defaultSecretsArray) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
this.kubeConfig = new k8s.KubeConfig();
|
||||
this.kubeConfig.loadFromDefault();
|
||||
this.kubeClient = this.kubeConfig.makeApiClient(k8s.CoreV1Api);
|
||||
this.kubeClientBatch = this.kubeConfig.makeApiClient(k8s.BatchV1Api);
|
||||
cloud_runner_logger_1.default.log('Loaded default Kubernetes configuration for this environment');
|
||||
this.namespace = 'default';
|
||||
this.buildParameters = buildParameters;
|
||||
const id = buildParameters.retainWorkspace ? cloud_runner_1.default.lockedWorkspace : buildParameters.buildGuid;
|
||||
|
|
@ -3032,7 +3030,7 @@ class Kubernetes {
|
|||
try {
|
||||
cloud_runner_logger_1.default.log('Cloud Runner K8s workflow!');
|
||||
// Setup
|
||||
this.buildGuid = buildGuid + Date.now();
|
||||
this.buildGuid = buildGuid;
|
||||
this.secretName = `build-credentials-${this.buildGuid}`;
|
||||
this.jobName = `unity-builder-job-${this.buildGuid}`;
|
||||
this.containerName = `main`;
|
||||
|
|
@ -3117,19 +3115,6 @@ class Kubernetes {
|
|||
throw error;
|
||||
}
|
||||
cloud_runner_logger_1.default.log('cleaning up finished');
|
||||
try {
|
||||
yield async_wait_until_1.default(() => __awaiter(this, void 0, void 0, function* () {
|
||||
var _b;
|
||||
const jobBody = (yield this.kubeClientBatch.readNamespacedJob(this.jobName, this.namespace)).body;
|
||||
const podBody = (yield this.kubeClient.readNamespacedPod(this.podName, this.namespace)).body;
|
||||
return (jobBody === null || ((_b = jobBody.status) === null || _b === void 0 ? void 0 : _b.active) === 0) && podBody === null;
|
||||
}), {
|
||||
timeout: 500000,
|
||||
intervalBetweenAttempts: 15000,
|
||||
});
|
||||
// eslint-disable-next-line no-empty
|
||||
}
|
||||
catch (_a) { }
|
||||
});
|
||||
}
|
||||
cleanupWorkflow(buildGuid, buildParameters,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -7,7 +7,6 @@ import KubernetesStorage from './kubernetes-storage';
|
|||
import CloudRunnerEnvironmentVariable from '../../services/cloud-runner-environment-variable';
|
||||
import KubernetesTaskRunner from './kubernetes-task-runner';
|
||||
import KubernetesSecret from './kubernetes-secret';
|
||||
import waitUntil from 'async-wait-until';
|
||||
import KubernetesJobSpecFactory from './kubernetes-job-spec-factory';
|
||||
import KubernetesServiceAccount from './kubernetes-service-account';
|
||||
import CloudRunnerLogger from '../../services/cloud-runner-logger';
|
||||
|
|
@ -31,10 +30,14 @@ class Kubernetes implements ProviderInterface {
|
|||
private cleanupCronJobName: string = '';
|
||||
private serviceAccountName: string = '';
|
||||
|
||||
constructor(
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
buildParameters: BuildParameters,
|
||||
) {}
|
||||
constructor(buildParameters: BuildParameters) {
|
||||
this.kubeConfig = new k8s.KubeConfig();
|
||||
this.kubeConfig.loadFromDefault();
|
||||
this.kubeClient = this.kubeConfig.makeApiClient(k8s.CoreV1Api);
|
||||
this.kubeClientBatch = this.kubeConfig.makeApiClient(k8s.BatchV1Api);
|
||||
CloudRunnerLogger.log('Loaded default Kubernetes configuration for this environment');
|
||||
}
|
||||
|
||||
listResources(): Promise<ProviderResource[]> {
|
||||
throw new Error('Method not implemented.');
|
||||
|
|
@ -74,12 +77,6 @@ class Kubernetes implements ProviderInterface {
|
|||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
||||
) {
|
||||
try {
|
||||
this.kubeConfig = new k8s.KubeConfig();
|
||||
this.kubeConfig.loadFromDefault();
|
||||
this.kubeClient = this.kubeConfig.makeApiClient(k8s.CoreV1Api);
|
||||
this.kubeClientBatch = this.kubeConfig.makeApiClient(k8s.BatchV1Api);
|
||||
CloudRunnerLogger.log('Loaded default Kubernetes configuration for this environment');
|
||||
|
||||
this.namespace = 'default';
|
||||
this.buildParameters = buildParameters;
|
||||
const id = buildParameters.retainWorkspace ? CloudRunner.lockedWorkspace : buildParameters.buildGuid;
|
||||
|
|
@ -112,7 +109,7 @@ class Kubernetes implements ProviderInterface {
|
|||
CloudRunnerLogger.log('Cloud Runner K8s workflow!');
|
||||
|
||||
// Setup
|
||||
this.buildGuid = buildGuid + Date.now();
|
||||
this.buildGuid = buildGuid;
|
||||
this.secretName = `build-credentials-${this.buildGuid}`;
|
||||
this.jobName = `unity-builder-job-${this.buildGuid}`;
|
||||
this.containerName = `main`;
|
||||
|
|
@ -219,21 +216,6 @@ class Kubernetes implements ProviderInterface {
|
|||
throw error;
|
||||
}
|
||||
CloudRunnerLogger.log('cleaning up finished');
|
||||
try {
|
||||
await waitUntil(
|
||||
async () => {
|
||||
const jobBody = (await this.kubeClientBatch.readNamespacedJob(this.jobName, this.namespace)).body;
|
||||
const podBody = (await this.kubeClient.readNamespacedPod(this.podName, this.namespace)).body;
|
||||
|
||||
return (jobBody === null || jobBody.status?.active === 0) && podBody === null;
|
||||
},
|
||||
{
|
||||
timeout: 500000,
|
||||
intervalBetweenAttempts: 15000,
|
||||
},
|
||||
);
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async cleanupWorkflow(
|
||||
|
|
|
|||
Loading…
Reference in New Issue