Skip to content

Commit 6a1e5ac

Browse files
Merge pull request #178 from iamemilio/portAllowedAddressPairsUX
Bug 1952179: Port Allowed Address Pairs UI
2 parents fc80c59 + 600b322 commit 6a1e5ac

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

pkg/apis/openstackproviderconfig/v1alpha1/types.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
2120
corev1 "k8s.io/api/core/v1"
2221
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2322
)
@@ -200,17 +199,17 @@ type SubnetFilter struct {
200199
}
201200

202201
type PortOpts struct {
203-
NetworkID string `json:"networkID" required:"true"`
204-
NameSuffix string `json:"nameSuffix" required:"true"`
205-
Description string `json:"description,omitempty"`
206-
AdminStateUp *bool `json:"adminStateUp,omitempty"`
207-
MACAddress string `json:"macAddress,omitempty"`
208-
FixedIPs []FixedIPs `json:"fixedIPs,omitempty"`
209-
TenantID string `json:"tenantID,omitempty"`
210-
ProjectID string `json:"projectID,omitempty"`
211-
SecurityGroups *[]string `json:"securityGroups,omitempty"`
212-
AllowedAddressPairs []ports.AddressPair `json:"allowedAddressPairs,omitempty"`
213-
Tags []string `json:"tags,omitempty"`
202+
NetworkID string `json:"networkID" required:"true"`
203+
NameSuffix string `json:"nameSuffix" required:"true"`
204+
Description string `json:"description,omitempty"`
205+
AdminStateUp *bool `json:"adminStateUp,omitempty"`
206+
MACAddress string `json:"macAddress,omitempty"`
207+
FixedIPs []FixedIPs `json:"fixedIPs,omitempty"`
208+
TenantID string `json:"tenantID,omitempty"`
209+
ProjectID string `json:"projectID,omitempty"`
210+
SecurityGroups *[]string `json:"securityGroups,omitempty"`
211+
AllowedAddressPairs []AddressPair `json:"allowedAddressPairs,omitempty"`
212+
Tags []string `json:"tags,omitempty"`
214213

215214
// The ID of the host where the port is allocated
216215
HostID string `json:"hostID,omitempty"`
@@ -224,6 +223,11 @@ type PortOpts struct {
224223
PortSecurity *bool `json:"portSecurity,omitempty"`
225224
}
226225

226+
type AddressPair struct {
227+
IPAddress string `json:"ipAddress,omitempty"`
228+
MACAddress string `json:"macAddress,omitempty"`
229+
}
230+
227231
type FixedIPs struct {
228232
SubnetID string `json:"subnetID"`
229233
IPAddress string `json:"ipAddress,omitempty"`

pkg/cloud/openstack/clients/machineservice.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,14 @@ func getOrCreatePort(is *InstanceService, name string, portOpts openstackconfigv
342342
TenantID: portOpts.TenantID,
343343
ProjectID: portOpts.ProjectID,
344344
SecurityGroups: portOpts.SecurityGroups,
345-
AllowedAddressPairs: portOpts.AllowedAddressPairs,
345+
AllowedAddressPairs: []ports.AddressPair{},
346+
}
347+
348+
for _, ap := range portOpts.AllowedAddressPairs {
349+
createOpts.AllowedAddressPairs = append(createOpts.AllowedAddressPairs, ports.AddressPair{
350+
IPAddress: ap.IPAddress,
351+
MACAddress: ap.MACAddress,
352+
})
346353
}
347354
if len(portOpts.FixedIPs) != 0 {
348355
fixedIPs := make([]ports.IP, len(portOpts.FixedIPs))
@@ -533,7 +540,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
533540
return nil, fmt.Errorf("Failed to retrieve cluster Infrastructure object: %v", err)
534541
}
535542

536-
allowedAddressPairs := []ports.AddressPair{}
543+
allowedAddressPairs := []openstackconfigv1.AddressPair{}
537544
if clusterInfra != nil && clusterInfra.Status.PlatformStatus != nil && clusterInfra.Status.PlatformStatus.OpenStack != nil {
538545
clusterVips := []string{
539546
clusterInfra.Status.PlatformStatus.OpenStack.APIServerInternalIP,
@@ -543,7 +550,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
543550

544551
for _, vip := range clusterVips {
545552
if vip != "" {
546-
allowedAddressPairs = append(allowedAddressPairs, ports.AddressPair{IPAddress: vip})
553+
allowedAddressPairs = append(allowedAddressPairs, openstackconfigv1.AddressPair{IPAddress: vip})
547554
}
548555
}
549556
}
@@ -557,7 +564,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
557564
portOpt.SecurityGroups = &securityGroups
558565
portOpt.AllowedAddressPairs = allowedAddressPairs
559566
if _, ok := netsWithoutAllowedAddressPairs[portOpt.NetworkID]; ok {
560-
portOpt.AllowedAddressPairs = []ports.AddressPair{}
567+
portOpt.AllowedAddressPairs = []openstackconfigv1.AddressPair{}
561568
}
562569

563570
port, err := getOrCreatePort(is, name, portOpt)

0 commit comments

Comments
 (0)