mirror of https://github.com/kubeflow/examples.git
Refactor job and deployment specs into different functions
This commit is contained in:
parent
e34f9aca75
commit
133e054033
|
@ -1,9 +1,9 @@
|
||||||
local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
|
|
||||||
{
|
{
|
||||||
spec(params, env, apiVersion="extensions/v1beta1", kind="Deployment"):: {
|
deploymentSpec(params, env, containers):: {
|
||||||
apiVersion: apiVersion,
|
apiVersion: "extensions/v1beta1",
|
||||||
kind: kind,
|
kind: "Deployment",
|
||||||
metadata: {
|
metadata: {
|
||||||
name: params.name,
|
name: params.name,
|
||||||
namespace: env.namespace,
|
namespace: env.namespace,
|
||||||
|
@ -13,7 +13,7 @@ local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
replicas: params.replicas,
|
replicas: params.replicas,
|
||||||
[if kind == "Deployment" then "selector"]: {
|
selector: {
|
||||||
matchLabels: {
|
matchLabels: {
|
||||||
app: params.name,
|
app: params.name,
|
||||||
},
|
},
|
||||||
|
@ -25,31 +25,7 @@ local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
[if kind == "Job" then "restartPolicy"]: "OnFailure",
|
containers: containers,
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: params.name,
|
|
||||||
image: params.image,
|
|
||||||
args: params.args,
|
|
||||||
ports: [
|
|
||||||
{
|
|
||||||
containerPort: 8008,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
env: [
|
|
||||||
{
|
|
||||||
name: "GOOGLE_APPLICATION_CREDENTIALS",
|
|
||||||
value: "/secret/gcp-credentials/user-gcp-sa.json",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
volumeMounts: [
|
|
||||||
{
|
|
||||||
mountPath: "/secret/gcp-credentials",
|
|
||||||
name: "gcp-credentials",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
],
|
|
||||||
volumes: [
|
volumes: [
|
||||||
{
|
{
|
||||||
name: "gcp-credentials",
|
name: "gcp-credentials",
|
||||||
|
@ -63,6 +39,63 @@ local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
jobSpec(params, env, containers):: {
|
||||||
|
apiVersion: "batch/v1",
|
||||||
|
kind: "Job",
|
||||||
|
metadata: {
|
||||||
|
name: params.name,
|
||||||
|
namespace: env.namespace,
|
||||||
|
labels: {
|
||||||
|
app: params.name,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
replicas: params.replicas,
|
||||||
|
template: {
|
||||||
|
metadata: {
|
||||||
|
labels: {
|
||||||
|
app: params.name,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
"restartPolicy": "OnFailure",
|
||||||
|
containers: containers,
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: "gcp-credentials",
|
||||||
|
secret: {
|
||||||
|
secretName: "user-gcp-sa",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
containerSpec(params):: {
|
||||||
|
name: params.name,
|
||||||
|
image: params.image,
|
||||||
|
args: params.args,
|
||||||
|
ports: [
|
||||||
|
{
|
||||||
|
containerPort: 8008,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
env: [
|
||||||
|
{
|
||||||
|
name: "GOOGLE_APPLICATION_CREDENTIALS",
|
||||||
|
value: "/secret/gcp-credentials/user-gcp-sa.json",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
volumeMounts: [
|
||||||
|
{
|
||||||
|
mountPath: "/secret/gcp-credentials",
|
||||||
|
name: "gcp-credentials",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
service(params, env):: {
|
service(params, env):: {
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Service",
|
kind: "Service",
|
||||||
|
@ -116,7 +149,7 @@ local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
},
|
},
|
||||||
|
|
||||||
all: [
|
all: [
|
||||||
$.spec(creatorParams, env, apiVersion="batch/v1", kind="Job"),
|
$.jobSpec(creatorParams, env, [ $.containerSpec(creatorParams) ]),
|
||||||
],
|
],
|
||||||
}.all,
|
}.all,
|
||||||
|
|
||||||
|
@ -135,7 +168,7 @@ local baseParams = std.extVar("__ksonnet/params").components["nmslib"];
|
||||||
|
|
||||||
all: [
|
all: [
|
||||||
$.service(serverParams, env),
|
$.service(serverParams, env),
|
||||||
$.spec(serverParams, env),
|
$.deploymentSpec(serverParams, env, [ $.containerSpec(serverParams) ]),
|
||||||
],
|
],
|
||||||
}.all,
|
}.all,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue