external-dns icon indicating copy to clipboard operation
external-dns copied to clipboard

feat: additional template functions

Open matkam opened this issue 2 years ago • 26 comments

Description

Adds a few useful text/template functions:

  • replaceAll: strings.replaceAll
  • isIPv6: exposes an existing function that returns a bool to let you know if a string is an IPv6 address
  • isIPv4: a new function that returns a bool to let you know if a string is an IPv4 address

N/A

Checklist

  • [x] Unit tests updated
  • [x] End user documentation updated

matkam avatar Sep 21 '23 20:09 matkam

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: matkam / name: Mathew Kamkar (6b0d792a19bc0934a83cd9367a344e7c9aabdc64, a5f3a17603fa4caba6da44c5ed9144181f533556, 68be9bda50747f39ea4052bd5ec264b5de5164b7, b0f3beb89992bf0d7bc127ad87dad912453eb92d, b610c94a5c0925ef49c37370e0faa819a7f4850e, 42f79f82501bd40a424db1550fd1aa7a491cbbdd, 88bfa6083f86225d6991adeacff1f5bf6ad9bc8f, 267cb1f1b612be2a641d915ab675c0f1e588ce78)

Welcome @matkam!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

k8s-ci-robot avatar Sep 21 '23 20:09 k8s-ci-robot

Hi @matkam. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 avatar Sep 21 '23 20:09 k8s-ci-robot

Please submit a CLA per the instructions above.

johngmyers avatar Sep 22 '23 00:09 johngmyers

Please submit a CLA per the instructions above.

Yes 👍 I'm just waiting on my employer to click the button.

matkam avatar Sep 22 '23 03:09 matkam

@johngmyers we are good to go here 👍

matkam avatar Sep 26 '23 23:09 matkam

Sprig has replace, which is similar. Perhaps we should follow their syntax?

johngmyers avatar Sep 27 '23 00:09 johngmyers

/ok-to-test

johngmyers avatar Sep 27 '23 00:09 johngmyers

Sprig has replace, which is similar. Perhaps we should follow their syntax?

does replace work differently? I could also add strings.replace to the FuncMap.

matkam avatar Sep 27 '23 00:09 matkam

I believe replace has the arguments in a different order. See the documentation in https://masterminds.github.io/sprig/strings.html

johngmyers avatar Sep 27 '23 00:09 johngmyers

I believe replace has the arguments in a different order. See the documentation in https://masterminds.github.io/sprig/strings.html

sprig looks like a nice package. how about just importing it and using hermeticTxtFuncMap like this:

func parseTemplate(fqdnTemplate string) (tmpl *template.Template, err error) {
	if fqdnTemplate == "" {
		return nil, nil
	}
	
	funcs := sprig.HermeticTxtFuncMap()
	funcs["isIPv6"] = isIPv6String
	funcs["isIPv4"] = isIPv4String

	return template.New("endpoint").Funcs(funcs).Parse(fqdnTemplate)
}

matkam avatar Sep 27 '23 04:09 matkam

@johngmyers let me know what you think. I've updated the template functions to include Sprig's hermetic text functions, and fixed the isIPv4String function so that it only returns true for valid IPv4 strings.

matkam avatar Oct 27 '23 01:10 matkam

@matkam Wdyt about adding isIPv4 and isIPv6 directly into slim-sprig ?

mloiseleur avatar Nov 09 '23 08:11 mloiseleur

@mloiseleur https://github.com/go-task/slim-sprig/pull/16

matkam avatar Nov 11 '23 08:11 matkam

/hold for https://github.com/go-task/slim-sprig/pull/16

mloiseleur avatar Nov 11 '23 10:11 mloiseleur

@matkam: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-external-dns-lint c16c17556b32a6fe4d85960df82eeca6257af939 link true /test pull-external-dns-lint

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

k8s-ci-robot avatar Jan 03 '24 18:01 k8s-ci-robot

@matkam Since slim-sprig maintainer does not review your PR, I think we can merge this one. Do you think you can rebase this PR ? And precise in documentation those additional functions of isIPv4 and isIPv6 ?

mloiseleur avatar Feb 11 '24 10:02 mloiseleur

@mloiseleur done!

matkam avatar Feb 12 '24 18:02 matkam

/lgtm

mloiseleur avatar Feb 13 '24 07:02 mloiseleur

@mloiseleur whats the next step required to get this merged?

matkam avatar Feb 20 '24 23:02 matkam

A review from @szuecs or @Raffo They will review this PR when they have time.

mloiseleur avatar Feb 21 '24 07:02 mloiseleur

/unhold

mloiseleur avatar Mar 12 '24 16:03 mloiseleur

/retitle feat: additional template functions

mloiseleur avatar Mar 12 '24 16:03 mloiseleur

Hello, I would like to see this merged and released. What needs to be done?

simonostendorf avatar May 22 '24 06:05 simonostendorf

New changes are detected. LGTM label has been removed.

k8s-ci-robot avatar May 29 '24 19:05 k8s-ci-robot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from mloiseleur. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar May 29 '24 19:05 k8s-ci-robot