Skip to content

Commit

Permalink
Merge pull request #255 from rabi/port_regression
Browse files Browse the repository at this point in the history
Fix regression when assigning provision server port
  • Loading branch information
openshift-merge-bot[bot] authored Jan 8, 2025
2 parents 0fd6a2a + ea54549 commit 2c19dda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/v1beta1/openstackprovisionserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func AssignProvisionServerPort(

if found {
if existingPorts[instance.GetName()] != cur {
return fmt.Errorf("%v port already used by another OpeStackProvisionServer", cur)
// continue to use the next port in the port range.
continue
} else {
break
}
Expand Down
20 changes: 11 additions & 9 deletions api/v1beta1/openstackprovisionserver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *OpenStackProvisionServer) validateCr() error {

for name, port := range existingPorts {
if name != r.Name && port == r.Spec.Port {
return fmt.Errorf("port %d is already in use", port)
return fmt.Errorf("port %d is already in use by another OpeStackProvisionServer", port)
}
}

Expand Down Expand Up @@ -115,13 +115,15 @@ func (r *OpenStackProvisionServer) Default() {
if r.Spec.OSImage == "" {
r.Spec.OSImage = openstackProvisionServerDefaults.OSImage
}
err := AssignProvisionServerPort(context.TODO(), webhookClient, r,
ProvisionServerPortStart, ProvisionServerPortEnd)
if err != nil {
// If this occurs, it will also be caught just after this defaulting webhook in the
// validating webhook, because that webhook calls the same underlying function that
// checks for the availability of ports. That will cause the create/update of the
// CR to fail and halt moving forward.
openstackprovisionserverlog.Error(err, "Cannot assign port for OpenStackProvisionServer", "OpenStackProvisionServer", r)
if r.Spec.Port == 0 {
err := AssignProvisionServerPort(context.TODO(), webhookClient, r,
ProvisionServerPortStart, ProvisionServerPortEnd)
if err != nil {
// If this occurs, it will also be caught just after this defaulting webhook in the
// validating webhook, because that webhook calls the same underlying function that
// checks for the availability of ports. That will cause the create/update of the
// CR to fail and halt moving forward.
openstackprovisionserverlog.Error(err, "Cannot assign port for OpenStackProvisionServer", "OpenStackProvisionServer", r)
}
}
}

0 comments on commit 2c19dda

Please sign in to comment.