-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runJob/kubernetes): use explicit pod name (#7039)
the previous implementation of run job used manifest events to get the name of the pod created by the job. this proved unreliable as events roll off quickly in large environments. this commit implements a `PodNameProvider` interface which supplies `JobManifestPodLogs` with the name of the Pod to fetch logs from. Run Job supplies these Pod names by collecting all Pods owned by the Job. For components which are still event based, the `JobEventBasedPodNameProvider` implements the previously used logic for getting the Pod name from the event.
- Loading branch information
1 parent
fc1cd1b
commit f0287a1
Showing
9 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/scripts/modules/core/src/manifest/PodNameProvider.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DefaultPodNameProvider, JobEventBasedPodNameProvider } from './PodNameProvider'; | ||
import { IManifest, IManifestEvent } from 'core/domain'; | ||
|
||
describe('PodNameProvider', function() { | ||
describe('DefaultPodNameProvider', function() { | ||
it('returns the pod name supplied to it', function() { | ||
const podName = 'test'; | ||
const provider = new DefaultPodNameProvider(podName); | ||
expect(provider.getPodName()).toBe(podName); | ||
}); | ||
}); | ||
|
||
describe('JobEventBasedPodNameProvider', function() { | ||
it('returns a pod name parsed from a message', function() { | ||
const podName = 'test'; | ||
const manifest = { manifest: { kind: 'Job', status: true } } as IManifest; | ||
const manifestEvent = { message: `Created pod: ${podName}` } as IManifestEvent; | ||
const provider = new JobEventBasedPodNameProvider(manifest, manifestEvent); | ||
expect(provider.getPodName()).toBe(podName); | ||
}); | ||
|
||
it('returns a empty string if manifest is not of type Job', function() { | ||
const podName = 'test'; | ||
const manifest = { manifest: { kind: 'Deployment', status: true } } as IManifest; | ||
const manifestEvent = { message: `Created pod: ${podName}` } as IManifestEvent; | ||
const provider = new JobEventBasedPodNameProvider(manifest, manifestEvent); | ||
expect(provider.getPodName()).toBe(''); | ||
}); | ||
|
||
it('returns empty string for messages that do not start with Created pod', function() { | ||
const podName = 'test'; | ||
const manifest = { manifest: { kind: 'Job', status: true } } as IManifest; | ||
const manifestEvent = { message: `Killed pod: ${podName}` } as IManifestEvent; | ||
const provider = new JobEventBasedPodNameProvider(manifest, manifestEvent); | ||
expect(provider.getPodName()).toBe(''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { IManifest, IManifestEvent } from 'core/domain'; | ||
import { trim } from 'lodash'; | ||
|
||
// when fetching logs from Pods there are some instances | ||
// where we know the name of the Pod ahead of time and some | ||
// where we must extract the name of the Pod from a Kubernetes | ||
// event. IPodNameProvider allows us to inject a Pod name into | ||
// components which need them based on a given situation where | ||
// the caller knows how to the name should be supplied. | ||
export interface IPodNameProvider { | ||
getPodName(): string; | ||
} | ||
|
||
export class DefaultPodNameProvider implements IPodNameProvider { | ||
private podName: string; | ||
|
||
constructor(podName: string) { | ||
this.podName = podName; | ||
} | ||
|
||
public getPodName(): string { | ||
return this.podName; | ||
} | ||
} | ||
|
||
export class JobEventBasedPodNameProvider implements IPodNameProvider { | ||
private manifest: IManifest; | ||
private manifestEvent: IManifestEvent; | ||
|
||
constructor(manifest: IManifest, manifestEvent: IManifestEvent) { | ||
this.manifest = manifest; | ||
this.manifestEvent = manifestEvent; | ||
} | ||
|
||
public getPodName(): string { | ||
const { manifestEvent } = this; | ||
return this.canParsePodName() ? trim(manifestEvent.message.split(':')[1]) : ''; | ||
} | ||
|
||
private canParsePodName(): boolean { | ||
const { manifest, manifestEvent } = this; | ||
return ( | ||
!!manifest.manifest && | ||
!!manifest.manifest.status && | ||
!!manifestEvent && | ||
!!manifestEvent.message.startsWith('Created pod') && | ||
manifest.manifest.kind.toLowerCase() === 'job' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters