-
Notifications
You must be signed in to change notification settings - Fork 5
Add Kind class job #20
Changes from all commits
1425872
c25d4ea
2840060
4f99c3c
70629f3
2368826
15c5c20
f19a2de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./github"; | ||
export * from "./kind"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Job } from "@brigadecore/brigadier"; | ||
export declare const kindJobImage = "radumatei/golang-kind:1.11-0.4"; | ||
export declare class KindJob extends Job { | ||
constructor(name: string, image?: string); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./github"; | ||
export * from "./kind"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Job } from "@brigadecore/brigadier"; | ||
|
||
export const kindJobImage = "radumatei/golang-kind:1.11-0.4"; | ||
vdice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export class KindJob extends Job { | ||
constructor(name: string, image?: string) { | ||
if (image == undefined) { | ||
image = kindJobImage; | ||
} | ||
super(name, image); | ||
|
||
// kind needs to run as a privileged pod | ||
this.privileged = true; | ||
vdice marked this conversation as resolved.
Show resolved
Hide resolved
vdice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// since the cluster creation takes some time, | ||
// set the timeout to 30 minutes | ||
this.timeout = 180000; | ||
radu-matei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// kind needs to add the following volumeMounts to function properly | ||
// the Brigade project must enable `allowHostMounts` | ||
this.volumes = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm super curious as to what each volume mount enables -- could we add a note to each? |
||
{ | ||
name: "modules", | ||
hostPath: { | ||
path: "/lib/modules", | ||
type: "Directory" | ||
} | ||
}, | ||
{ | ||
name: "cgroup", | ||
hostPath: { | ||
path: "/sys/fs/cgroup", | ||
type: "Directory" | ||
} | ||
}, | ||
{ | ||
name: "docker-graph-storage", | ||
emptyDir: {} | ||
} | ||
]; | ||
this.volumeMounts = [ | ||
{ | ||
name: "modules", | ||
mountPath: "/lib/modules", | ||
readOnly: true | ||
}, | ||
{ | ||
name: "cgroup", | ||
mountPath: "/sys/fs/cgroup" | ||
}, | ||
{ | ||
name: "docker-graph-storage", | ||
mountPath: "/var/lib/docker" | ||
} | ||
]; | ||
|
||
// to add your own tasks to this job, use job.tasks.push() | ||
this.tasks = [ | ||
vdice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// when the pod finishes, regardless of the exit code, delete the cluster | ||
// to avoid resource leaks | ||
// see https://github.com/kubernetes-sigs/kind/issues/759 | ||
"trap 'kind delete cluster' EXIT", | ||
"dockerd-entrypoint.sh &", | ||
"sleep 20", | ||
"kind create cluster --wait 300s", | ||
`export KUBECONFIG="$(kind get kubeconfig-path)"`, | ||
// this pod is running inside a Kubernetes cluster | ||
// unset environment variables pointing to the host cluster | ||
// even if the service account is limited, and KUBECONFIG is properly set, | ||
// some operations might still point to the in-cluster configuration | ||
"unset $(env | grep KUBERNETES_ | xargs)", | ||
"kubectl cluster-info", | ||
"kubectl get pods --all-namespaces", | ||
// even though we're using the --wait flag for kind, | ||
// some pods (the DNS pods, for example) are not ready yet. | ||
"sleep 60" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import "mocha"; | ||
import { assert } from "chai"; | ||
import { KindJob, kindJobImage } from "../src/kind"; | ||
|
||
describe("when creating a new Kind job", () => { | ||
it("without an image for the job, the default image is used", () => { | ||
let kind = new KindJob("kind"); | ||
|
||
assert.equal(kind.name, "kind"); | ||
assert.equal(kind.image, kindJobImage); | ||
}); | ||
|
||
it("and an image is passed, the image is used", () => { | ||
let kind = new KindJob("kind", "my-custom-kind-image"); | ||
|
||
assert.equal(kind.name, "kind"); | ||
assert.equal(kind.image, "my-custom-kind-image"); | ||
}); | ||
|
||
it("job is privilged, with right number of pre-defined tasks", () => { | ||
let kind = new KindJob("kind"); | ||
|
||
assert.isTrue(kind.privileged); | ||
assert.equal(kind.tasks.length, 9); | ||
}); | ||
|
||
it("all volumes are properly set", () => { | ||
let kind = new KindJob("kind"); | ||
assert.equal(kind.volumeMounts.length, 3); | ||
|
||
assert.equal(kind.volumes[0].name, "modules"); | ||
assert.equal(kind.volumes[0].hostPath!.path, "/lib/modules"); | ||
assert.equal(kind.volumes[0].hostPath!.type, "Directory"); | ||
assert.equal(kind.volumes[1].name, "cgroup"); | ||
assert.equal(kind.volumes[1].hostPath!.path, "/sys/fs/cgroup"); | ||
assert.equal(kind.volumes[1].hostPath!.type, "Directory"); | ||
assert.equal(kind.volumes[2].name, "docker-graph-storage"); | ||
assert.deepEqual(kind.volumes[2].emptyDir!, {}); | ||
}); | ||
|
||
it("all volume mounts are properly set", () => { | ||
let kind = new KindJob("kind"); | ||
|
||
assert.equal(kind.volumeMounts.length, 3); | ||
assert.equal(kind.volumeMounts[0].name, "modules"); | ||
assert.equal(kind.volumeMounts[0].mountPath, "/lib/modules"); | ||
assert.equal(kind.volumeMounts[1].name, "cgroup"); | ||
assert.equal(kind.volumeMounts[1].mountPath, "/sys/fs/cgroup"); | ||
assert.equal(kind.volumeMounts[2].name, "docker-graph-storage"); | ||
assert.equal(kind.volumeMounts[2].mountPath, "/var/lib/docker"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still want to host this image (and repo containing Dockerfile) in bridagecore? I'd be fine with a follow-up ticket/PR, just wanted to make a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd like to gather all things in the same place, but I wouldn't hold this PR for it.