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 validation for loadbalancer port against 6443 and to avoid duplicate names #1746

Merged

Conversation

KeerthanaAP
Copy link
Contributor

@KeerthanaAP KeerthanaAP commented Apr 24, 2024

Added validation for loadbalancer port against 6443 as its already used, kubebuilder tag to avoid duplicate ports and validation to avoid duplicate loadbalancer, vpcsubnet names.

Validation output:

The IBMPowerVSCluster "capi-powervs-keerthana" is invalid:
* spec.vpcSubnets[1]: Duplicate value: map[string]interface {}{"Name":"capi-powervs-keerthana-vpcsubnet"}
* spec.loadbalancers[2]: Duplicate value: map[string]interface {}{"Name":"capi-powervs-keerthana-loadbalancer2"}
* spec.loadbalancers[3]: Duplicate value: map[string]interface {}{"Name":"capi-powervs-keerthana-loadbalancer1"}
* spec.loadbalancers[0].additionalListeners[0].port: Invalid value: 6443: value of port should not be equal to APIServerPort (6443)

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1663

Special notes for your reviewer:

/area provider/ibmcloud

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

Add validation for loadbalancer port against 6443 and to avoid duplicate names.

@k8s-ci-robot k8s-ci-robot added the area/provider/ibmcloud Issues or PRs related to ibmcloud provider label Apr 24, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 24, 2024
@k8s-ci-robot
Copy link
Contributor

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

Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!

Name Link
🔨 Latest commit 643d878
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-ibmcloud/deploys/665d7583ed04cf00084fddf6
😎 Deploy Preview https://deploy-preview-1746--kubernetes-sigs-cluster-api-ibmcloud.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 24, 2024
Copy link
Contributor

@Karthik-K-N Karthik-K-N left a comment

Choose a reason for hiding this comment

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

/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 Apr 24, 2024
@KeerthanaAP
Copy link
Contributor Author

/retest-required

@Prajyot-Parab
Copy link
Contributor

ptal @Karthik-K-N

