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 Jan 3, 2019
1 parent 83a408a commit 6bcede8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
74 changes: 74 additions & 0 deletions kubeflow/common/util.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,80 @@
return:: aux(a, b, 0, 0, []) tailstrict,
}.return,

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,

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,

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,

extractGroups(obj)::
if std.type(obj) == "object" then
[obj[key] for key in std.objectFields(obj)]
else
[],

extractResources(group)::
if std.type(group) == "object" then
[group[key] for key in std.objectFields(group)]
else
[],

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 util.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,

// Produce a list of manifests. obj must be an array
list(obj):: k.core.v1.list.new(obj,),
}
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
8 changes: 7 additions & 1 deletion 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 Down Expand Up @@ -115,7 +116,12 @@ function(request) {
},
},
],
children: children,
local validatedChildren = util.sort(std.filter(util.validateResource, children), util.comparator),
local requestedChildren = std.flattenArrays(std.map(util.extractResources, util.extractGroups(request.children))),
local groupedRequestedChildren = util.groupByResource(requestedChildren),
local missingChildren = util.sort(std.filter(util.curryResources(groupedRequestedChildren, false), validatedChildren), util.comparator),
local desired = requestedChildren + missingChildren,
children: desired,
status: {
phase: "Active",
conditions: [{
Expand Down
1 change: 1 addition & 0 deletions kubeflow/jupyter/tests/notebooks_test.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ std.assertEqual(
apiVersion: "v1",
data: {
"sync-notebook.jsonnet": (importstr "../sync-notebook.jsonnet"),
"util.libsonnet": (importstr "kubeflow/common/util.libsonnet"),
},
kind: "ConfigMap",
metadata: {
Expand Down
2 changes: 1 addition & 1 deletion kubeflow/jupyter/tests/sync-notebook_test.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local env = {
namespace: "kubeflow",
};

local syncNotebook = import "../sync-notebook.jsonnet";
local syncNotebook = import "sync-notebook.jsonnet";

local notebook = {
apiVersion: "kubeflow.org/v1alpha1",
Expand Down

0 comments on commit 6bcede8

Please sign in to comment.