-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🐛 add APIEndpoint IsValid() when both host and port are non-zero value #3541
🐛 add APIEndpoint IsValid() when both host and port are non-zero value #3541
Conversation
Hi @jzhoucliqr. 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/test-infra repository. |
/ok-to-test |
@@ -178,9 +178,9 @@ type APIEndpoint struct { | |||
Port int32 `json:"port"` | |||
} | |||
|
|||
// IsZero returns true if host and the port are zero values. | |||
// IsZero returns true if either the host or the port is zero value. | |||
func (v APIEndpoint) IsZero() bool { |
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.
hello, i don't think this change is appropriate, since it does a change in behavior.
the purpose of the function seems to be to check if the the endpoint is not set by the user.
side note, IsZero is a misleading name for a function that works on non-numerical types.
after this change the function name becomes more misleading.
Current Endpoint.IsZero() check will allow empty Host with non-empty Port to pass the check (vice versa). This will cause issue if Infra provider have partial endpoint information with either of them is empty. The specific case we saw is with CAPV when user need to manually configure endpoint for kube-vip based HA.
this seems like the responsibility of a different validation function that ensures that both fields are set.
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.
Agree that the name might be misleading. All the controllers (bootstrap/kcp) relies on this check to decide whether it should proceed or keep waiting. We could add a new function and change those controllers, then this one will be only used in conversion/validation. @ncdc
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.
Should we hold this until v0.4? Just to point out here as well (after our discussion on slack) the Host and Port field are required in open api validation, this is really an extra check.
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.
I don't 100% agree that IsZero
is misleading, as the zero value for a struct means all its fields have their default initialized (zero) values. This function is currently doing what I'd expect based on what a Go struct's zero value means.
However, I do agree this function may be misleading to the end user, who is probably calling it to check if the APIEndpoint has been set, and having it return false (i.e. it has been set) when the host is empty but the port is filled in seems wrong.
Let's maybe add a new function, something like IsComplete
, that returns true iff both host and port are nonzero?
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.
+1, I'd say we're going into semantic validation
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.
+1 for IsComplete
The open api validation doesn't seem to prevent this case, since both default to zero values and a patch with only port is accepted by the apiserver.
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.
Let's use IsValid
which is consistent with other parts of the codebase. And yeah, upon further validation the fields are required, but nothing stops an empty string (we should fix this in v1alpha4)
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.
With the current changes are there any remaining uses of IsZero? If not, we should likely mark the method as deprecated.
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's used in conversion.go, to decide whether apiendpoint is set.
…hange controllers to use IsValid
b5d1880
to
fffcfed
Compare
/lgtm |
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.
/approve
/milestone v0.3.9
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vincepri 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 |
/test pull-cluster-api-test |
/retest |
What this PR does / why we need it:
Current Endpoint.IsZero() check will allow empty Host with non-empty Port to pass the check (vice versa). This will cause issue if Infra provider have partial endpoint information with either of them is empty. The specific case we saw is with CAPV when user need to manually configure endpoint for kube-vip based HA.
Add IsValid() when both host and port are non-zero. Change controllers to use IsValid() to decide whether to proceed or keep waiting.