New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util.libsonnet has methods that allow a <component>.part to be modified #1395
Conversation
/assign @jlewi |
/cc @ankushagarwal |
/lgtm |
/lgtm |
/retest |
See comment here: It looks like the pattern you are suggesting is to have parts define a list and then convert that to a map so you can modify an element by name. That's a useful function. But why wouldn't we just rewrite the libsonnet file to be a map? e.g suppose the libsonnet file looked like
Then I think in the .jsonnet file you could do something like
|
kubeflow/core/util.libsonnet
Outdated
toList:: [$[key] for key in std.objectFields($)], | ||
|
||
// Convert an array of kubernetes resources into a map[kind/name, resource] | ||
toMap:: function(params) { |
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.
Why is toMap taking params as an argument?
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.
I believe I understand. Does the following make sense?
- Remove params from toMap (prometheus.libsonnet is an example where parts is a map and all is parts)
- Build the map first, then the parts which reference the map eg: [map.values()]
Question: What about repeating resources within a libsonnet? For example jupyterhub.libsonnet has 2 Services, 2 ServiceAccounts, 2 Roles, 2 RoleBindings. Should we deal with it only if needed? For example:
local jup = {
Service: {
"tf-hub-0": {foo:"bar",},
"tf-hub-lb": {bar:"baz",},
},
};
so the update would look like
jup + {
Service+: {
"tf-hub-0"+: {one: "two",},
},
}
yielding
{
"Service": {
"tf-hub-0": {
"foo": "bar",
"one": "two"
},
"tf-hub-lb": {
"bar": "baz"
}
}
}
for non-repeating resources it would look like your example with StatefulSet or would that be too confusing?
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.
I don't think the top level items in the dictionary should be based on type. They should be based on what they do; e.g. if there are multiple services each service should be its own item.
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.
so how bout
{
ConfigMap::
HubService::
HubServiceAccount::
HubRole::
HubRoleBinding::
NotebookService::
NotebookServiceAccount::
NotebookRole::
NotebookRoleBinding::
StatefulSet::
}
where the map is a set of functional hidden names. The one above would be jupyterhub.
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.
parts (or all) would be in the top level mapping
{
ConfigMap::
HubService::
HubServiceAccount::
HubRole::
HubRoleBinding::
NotebookService::
NotebookServiceAccount::
NotebookRole::
NotebookRoleBinding::
StatefulSet::
parts|all:: [ ConfigMap:: HubService:: ... ]
}
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.
LGTM
This now works
I can update the other libsonnets if this looks ok. Note that params is now referenced as $.params within the resources. |
kubeflow/core/jupyterhub.libsonnet
Outdated
if key != "list" && key != "params" && key != "all" | ||
], | ||
|
||
ConfigMap:: { |
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.
nit: Change the name and StatefulSet name to be more descriptive
e.g
ConfigMap -> KubeSpawnerConfig
StatefulSet -> HubStatefulSet
Looks great to me. I had one nit about the names but otherwise this is ready IMO. |
thanks @jlewi |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ankushagarwal, jlewi The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…ed (kubeflow#1395) * initial checkin on generalized way of editing component parts * added add, modify, remove examples * kubeflow/core/util.libsonnet holds new methods to update <component>.parts * added testing * fix fmt error for kubeflow/core/util.jsonnet * /retest * /retest * /retest * /retest * /retest * /retest
Fixes #1231
After
kfctl.sh generate k8s
the user would update components/jupterhub.jsonnetThis change is