-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready #4996
Conversation
Signed-off-by: Mikael Johansson <[email protected]>
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 Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
source/f5_virtualserver.go
Outdated
@@ -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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here: d5c7f23
This PR looks good, thanks. I have not a strong opinion about the log level, it's just a suggestion. |
Signed-off-by: Mikael Johansson <[email protected]>
/retitle fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready |
source/f5_virtualserver.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
source/f5_virtualserver.go
Outdated
normalizedStatus := strings.ToLower(vs.Status.Status) | ||
normalizedAddress := strings.ToLower(vs.Status.VSAddress) | ||
|
||
return normalizedStatus == "ok" && (normalizedAddress != "none" && normalizedAddress != "") |
There was a problem hiding this comment.
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 != ""
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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. |
@ivankatliarchuk Btw, do you want me to rebase and squash the commits? Not sure what the usual workflow is! |
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? |
It can be configured with labels, see tide/merge-method-squash. thanks for this review @ivankatliarchuk 👍 /label tide/merge-method-squash |
[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 |
…r when TSServer is not ready
… when TSServer is not ready
Description
Due to changes in logic in the controller that operates on
VirtualServer
objects theVirtualServer
external-dnsSource
needs to determine if theVirtualServer
object is ready or not. This PR adds a check to determine if theVirtualServer
is ready and if not skips endpoint creation for that particular object.Checklist