test k8s on startup by listing namespaces to confirm kubeclient access

pull/437/head
Frostebite 2022-11-01 21:55:01 +00:00
parent 61071092c1
commit c657d15029
3 changed files with 28 additions and 23 deletions

18
dist/index.js vendored
View File

@ -2961,7 +2961,9 @@ const kubernetes_service_account_1 = __importDefault(__nccwpck_require__(47319))
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855)); const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144)); const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
class Kubernetes { class Kubernetes {
constructor(buildParameters) { constructor(
// eslint-disable-next-line no-unused-vars
buildParameters) {
this.buildGuid = ''; this.buildGuid = '';
this.pvcName = ''; this.pvcName = '';
this.secretName = ''; this.secretName = '';
@ -2970,13 +2972,6 @@ class Kubernetes {
this.containerName = ''; this.containerName = '';
this.cleanupCronJobName = ''; this.cleanupCronJobName = '';
this.serviceAccountName = ''; 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');
this.namespace = 'default';
this.buildParameters = buildParameters;
} }
listResources() { listResources() {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
@ -3013,6 +3008,13 @@ class Kubernetes {
defaultSecretsArray) { defaultSecretsArray) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { 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; const id = buildParameters.retainWorkspace ? cloud_runner_1.default.lockedWorkspace : buildParameters.buildGuid;
this.pvcName = `unity-builder-pvc-${id}`; this.pvcName = `unity-builder-pvc-${id}`;
this.cleanupCronJobName = `unity-builder-cronjob-${id}`; this.cleanupCronJobName = `unity-builder-cronjob-${id}`;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -17,30 +17,25 @@ import { ProviderResource } from '../provider-resource';
import { ProviderWorkflow } from '../provider-workflow'; import { ProviderWorkflow } from '../provider-workflow';
class Kubernetes implements ProviderInterface { class Kubernetes implements ProviderInterface {
private kubeConfig: k8s.KubeConfig; private kubeConfig!: k8s.KubeConfig;
private kubeClient: k8s.CoreV1Api; private kubeClient!: k8s.CoreV1Api;
private kubeClientBatch: k8s.BatchV1Api; private kubeClientBatch!: k8s.BatchV1Api;
private buildGuid: string = ''; private buildGuid: string = '';
private buildParameters: BuildParameters; private buildParameters!: BuildParameters;
private pvcName: string = ''; private pvcName: string = '';
private secretName: string = ''; private secretName: string = '';
private jobName: string = ''; private jobName: string = '';
private namespace: string; private namespace!: string;
private podName: string = ''; private podName: string = '';
private containerName: string = ''; private containerName: string = '';
private cleanupCronJobName: string = ''; private cleanupCronJobName: string = '';
private serviceAccountName: string = ''; private serviceAccountName: string = '';
constructor(buildParameters: BuildParameters) { constructor(
this.kubeConfig = new k8s.KubeConfig(); // eslint-disable-next-line no-unused-vars
this.kubeConfig.loadFromDefault(); buildParameters: BuildParameters,
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;
}
listResources(): Promise<ProviderResource[]> { listResources(): Promise<ProviderResource[]> {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -79,6 +74,14 @@ class Kubernetes implements ProviderInterface {
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[], defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
) { ) {
try { 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; const id = buildParameters.retainWorkspace ? CloudRunner.lockedWorkspace : buildParameters.buildGuid;
this.pvcName = `unity-builder-pvc-${id}`; this.pvcName = `unity-builder-pvc-${id}`;
this.cleanupCronJobName = `unity-builder-cronjob-${id}`; this.cleanupCronJobName = `unity-builder-cronjob-${id}`;