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

Replacement inbetween #5616

Open
2 tasks done
Yingrjimsch opened this issue Mar 18, 2024 · 1 comment
Open
2 tasks done

Replacement inbetween #5616

Yingrjimsch opened this issue Mar 18, 2024 · 1 comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@Yingrjimsch
Copy link

Yingrjimsch commented Mar 18, 2024

Eschewed features

  • This issue is not requesting templating, unstuctured edits, build-time side-effects from args or env vars, or any other eschewed feature.

What would you like to have added?

To replace inbetween to substrings or chars would be very benificial. The replacement by delimiter with an index works pretty good but in some cases it is not enough because the part to replace is between two different chars.

Why is this needed?

If for example I want to replace the major version of nginx:1.7.9 to nginx:2.7.9 there is no right delimiter for me to use to achieve the task. We have this problem in multiple yaml replacements, where the delimiter replacement is not enough.

The following issue tries to achieve something similar: #4555
Another example is we have a URL: http://loki-backend.$(ENVIRONMENT)-myapp-observability.svc.cluster.local:3100$request_uri; where we want to replace dynamically the $(ENVIRONMENT) with sta, pre, pro or other environment abbreviations. For now it is not possible to replace this correctly because it is between the char . and the char -

Can you accomplish the motivating task without this feature, and if so, how?

For now the example cannot be solved because it is between the char . and the char -

What other solutions have you considered?

My suggested solution is to have an additional enddelimiter property in replacement.options which can specify the second char / substring for replacement purpose. This can be done in source and target to be consistent and would have no affect on the current functionallity and a minimal code change

replacements:
- source:
    kind: Deployment
    name: deploy2
    fieldPath: spec.template.spec.containers.0.image
    options:
      delimiter: ':'
  targets:
  - select:
      kind: Deployment
      name: deploy1
    fieldPaths:
    - spec.template.spec.containers.1.image
    options:
      delimiter: ':'
      enddelimiter: '.'

Anything else we should know?

I have created a branch on my fork with an implemented version, due to being new to golang I'm open for clean code or performance optimization suggestion. I also included two basic tests in the replacement_test.go which are called partial string replacement with enddelimiter in target - replace and partial string replacement with enddelimiter in source - replace

Feature ownership

  • I am interested in contributing this feature myself! 🎉
  • Issue is implemented on forked repo here
@Yingrjimsch Yingrjimsch added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 18, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

2 participants