Skip to content

Commit 0c82a58

Browse files
authored
Fix bug with CloudRunner and K8s with Namespaces (#763)
* Fixes bug where kubectl picks a different namespace (e.g. cloud runner is kicked from self hosted k8s agents that are in a non default namespace) * update generated content * Add support for setting a namespace for containers in Cloud Runner
1 parent 1d4ee06 commit 0c82a58

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

dist/index.js

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/build-parameters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class BuildParameters {
5959
public kubeConfig!: string;
6060
public containerMemory!: string;
6161
public containerCpu!: string;
62+
public containerNamespace!: string;
6263
public kubeVolumeSize!: string;
6364
public kubeVolume!: string;
6465
public kubeStorageClass!: string;
@@ -187,6 +188,7 @@ class BuildParameters {
187188
kubeConfig: CloudRunnerOptions.kubeConfig,
188189
containerMemory: CloudRunnerOptions.containerMemory,
189190
containerCpu: CloudRunnerOptions.containerCpu,
191+
containerNamespace: CloudRunnerOptions.containerNamespace,
190192
kubeVolumeSize: CloudRunnerOptions.kubeVolumeSize,
191193
kubeVolume: CloudRunnerOptions.kubeVolume,
192194
postBuildContainerHooks: CloudRunnerOptions.postBuildContainerHooks,

src/model/cloud-runner/options/cloud-runner-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class CloudRunnerOptions {
135135
return CloudRunnerOptions.getInput('containerMemory') || `3072`;
136136
}
137137

138+
static get containerNamespace(): string {
139+
return CloudRunnerOptions.getInput('containerNamespace') || `default`;
140+
}
141+
138142
static get customJob(): string {
139143
return CloudRunnerOptions.getInput('customJob') || '';
140144
}

src/model/cloud-runner/providers/k8s/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Kubernetes implements ProviderInterface {
3737
public serviceAccountName: string = '';
3838
public ip: string = '';
3939

40-
// eslint-disable-next-line no-unused-vars
4140
constructor(buildParameters: BuildParameters) {
4241
Kubernetes.Instance = this;
4342
this.kubeConfig = new k8s.KubeConfig();
@@ -46,7 +45,7 @@ class Kubernetes implements ProviderInterface {
4645
this.kubeClientApps = this.kubeConfig.makeApiClient(k8s.AppsV1Api);
4746
this.kubeClientBatch = this.kubeConfig.makeApiClient(k8s.BatchV1Api);
4847
this.rbacAuthorizationV1Api = this.kubeConfig.makeApiClient(k8s.RbacAuthorizationV1Api);
49-
this.namespace = 'default';
48+
this.namespace = buildParameters.containerNamespace ? buildParameters.containerNamespace : 'default';
5049
CloudRunnerLogger.log('Loaded default Kubernetes configuration for this environment');
5150
}
5251

src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class KubernetesTaskRunner {
3030
);
3131
let extraFlags = ``;
3232
extraFlags += (await KubernetesPods.IsPodRunning(podName, namespace, kubeClient))
33-
? ` -f -c ${containerName}`
34-
: ` --previous`;
33+
? ` -f -c ${containerName} -n ${namespace}`
34+
: ` --previous -n ${namespace}`;
3535

3636
const callback = (outputChunk: string) => {
3737
output += outputChunk;

0 commit comments

Comments
 (0)