@@ -81,6 +81,7 @@ type VPCLoadBalancerSpec struct {
// +listType=map
// +listMapKey=port
// +optional
// ++kubebuilder:validation:UniqueItems=true
Copy link
Contributor

Choose a reason for hiding this comment

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

Do mind sharing some reference about this tag usage.

Since its slice and for now we have only Port within it. what should be unique, Is port? in future we add another field name say PortName along with port then what should be unique is it port or port and portName combination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// +kubebuilder:validation:UniqueItems = <bool>
specifies that all items in this list must be unique.

As mentioned it validates the ports. All the ports should be unique. if we add another field like PortName, it will fail only if both the fields (portName and port) are same.

api/v1beta2/ibmpowervscluster_webhook.go Outdated Show resolved Hide resolved
api/v1beta2/ibmpowervscluster_webhook.go Outdated Show resolved Hide resolved
api/v1beta2/ibmpowervscluster_webhook.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Karthik-K-N Karthik-K-N left a comment

Choose a reason for hiding this comment

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

Overall LGTM Thanks, Is there any way to improve the error message

spec.vpcSubnets[1]: Duplicate value: map[string]interface {}{"Name":"capi-powervs-keerthana-vpcsubnet"}

to remove map[string]interface {}

@KeerthanaAP
Copy link
Contributor Author

KeerthanaAP commented May 6, 2024

Overall LGTM Thanks, Is there any way to improve the error message

spec.vpcSubnets[1]: Duplicate value: map[string]interface {}{"Name":"capi-powervs-keerthana-vpcsubnet"}

to remove map[string]interface {}

I followed the same error msg format that we get when we apply the kubebuilder tag ++kubebuilder:validation:UniqueItems=true

Example:
The IBMPowerVSCluster "capi-powervs-keerthana" is invalid: spec.loadBalancers[1].additionalListeners[1]: Duplicate value: map[string]interface {}{"port":6442}

or
we can print it as a string as mentioned below

The IBMPowerVSCluster "capi-powervs-keerthana" is invalid: 
* spec.vpcSubnets[1]: Duplicate value: "{Name: capi-powervs-keerthana-vpcsubnet}"

@Karthik-K-N
Copy link
Contributor

Thanks for clarifying
/lgtm

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

@mkumatag @Prajyot-Parab ptal.

@Prajyot-Parab
Copy link
Contributor

@mkumatag @Prajyot-Parab ptal.

update release notes field please.

@KeerthanaAP
Copy link
Contributor Author

@mkumatag @Prajyot-Parab ptal.

update release notes field please.

Done. Updated the release notes.

func (r *IBMPowerVSCluster) validateIBMPowerVSClusterLoadBalancerPort() (allErrs field.ErrorList) {
for i, loadbalancer := range r.Spec.LoadBalancers {
for j, listerner := range loadbalancer.AdditionalListeners {
if listerner.Port == int64(DefaultAPIServerPort) {
Copy link
Member

Choose a reason for hiding this comment

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

what if this port is set Cluster.Spec.ClusterNetwork.APIServerPort ? will this comparison with DefaultAPIServerPort still hold good?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it won't hold good, if user has set Cluster.Spec.ClusterNetwork.APIServerPort we should make sure that that port is not set here in listner.
We usually find the apiserver port like this

// APIServerPort returns the APIServerPort to use when creating the ControlPlaneEndpoint.
func (s *PowerVSClusterScope) APIServerPort() int32 {
if s.Cluster.Spec.ClusterNetwork != nil && s.Cluster.Spec.ClusterNetwork.APIServerPort != nil {
return *s.Cluster.Spec.ClusterNetwork.APIServerPort
}
return infrav1beta2.DefaultAPIServerPort
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we dont have access to cluster resource here in webhook, So we need verify this one scenario in controller code only.

Copy link
Member

Choose a reason for hiding this comment

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

then adding this check here for the DefaultAPIServerPort may mislead the user, lets drop this change here and introduce in the controller itself

Copy link
Contributor

Choose a reason for hiding this comment

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

I think most of the time the apiserver will be running in 6443 only, so i think we can keep it here and can add a check in controller only if the apiserver port is not 6443.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will add this as error msg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified the error msg.
Updated output:

Conditions:
    Last Transition Time:  2024-05-27T17:01:33Z
    Message:               capi-powervs-keerthana-new-loadbalancer2 port (6443) cannot be used as additional Listener port value, as its already configured by system for default listener
    Reason:                LoadBalancerReconciliationFailed

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, Lets hear others opinion on as well.

Copy link
Member

Choose a reason for hiding this comment

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

how about this one - #1746 (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good. As the error strings should not be capitalized, Can we update it as below.

  Conditions:
    Last Transition Time:  2024-05-29T07:03:15Z
    Message:               port 6443 for the capi-powervs-keerthana-new-loadbalancer2 load balancer cannot be used as an additional listener port, as it is already assigned to the API server
    Reason:                LoadBalancerReconciliationFailed

@mkumatag mkumatag added this to the v0.8 milestone May 17, 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 20, 2024
@mkumatag
Copy link
Member

@KeerthanaAP can you make the changes by tomorrow sometime? we are planning to cut a release soon

@KeerthanaAP KeerthanaAP force-pushed the loadbalancer_validation branch 2 times, most recently from 572b09e to d8e1605 Compare May 22, 2024 09:48
@mkumatag mkumatag modified the milestones: v0.8, v0.8.x May 24, 2024
@KeerthanaAP KeerthanaAP force-pushed the loadbalancer_validation branch 2 times, most recently from c58e4da to af434d1 Compare May 27, 2024 16:59
cloud/scope/powervs_cluster.go Outdated Show resolved Hide resolved
Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KeerthanaAP, mkumatag

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 Jun 4, 2024
@k8s-ci-robot k8s-ci-robot merged commit ff78637 into kubernetes-sigs:main Jun 4, 2024
13 checks passed
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. area/provider/ibmcloud Issues or PRs related to ibmcloud provider 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add webhook for validating powervscluster.spec.loadbalancer.additionallister.port against 6443
5 participants