Giter Site home page Giter Site logo

Comments (20)

 avatar commented on May 12, 2024 1

Thanks!

from dasel.

TomWright avatar TomWright commented on May 12, 2024

Are you referring to the JSON content within node.longhorn.io/default-disks-config?

On another note, please use 3 backticks for code highlighting instead of 1. That way new lines etc are displayed properly.

from dasel.

 avatar commented on May 12, 2024

Thanks, I would to create the complete data structure from scratch

from dasel.

TomWright avatar TomWright commented on May 12, 2024

You can use dasel put string with a blank input to create new documents.

E.g.

echo '' | dasel put string -p yaml some.path.here value
some:
  path:
    here: value

You can then pipe that output into another dasel command:

echo '' | dasel put string -p yaml 'some.path.here' value | dasel put string -p yaml 'some.path.too' value2
some:
  path:
    here: value
    too: value2

I just made a release that will allow you to use . in the property name by escaping it. Download dasel v1.5.0 and then the following should work:

echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config

If you want to save this file just add > myfile.yaml at the end of the command.

I've just ran this locally with v1.5.0:

echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config
metadata:
  annotations:
    node.longhorn.io/create-default-disk: config
    node.longhorn.io/default-disks-config: '[ { "name":"fast",  "path":"/mnt/data-fast1",
      "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1",
      "allowScheduling":true, "tags":["slow"]} ]'

from dasel.

 avatar commented on May 12, 2024

Hi @TomWright,

Thanks, looking good. One question, this part:

            "    node.longhorn.io/default-disks-config: '[ { \"name\":\"fast\",  \"path\":\"/mnt/data-fast1\", \"allowScheduling\":true, \"tags\":[\"fast\"]}, { \"name\":\"slow\",  \"path\":\"/mnt/data-slow1\", \"allowScheduling\":true, \"tags\":[\"slow\"]} ]'" \

Is it possible to create this as an array? As far as I understand it, this part is an array and I do need 1 to x entries in this part, depending on the number of disks.

Thanks!

from dasel.

TomWright avatar TomWright commented on May 12, 2024

Just append [] to the selector you want to be an array.
https://github.com/TomWright/dasel#next-available-index

from dasel.

 avatar commented on May 12, 2024

Hi @TomWright ,

Thanks, I really appreciate the help you are giving, could you give me an example how to create this with an array?

metadata:
  annotations:
    node.longhorn.io/create-default-disk: config
    node.longhorn.io/default-disks-config: '[ { "name":"fast",  "path":"/mnt/data-fast1",
      "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1",
      "allowScheduling":true, "tags":["slow"]} ]'

The part of the disks-config is what I am looking for.

Thanks again

from dasel.

TomWright avatar TomWright commented on May 12, 2024

Those values are in a JSON string. Do you want them as JSON or as YAML?

from dasel.

 avatar commented on May 12, 2024

Hi @TomWright ,

That should be JSON, thanks.

from dasel.

TomWright avatar TomWright commented on May 12, 2024
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config.[]' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config

from dasel.

 avatar commented on May 12, 2024

Hi @TomWright ,

Could you please take a look at this again?

I am trying to use your example, but it is different from my example. In your example config (last line) is also on metadata.annotation, but in my question it is on metadata.labels. When I replace the word annotation with labels it is not working, also not when I am splitting it into 2 commands.

This is not giving the line with the labels:

echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' config

Also splitting it into 2 parts doesn't work:

longhorn_disk_annotation=$(echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]')
result=$(echo "$longhorn_disk_annotation" | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' config)

How can I get this working?

from dasel.

TomWright avatar TomWright commented on May 12, 2024

What is the final output you want to see?

from dasel.

 avatar commented on May 12, 2024

This :-)

metadata:
  annotations:
    node.longhorn.io/default-disks-config: '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]'
  labels:
    node.longhorn.io/create-default-disk: config

from dasel.

 avatar commented on May 12, 2024

Hello @TomWright,

I have tried it with variables and with files, the second put string is not working. Is this a bug or am I doing something wrong?

from dasel.

TomWright avatar TomWright commented on May 12, 2024

I'll take a look at this today and get back to you

from dasel.

 avatar commented on May 12, 2024

Great, thanks!

from dasel.

TomWright avatar TomWright commented on May 12, 2024

Hey @ws-way, this looks like a bug.

I'm debugging it now and will release a fix ASAP. Thanks for your patience 👍

from dasel.

 avatar commented on May 12, 2024

Ok, thanks, good luck with the fix

from dasel.

TomWright avatar TomWright commented on May 12, 2024

OK the issue is fixed as of v1.5.1.

echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast",  "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' 'config'

Output is:

metadata:
  annotations:
    node.longhorn.io/default-disks-config: '[ { "name":"fast",  "path":"/mnt/data-fast1",
      "allowScheduling":true, "tags":["fast"]}, { "name":"slow",  "path":"/mnt/data-slow1",
      "allowScheduling":true, "tags":["slow"]} ]'
  labels:
    node.longhorn.io/create-default-disk: config

from dasel.

 avatar commented on May 12, 2024

Looks it is working, thanks again!

from dasel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.