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

fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready #4996

Merged

Conversation

mikejoh
Copy link
Contributor

@mikejoh mikejoh commented Jan 8, 2025

Description

Due to changes in logic in the controller that operates on VirtualServer objects the VirtualServer external-dns Source needs to determine if the VirtualServer object is ready or not. This PR adds a check to determine if the VirtualServer is ready and if not skips endpoint creation for that particular object.

Checklist

  • Unit tests updated
  • End user documentation updated (not needed AFAICT)

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 8, 2025
@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 Jan 8, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @mikejoh. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 8, 2025
@mikejoh mikejoh changed the title Skip endpoint creation if VirtualServer is not considered ready fix(source/f5_virtualserver): skip endpoint creation if VirtualServer is not considered ready Jan 8, 2025
@mikejoh mikejoh marked this pull request as ready for review January 10, 2025 12:36
@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 Jan 10, 2025
@mikejoh mikejoh mentioned this pull request Jan 10, 2025
2 tasks
@mloiseleur
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 Jan 10, 2025
@@ -147,6 +148,12 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f
var endpoints []*endpoint.Endpoint

for _, virtualServer := range virtualServers {
if !isVirtualServerReady(virtualServer) {
log.Infof("F5 VirtualServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Infof("F5 VirtualServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.",
log.Warnf("F5 VirtualServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.",

Shouldn't it be a warning ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could definitely be a warning instead, i'll change it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: d5c7f23

@mloiseleur
Copy link
Contributor

This PR looks good, thanks. I have not a strong opinion about the log level, it's just a suggestion.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2025
Signed-off-by: Mikael Johansson <[email protected]>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2025
@mloiseleur
Copy link
Contributor

/retitle fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready

@k8s-ci-robot k8s-ci-robot changed the title fix(source/f5_virtualserver): skip endpoint creation if VirtualServer is not considered ready fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready Jan 10, 2025
@@ -211,3 +219,10 @@ func (vs *f5VirtualServerSource) filterByAnnotations(virtualServers []*f5.Virtua

return filteredList, nil
}

func isVirtualServerReady(vs *f5.VirtualServer) bool {
normalizedStatus := strings.ToLower(vs.Status.Status)
Copy link
Contributor

Choose a reason for hiding this comment

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

potential null pointer as vs is a reference

The null check will help to avoid external-dns crashlooping.

Ideally the null check should be added in method

func (vs *f5VirtualServerSource) endpointsFromVirtualServers
...

for _, virtualServer := range virtualServers {
   if virtualServer == nil {
            continue
        }

Copy link
Contributor Author

@mikejoh mikejoh Jan 11, 2025

Choose a reason for hiding this comment

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

Good catch but AFAICT the vs pointer here are explicitly set earlier and appended to the slice of vs pointer (before passed to the endpointsFromVirtualServers method), this would effectively mitigate any risk of encountering a nil pointer.

Copy link
Contributor

@ivankatliarchuk ivankatliarchuk Jan 11, 2025

Choose a reason for hiding this comment

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

Hi

Looks like missed that piece ;-) If server is empty and created like that, then you right.

virtualServer := &f5.VirtualServer{}

If the virtual server created like the one above, is there is is a chance to throw a null pointer panic in helper function isVirtualServerReady, as vs.Status is not set?

vs.Status.Status 
vs.Status.VSAddress

Am I correct or missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for all the review comments, super helpful! 🙏🏻

The status field of the VirtualServer object is defined as a non-pointer: https://github.com/F5Networks/k8s-bigip-ctlr/blob/508f686bf2886a4f95af0f3a822e6ed25bce2ec7/config/apis/cis/v1/types.go#L19. AFAICT this means that in this context, the fields of the VirtualServerStatus struct, will be set to their respective zero values if not explicitly initialized!

normalizedStatus := strings.ToLower(vs.Status.Status)
normalizedAddress := strings.ToLower(vs.Status.VSAddress)

return normalizedStatus == "ok" && (normalizedAddress != "none" && normalizedAddress != "")
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk Jan 10, 2025

Choose a reason for hiding this comment

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

Just a suggestion to use early return, example

if strings.ToLower(vs.Status.Status) != "ok" {
		return false
	}

normalizedAddress := strings.ToLower(vs.Status.VSAddress)
return normalizedAddress != "none" && normalizedAddress != ""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, changed here: a70d5d0

@@ -147,6 +148,12 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f
var endpoints []*endpoint.Endpoint

for _, virtualServer := range virtualServers {
if !isVirtualServerReady(virtualServer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just a suggestion

if !virtualServer.isReady()

^ This will crash if virtualServer is null))

Copy link
Contributor Author

@mikejoh mikejoh Jan 11, 2025

Choose a reason for hiding this comment

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

Totally understand this but we would need to embed the f5.VirtualServer struct in our own data type and then add a method to that, in this context it feels a bit overkill? A helper func (as used now) that operates on a *f5.VirtualServer feels like a good middle ground.

Copy link
Contributor

Choose a reason for hiding this comment

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

it was simply a style suggestion, nice one.

@k8s-ci-robot
Copy link
Contributor

@ivankatliarchuk: changing LGTM is restricted to collaborators

In response to this:

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.

@mikejoh
Copy link
Contributor Author

mikejoh commented Jan 12, 2025

@ivankatliarchuk Btw, do you want me to rebase and squash the commits? Not sure what the usual workflow is!

@ivankatliarchuk
Copy link
Contributor

You could try asking a bot to squash commits https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#squashing. Not sure if it's mandatory.

As this branch has no conflicts with master rebase is most likely optional.

👋 @mloiseleur am I correct?

@mloiseleur
Copy link
Contributor

It can be configured with labels, see tide/merge-method-squash.

thanks for this review @ivankatliarchuk 👍

/label tide/merge-method-squash
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jan 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivankatliarchuk, mloiseleur

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 13, 2025
@k8s-ci-robot k8s-ci-robot merged commit 9368a24 into kubernetes-sigs:master Jan 13, 2025
14 checks passed
visokoo added a commit to visokoo/external-dns that referenced this pull request Jan 21, 2025
visokoo added a commit to visokoo/external-dns that referenced this pull request Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants