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

🐛 add APIEndpoint IsValid() when both host and port are non-zero value #3541

Merged

Conversation

jzhoucliqr
Copy link
Contributor

@jzhoucliqr jzhoucliqr commented Aug 27, 2020

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 27, 2020
@k8s-ci-robot
Copy link
Contributor

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 /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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 27, 2020
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 27, 2020
@ncdc
Copy link
Contributor

ncdc commented Aug 27, 2020

/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 Aug 27, 2020
@@ -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 {
Copy link
Member

@neolit123 neolit123 Aug 27, 2020

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member

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

Copy link
Contributor Author

@jzhoucliqr jzhoucliqr Aug 27, 2020

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.

Copy link
Member

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)

Copy link
Member

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.

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's used in conversion.go, to decide whether apiendpoint is set.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 27, 2020
@jzhoucliqr jzhoucliqr changed the title 🐛 controlplane endpoint IsZero if either the host or port is zero value 🐛 add APIEndpoint IsValid() check when both host and port are non-zero value Aug 27, 2020
@jzhoucliqr jzhoucliqr changed the title 🐛 add APIEndpoint IsValid() check when both host and port are non-zero value 🐛 add APIEndpoint IsValid() when both host and port are non-zero value Aug 27, 2020
@fabriziopandini
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2020
Copy link
Member

@vincepri vincepri left a 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

@k8s-ci-robot k8s-ci-robot added this to the v0.3.9 milestone Aug 28, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /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 Aug 28, 2020
@vincepri
Copy link
Member

/test pull-cluster-api-test

@jzhoucliqr
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 6ee07b3 into kubernetes-sigs:master Aug 28, 2020
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/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.

7 participants