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

feat: additional template functions #3949

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

matkam
Copy link

@matkam matkam commented Sep 21, 2023

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

  • Unit tests updated
  • End user documentation updated

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 21, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 21, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Sep 21, 2023
@k8s-ci-robot
Copy link
Contributor

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. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 21, 2023
@k8s-ci-robot
Copy link
Contributor

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 k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 21, 2023
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 21, 2023
@matkam matkam changed the title [WIP] Additional template functions Additional template functions Sep 22, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 22, 2023
@johngmyers
Copy link
Contributor

Please submit a CLA per the instructions above.

@matkam
Copy link
Author

matkam commented Sep 22, 2023

Please submit a CLA per the instructions above.

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 26, 2023
@matkam
Copy link
Author

matkam commented Sep 26, 2023

@johngmyers we are good to go here 👍

source/source.go Outdated

func isIPv4String(input string) bool {
netIP := net.ParseIP(input)
return netIP != nil && netIP.To4() != nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function intended to return true for IPv4-mapped IPv6 addresses?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just returns true when the input string is an IPv4 address. It'll return false if its IPv6 or otherwise invalid IP address.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like this?

func isIPv4String(input string) bool {
	netIP := net.ParseIP(input)
	return netIP != nil && netIP.To4() != nil && !strings.Contains(input, ":")
}

@johngmyers
Copy link
Contributor

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

@johngmyers
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 27, 2023
@matkam
Copy link
Author

matkam commented Sep 27, 2023

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.

@johngmyers
Copy link
Contributor

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

@matkam
Copy link
Author

matkam commented Sep 27, 2023

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 matkam requested a review from johngmyers October 9, 2023 23:18
@matkam
Copy link
Author

matkam commented Oct 27, 2023

@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.

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jan 3, 2024

@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 c16c175 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.

@mloiseleur
Copy link
Contributor

@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 ?

@matkam
Copy link
Author

matkam commented Feb 12, 2024

@mloiseleur done!

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2024
@mloiseleur
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 13, 2024
@matkam
Copy link
Author

matkam commented Feb 20, 2024

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

@mloiseleur
Copy link
Contributor

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

@mloiseleur
Copy link
Contributor

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 12, 2024
@mloiseleur
Copy link
Contributor

/retitle feat: additional template functions

@k8s-ci-robot k8s-ci-robot changed the title Additional template functions feat: additional template functions Mar 12, 2024
@simonostendorf
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 29, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 29, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot
Copy link
Contributor

[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 k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 29, 2024
@@ -29,6 +29,7 @@ import (
"time"
"unicode"

sprig "github.com/go-task/slim-sprig"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no import for a single func.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants