Skip to content

Component Names Collide with Jsonnet Libraries #274

@srueg

Description

@srueg

If a component has the same name as a Jsonnet library which is included (by any other component), the paths in vendor/ collide and therefore either the component is not included correctly, or the Jsonnet library can't be used with a relative import. Since kube-prometheus uses relative imports everywhere, it will break if we have a component named grafana.
Jsonnet-bundler just print a warning and skips the colliding symlink:

WARN: cannot link 'github.com/brancz/kubernetes-grafana/grafana' to '/app/data/vendor/grafana', because package '../dependencies/grafana' already uses that name. The absolute import still works

Steps to Reproduce the Problem

  1. Create a component called component-grafana
  2. Compile a cluster which installs a component with a dependency on kube-prometheus (i.e. synsights-metrics)

Actual Behavior

Compilation fails:

Jsonnet error: failed to compile /app/data/vendor/spks-monitoring/component/main.jsonnet:
 RUNTIME ERROR: couldn't open import "grafana/grafana.libsonnet": [Errno 2] No such file or directory: '/app/data/vendor/kube-prometheus/grafana/grafana.libsonnet'
	/app/data/vendor/kube-prometheus/kube-prometheus.libsonnet:5:2-36	thunk <import>
	/app/data/vendor/spks-monitoring/component/rules.libsonnet:62:4-54	thunk <kp>
	/app/data/vendor/spks-monitoring/component/rules.libsonnet:88:31-33	object <anonymous>
	During manifestation

Expected Behavior

The compilation is successful.

Ideas

  1. Forbid using component names which collide with library names.
    Leads to bad UX and might break in the future if new libraries are included.
  2. Prefix all components in vendor/ with component-.
    Would require to change the compile input_paths of all components. We could introduce a helper variable like parameters._component (analog to `_instance) to make it easier.
    Benefit: the names would match the actual git repo names.
  3. Always use absolute imports in Jsonnet.
    Might not be possible to control in upstream projects (i.e. kube-prometheus).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions