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

Question on replacing value(s) single and multiple occurrences #23

Closed
ghost opened this issue Oct 31, 2020 · 9 comments
Closed

Question on replacing value(s) single and multiple occurrences #23

ghost opened this issue Oct 31, 2020 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Oct 31, 2020

Hello,

I was pointed out by someone that this tool was better to replace (multiple) values in a yaml file than using sed. I have tried some examples, but it is not clear to me how to replace certain values in https://raw.githubusercontent.com/c4po/harbor_exporter/master/kubernetes/harbor-exporter.yaml

I need to replace multiple occurrences in this file, however, I am only able to select 1. How do I add a line with the namespace value?

metadata:
  name: harbor-exporter

to

metadata:
  name: harbor-exporter
  namespace: test

Next to this, I also need to replace the value of "- harbor #......" to test and keep the remaining lines and this is failing with dasel put string -f he.yaml -s "spec.namespaceSelector.matchNames" "test"

  namespaceSelector:
    matchNames:
    - harbor # change to the namespace where you deployed Harbor

Thanks!

@TomWright
Copy link
Owner

Thanks for your interest in dasel!

After taking a look at your example file I can tell you that dasel doesn't currently support multiple yaml documents in the same file due to limitations in the yaml package we use: https://github.com/go-yaml/yaml#compatibility

If this is a recurring issue I'll look at migrating to a new yaml package.

If we assume you have split the documents out into service.yaml, deployment.yaml and servicemon.yaml then...

How do I add a line with the namespace value?

dasel put string -f service.yaml '.metadata.namespace' 'test'
dasel put string -f deployment.yaml '.metadata.namespace' 'test'
dasel put string -f servicemon.yaml '.metadata.namespace' 'test'

Change the namespaceSelector
Your example hasn't worked because matchNames is actually a list of strings.

dasel put string -f servicemon.yaml '.spec.namespaceSelector.matchNames[0]' 'test'

Notes
It's still very early on for dasel and there's going to be cases (much like this) that aren't ideal. I'm working hard to document all of these cases and working to create the best solution.

This does highlight the potential use of multiple files/multiple documents.

@TomWright TomWright self-assigned this Oct 31, 2020
@TomWright TomWright added the question Further information is requested label Oct 31, 2020
@ghost
Copy link
Author

ghost commented Oct 31, 2020

Thanks, in the Kubernetes world a lot of files contains multiple yaml documents, so one command to change every occurence of something is very welcome!

@TomWright
Copy link
Owner

Hi @ws-way,
Multi-document YAML files are now supported as of v1.2.0.

@ghost
Copy link
Author

ghost commented Nov 7, 2020

Hi @TomWright ,

Thanks for adding this, I have read the readme.md and tested it, but it is unclear how I can change all values in an yaml file without knowing how much yaml documents are in there. Do you have an example?

@TomWright
Copy link
Owner

Dasel is really only designed for use-cases where you know the structure of the files.

This sounds like you're after a search + multi-selector feature.

A feature request for multi-selector is here: #15

I have thought about adding search functionality but haven't created a feature request for it yet.

@ghost
Copy link
Author

ghost commented Nov 8, 2020

Hello @TomWright ,

Ok, thanks for the answer!

@TomWright
Copy link
Owner

As of v1.4.0 multi-select is supported.

The following will set the metadata name in all yaml documents to test:

dasel put string -m -f harbor-exporter.yaml '.[*].metadata.name' 'test'

@ghost
Copy link
Author

ghost commented Nov 10, 2020

Hi @TomWright ,

Thanks, I will take a look at this later this week or next week.

@ghost
Copy link
Author

ghost commented Nov 11, 2020

Hello @TomWright ,

The multiline replace is working fine, thanks.

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

No branches or pull requests

1 participant