Skip to content

Commit

Permalink
sync-notebook needs to look for a Deployment kind that is version ind…
Browse files Browse the repository at this point in the history
…ependent. (#2185)

Signed-off-by: Abhilash Pallerlamudi <stp.abhi@gmail.com>
  • Loading branch information
stpabhi committed Dec 31, 2018
1 parent ff5cfef commit f492770
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions kubeflow/jupyter/notebooks.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
data: {
"sync-notebook.jsonnet": (importstr "sync-notebook.jsonnet"),
"util.libsonnet": importstr "kubeflow/common/util.libsonnet",
},
},
notebooksConfigMap:: notebooksConfigMap,
Expand Down
78 changes: 76 additions & 2 deletions kubeflow/jupyter/sync-notebook.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// - Service
// - Pod
function(request) {
local util = import "util.libsonnet",
local sharedNamespace = request.controller.metadata.annotations.namespace,
local templateSpec = request.parent.spec.template.spec,
local podTemplateSpec = {
Expand All @@ -26,7 +27,7 @@ function(request) {
value: "true",
},
],
image: "gcr.io/kubeflow-images-public/tensorflow-1.10.1-notebook-cpu:v0.3.0",
image: "gcr.io/kubeflow-images-public/tensorflow-1.10.1-notebook-cpu:v0.4.0",
imagePullPolicy: "IfNotPresent",
name: "notebook",
ports: [
Expand Down Expand Up @@ -115,7 +116,80 @@ function(request) {
},
},
],
children: children,
local groupByResource(resources) = {
local getKey(resource) = {
return::
resource.kind,
}.return,
local getValue(resource) = {
return::
{ [resource.metadata.name]+: resource },
}.return,
return:: util.foldl(getKey, getValue, resources),
}.return,
local comparator(a, b) = {
return::
if a.metadata.name == b.metadata.name then
0
else
if a.metadata.name < b.metadata.name then
-1
else
1,
}.return,
local validateResource(resource) = {
return::
if std.type(resource) == "object" &&
std.objectHas(resource, "kind") &&
std.objectHas(resource, "apiVersion") &&
std.objectHas(resource, "metadata") &&
std.objectHas(resource.metadata, "name") then
true
else
false,
}.return,
local validatedChildren = util.sort(std.filter(validateResource, children), comparator),
local extractGroups(obj) =
if std.type(obj) == "object" then
[obj[key] for key in std.objectFields(obj)]
else
[],
local extractResources(group) =
if std.type(group) == "object" then
[group[key] for key in std.objectFields(group)]
else
[],
local curryResources(resources, exists) = {
local existingResource(resource) = {
local resourceExists(kind, name) = {
return::
if std.objectHas(resources, kind) &&
std.objectHas(resources[kind], name) then
true
else
false,
}.return,
return::
if validateResource(resource) then
resourceExists(resource.kind, resource.metadata.name)
else
false,
}.return,
local missingResource(resource) = {
return::
existingResource(resource) == false,
}.return,
return::
if exists == true then
existingResource
else
missingResource,
}.return,
local requestedChildren = std.flattenArrays(std.map(extractResources, extractGroups(request.children))),
local groupedRequestedChildren = groupByResource(requestedChildren),
local missingChildren = util.sort(std.filter(curryResources(groupedRequestedChildren, false), validatedChildren), comparator),
local desired = requestedChildren + missingChildren,
children: desired,
status: {
phase: "Active",
conditions: [{
Expand Down

0 comments on commit f492770

Please sign in to comment.