forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync-notebook needs to look for a Deployment kind that is version ind…
…ependent (kubeflow#2194) Signed-off-by: Abhilash Pallerlamudi <[email protected]>
- Loading branch information
1 parent
fda860f
commit 47162b3
Showing
5 changed files
with
262 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
// Some useful routines. | ||
// Duplicating kubeflow/common/util.libsonnet for unit tests to work. | ||
// For lambda metacontroller it's available via ConfigMap. | ||
{ | ||
local k = import "k.libsonnet", | ||
local util = self, | ||
|
||
// Convert a string to lower case. | ||
lower:: function(x) { | ||
local cp(c) = std.codepoint(c), | ||
local lowerLetter(c) = if cp(c) >= 65 && cp(c) < 91 then | ||
std.char(cp(c) + 32) | ||
else c, | ||
result:: std.join("", std.map(lowerLetter, std.stringChars(x))), | ||
}.result, | ||
|
||
// Convert non-boolean types like string,number to a boolean. | ||
// This is primarily intended for dealing with parameters that should be booleans. | ||
toBool:: function(x) { | ||
result:: | ||
if std.type(x) == "boolean" then | ||
x | ||
else if std.type(x) == "string" then | ||
std.asciiUpper(x) == "TRUE" | ||
else if std.type(x) == "number" then | ||
x != 0 | ||
else | ||
false, | ||
}.result, | ||
|
||
// Convert a comma-delimited string to an Array | ||
toArray:: function(str) { | ||
local trim(str) = { | ||
rest:: | ||
if std.startsWith(str, " ") then | ||
std.substr(str, 1, std.length(str) - 1) | ||
else | ||
str, | ||
}.rest, | ||
result:: | ||
if std.type(str) == "string" && str != "null" && std.length(str) > 0 then | ||
std.map(trim, std.split(str, ",")) | ||
else [], | ||
}.result, | ||
|
||
foldl:: function(key, value, objs) { | ||
local aux(arr, i, running) = | ||
if i >= std.length(arr) then | ||
running | ||
else | ||
aux(arr, i + 1, running { [key(arr[i])]+: value(arr[i]) }) tailstrict, | ||
return:: aux(objs, 0, {},), | ||
}.return, | ||
|
||
sort:: function(arr, compare=function(a, b) { | ||
return:: | ||
if a == b then | ||
0 | ||
else if a < b then | ||
-1 | ||
else | ||
1, | ||
}.return) { | ||
local l = std.length(arr), | ||
local f = { | ||
local pivot = arr[0], | ||
local rest = std.makeArray(l - 1, function(i) arr[i + 1]), | ||
local left = std.filter(function(x) compare(x, pivot) <= 0, rest), | ||
local right = std.filter(function(x) compare(x, pivot) > 0, rest), | ||
return:: util.sort(left, compare) + [pivot] + util.sort(right, compare), | ||
}.return, | ||
return:: | ||
if std.length(arr) == 0 then | ||
[] | ||
else | ||
f, | ||
}.return, | ||
|
||
setDiff:: function(a, b, compare=function(a, b) { | ||
return:: | ||
if a == b then | ||
0 | ||
else if a < b then | ||
-1 | ||
else | ||
1, | ||
}.return) { | ||
local aux(a, b, i, j, acc) = | ||
if i >= std.length(a) then | ||
acc | ||
else if j >= std.length(b) then | ||
aux(a, b, i + 1, j, acc + [a[i]]) tailstrict | ||
else | ||
if compare(a[i], b[j]) == 0 then | ||
aux(a, b, i + 1, j + 1, acc) tailstrict | ||
else if compare(a[i], b[j]) == -1 then | ||
aux(a, b, i + 1, j, acc + [a[i]]) tailstrict | ||
else | ||
aux(a, b, i, j + 1, acc) tailstrict, | ||
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,), | ||
} |