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

Reference Substrings in Apply Time Mutations #3966

Open
tylerreidwaze opened this issue May 16, 2023 · 3 comments
Open

Reference Substrings in Apply Time Mutations #3966

tylerreidwaze opened this issue May 16, 2023 · 3 comments
Labels
area/live enhancement New feature or request

Comments

@tylerreidwaze
Copy link

Describe your problem

I am trying to create a Memcached Instance and a DNS Entry for that instance in a single package

I'm trying to use apply-time-mutation which will get the discoveryEndpoint of the memcached and create a DNS record for it in DNS.

The problem is the result includes the port:

kubectl get MemcacheInstance memcached-kpt-test -o jsonpath='{.status.discoveryEndpoint}'
10.19.208.3:11211

And I can't find a way to split it as jsonPath doesnt let me index strings (strings aren't arrays I suppose?)

> kubectl get MemcacheInstance memcached-kpt-test -o jsonpath='{.status.discoveryEndpoint[0:-6]}' -n waze-platform-codelabs
error: error executing jsonpath "{.status.discoveryEndpoint[0:-6]}": Error executing template: string is not array or slice. Printing more information for debugging the template:
	template was:
		{.status.discoveryEndpoint[0:-6]}

The whole object we tried as reference

metadata:
  name: memcached-kpt-test
  annotations:
    config.kubernetes.io/apply-time-mutation: |
      - sourceRef:
          kind: MemcacheInstance
          name: memcached-kpt-test
        sourcePath: $.status.discoveryEndpoint[0:10]
        targetPath: $.spec.rrdatas.value
        token: ${memcache-discovery-ip}
spec:
  name: "memcached-kpt-test.dretest."
  type: "A"
  ttl: 60
  managedZoneRef:
    external: dretest
  rrdatas:
  - "${memcache-discovery-ip}"

This is not a massive blocker for us as Apply Time Mutations aren't supported yet in Config Sync which is the eventual consumer of this output.

Let us know if you need more information or want us to test something out. Or, if there is a more kpt native way to do this.

Thanks in advance!

@tylerreidwaze tylerreidwaze added the enhancement New feature or request label May 16, 2023
@github-project-automation github-project-automation bot moved this to Backlog in kpt May 16, 2023
@droot
Copy link
Contributor

droot commented May 17, 2023

/cc @karlkfi since he has expertise in this area.

@karlkfi
Copy link
Contributor

karlkfi commented May 17, 2023

Sounds like it’s working as intended. The error message is even pretty clear. ;)

I don’t think there’s really any way to do what you’re trying to do with the current design.

Ironically, I initially proposed yq as a parser, which would have allowed this. The jsonPath code can’t easily be modified to add this kind of thing.

We could hypothetically add another field to describe how to process the value, but it’d probably need to support more than just substring operations by index. Regex might work.

pattern: “(.+):\d+”
value: “\1”

@tylerreidwaze
Copy link
Author

Regex by pattern would work for us. Anyway to extract some of the value instead of all of it really

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/live enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants