Skip to content
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

Follow conventions when creating objects #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

redbaron
Copy link

It seems that shape of the object produced by individual
jsonnet library set to be following:

{
  hidden:: { ... }

  component: {
    resource1: { apiVersion: ... , kind: .... },
    resource2: { apiVersion: ... , kind: .... },
  }
}

so that std.objectFields(obj) returns an object
made of kubernetes object to apply.

Hidden fields are then can be used for cooperation
on values, such as _config::

This commit brings produced output in line with convention above

@redbaron redbaron force-pushed the dashboard-definitions-list branch 2 times, most recently from 46d46f0 to a145d2a Compare May 22, 2019 20:04
It seems that shape of the object produced by individual
jsonnet library agreed to be following:

```
{
  hidden:: { ... }

  component: {
    resource1: { apiVersion: ... , kind: .... },
    resource2: { apiVersion: ... , kind: .... },
  }
}
```

so that std.objectFields(obj) returns an object
made of kubernetes object to apply.

Hidden fields are then can be used for cooperation
on values, such as `_config::`

This commit brings produced output in line with convention above
@redbaron redbaron force-pushed the dashboard-definitions-list branch from a145d2a to ba95ada Compare May 22, 2019 20:13
@redbaron
Copy link
Author

redbaron commented May 23, 2019

hm, is Travis CI webhook stuck?

If there is no dashboards, then no /grafana-dashboard-definitions/0/
is created and Grafana becomes upset, because it's provisioning
config points there.
@redbaron redbaron force-pushed the dashboard-definitions-list branch from b60dbbe to 138c136 Compare May 23, 2019 10:34
[
grafana.dashboardDefinitions,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time I checked lists couldn't be nested, which is why we did what we did. Has this changed recently?

@redbaron
Copy link
Author

redbaron commented May 28, 2019 via email

local dashboardName = 'grafana-dashboard-' + std.strReplace(name, '.json', '');
configMap.new(dashboardName, { [name]: std.manifestJsonEx($._config.grafana.dashboards[name], ' ') }) +
configMap.mixin.metadata.withNamespace($._config.namespace)
configMapList.new(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see here, it used to be a [], but now a single { kind: ConfigmapList, items: [] } object, it allows embedding it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but when you render out a kind: List, does kubectl actually create deep lists recursively?

Copy link
Author

@redbaron redbaron May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem so. See same transformation in kube-prometheus:

https://github.com/coreos/kube-prometheus/blob/3fbc968930c2fef025470c59060d25635070f8e7/jsonnet/kube-prometheus/kube-prometheus.libsonnet#L18

kubectl seems to flatten kind: List items, at least one level deep for sure. here we are exactly one level deep, so should be fine

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only works because what is generated is not a List object but a directory of objects, where one of the files happens to be a ConfigMapList, so for kubectl the ConfigMapList is actually the top level item.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me run few tests, I'll come back to you

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct :)

Copy link
Author

@redbaron redbaron May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"library" object should still have "standard" shape:

{ key: { kind: ... } }

to make it easier to use it in other jsonnet deployments.

it is only examples which need to change. I can go with

local grafana =
  ((import 'grafana/grafana.libsonnet') + .... ).grafana;

local flatten(lst) = std.foldl(function(acc, r) if ! std.endsWith(r.kind, "List") then acc + [r] else acc + r.items, lst, []);

k.core.v1.list.new(flatten([grafana[k] for k in grafana]))

what do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I quite like that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach would be to return plain array and change exampes to call jsonnet --yaml-stream.

Either way output is pipeable into kubectl . Which one do you prefer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the first, as that way when people want to they can still make use of the *List types for grouping, in the way I think it's good that the dashboard configmaps are currently grouped that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants