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

YAML parsing of additional config doesn't allow for markdown new lines #161

Open
ybizeul opened this issue Aug 3, 2023 · 1 comment
Open
Labels
invalid This doesn't seem right more info More information required from the reporter

Comments

@ybizeul
Copy link

ybizeul commented Aug 3, 2023

I'm adding a ConfigMap to the namespace for DEFAULT_DASHBOARD declaration, it looks like this :

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |
    DEFAULT_DASHBOARD: [
      {
        'widget': 'extras.NoteWidget',
        'width': 3,
        'height': 2,
        'title': 'Shortcuts',
        'config': {
            'content':"**Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)  
    **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)  
    **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)"
        }
      },
    ]

Note that one line 15, I add two blank space " " which means "Got to next line" in markdown.

I think when python parses the yaml of the ConfigMap, it doesn't use the string as-is and does some funky stuff.

The only thing I managed to do was to add two blank line, but that creates a new markdown paragraph, instead of going to next line.

Note 1
Strictly using the dashboard UI in NetBox to create a note block and going to next line with the double space syntax does work correctly.

Note 2
If I strictly follow the example on NetBox documentation, is doesn't work at all as the parenthesis string literals in python don't play well with yaml :

    {
        'widget': 'extras.NoteWidget',
        'width': 4,
        'height': 2,
        'title': 'Welcome!',
        'color': 'green',
        'config': {
            'content': (
                'This is your personal dashboard. Feel free to customize it by rearranging, resizing, or removing '
                'widgets. You can also add new widgets using the "add widget" button below. Any changes affect only '
                '_your_ dashboard, so feel free to experiment!'
            )
        }
    },

Note 3
First thing I tried is using the | pipe yaml string literal to try and make a non escaped multi line paragraph :

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |
    DEFAULT_DASHBOARD: [
      {
        'widget': 'extras.NoteWidget',
        'width': 3,
        'height': 2,
        'title': 'Shortcuts',
        'config': {
            'content':|
              **Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)  
              **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)  
              **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)"
        }
      },
    ]

But it doesn't seem python yaml.safe_load() is interpreting this correctly and leads to exceptions in the logs :

in "/run/config/extra/..2023_08_03_21_07_49.1217131338/default-dashboard.yaml", line 8, column 19
@bootc
Copy link
Member

bootc commented Nov 4, 2023

Remember that the example you pointed at is actually Python code; your snippet should use valid YAML. The python code looks a little like JSON (which is valid YAML) but the quoting is wrong. I haven't actually tried this, but this is valid YAML at least:

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |-
    DEFAULT_DASHBOARD:
      - widget: extras.NoteWidget
        width: 3
        height: 2
        title: Shortcuts
        config:
          content: |-
            **Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)
            **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)
            **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)

Please give this a go, and if you continue to get exceptions please post the full stack trace.

@bootc bootc added invalid This doesn't seem right more info More information required from the reporter labels Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right more info More information required from the reporter
Projects
None yet
Development

No branches or pull requests

2 participants