-
Notifications
You must be signed in to change notification settings - Fork 33
Port Count #170
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
Port Count #170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ import ( | |
| netext "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" | ||
| "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" | ||
|
|
@@ -95,11 +96,26 @@ type Instance struct { | |
| } | ||
|
|
||
| type ServerNetwork struct { | ||
| networkID string | ||
| subnetID string | ||
| portTags []string | ||
| vnicType string | ||
| networkID string | ||
| subnetID string | ||
| portTags []string | ||
| vnicType string | ||
| portSecurity *bool | ||
| portName string | ||
| } | ||
|
|
||
| // for geting vnic type when listing ports | ||
iamemilio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type portWithPortsbinding struct { | ||
| ports.Port | ||
| portsbinding.PortsBindingExt | ||
| } | ||
|
|
||
| // for updating port security | ||
iamemilio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var portWithPortSecurityExtensions struct { | ||
| ports.Port | ||
| portsecurity.PortSecurityExt | ||
| } | ||
|
|
||
| type InstanceListOpts struct { | ||
| // Name of the image in URL format. | ||
| Image string `q:"image"` | ||
|
|
@@ -421,35 +437,61 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Set default number of ports created per network to 1 | ||
| portCount := 1 | ||
| if net.PortCount > 1 { | ||
| portCount = int(net.PortCount) | ||
| } | ||
|
|
||
| for _, netID := range ids { | ||
| if net.NoAllowedAddressPairs { | ||
| netsWithoutAllowedAddressPairs[netID] = struct{}{} | ||
| } | ||
| if net.Subnets == nil { | ||
| nets = append(nets, ServerNetwork{ | ||
| networkID: netID, | ||
| portTags: net.PortTags, | ||
| vnicType: net.VNICType, | ||
| }) | ||
| // Create one NIC per count | ||
| for i := 0; i < portCount; i++ { | ||
| nets = append(nets, ServerNetwork{ | ||
| networkID: netID, | ||
| portTags: net.PortTags, | ||
| vnicType: net.VNICType, | ||
| portSecurity: net.PortSecurity, | ||
| portName: fmt.Sprintf("%s-%d", name, i), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where the instance name is enforced, but could it have the following format
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I am not sure actually. Can CAPO manage control plane resources? If so, then this is a possibility. For workers the name scheme for machines is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it does, so this could be a problem. The way I see it, there are 2 ways to handle this:
@MaysaMacedo I am not sure if either of these would have consequences for kuryr, but if either is acceptable, I would lean towards 1.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I thought about this, and while its ugly for now, I would rather just leave it and make it a consideration in a bz we are going to file to eventually have upstream parity with this feature based on this work happening upstream: kubernetes-sigs#778 We will fix this post FF by allowing the port names to be explicitly setable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're working on moving away from relying on ports names on 4.8, so it's fine. I was just not sure is the name of that Port would be something like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that would be a possibility for the master nodes. Its ugly, but we are going to fix it by letting you specify port names when we adopt kubernetes-sigs#778 |
||
| }) | ||
| } | ||
| } | ||
|
|
||
| for _, snetParam := range net.Subnets { | ||
| sopts := subnets.ListOpts(snetParam.Filter) | ||
| sopts.ID = snetParam.UUID | ||
| sopts.NetworkID = netID | ||
|
|
||
| // inherit port security settings from network if not set on subnet | ||
| portSecurity := net.PortSecurity | ||
| if snetParam.PortSecurity != nil { | ||
| portSecurity = snetParam.PortSecurity | ||
| } | ||
|
|
||
| if snetParam.PortCount > 0 { | ||
| portCount = int(snetParam.PortCount) | ||
| } | ||
|
|
||
| // Query for all subnets that match filters | ||
| snetResults, err := getSubnetsByFilter(is, &sopts) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, snet := range snetResults { | ||
| nets = append(nets, ServerNetwork{ | ||
| networkID: snet.NetworkID, | ||
| subnetID: snet.ID, | ||
| portTags: append(net.PortTags, snetParam.PortTags...), | ||
| vnicType: net.VNICType, | ||
| }) | ||
| for i := 0; i < portCount; i++ { | ||
| nets = append(nets, ServerNetwork{ | ||
| networkID: snet.NetworkID, | ||
| subnetID: snet.ID, | ||
| portTags: append(net.PortTags, snetParam.PortTags...), | ||
| vnicType: net.VNICType, | ||
| portSecurity: portSecurity, | ||
| portName: fmt.Sprintf("%s-%d", name, i), | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -478,40 +520,41 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust | |
| } | ||
| } | ||
|
|
||
| // Convert nets list into a list of servers.Network to be passed as NICs for instance create | ||
| userData := base64.StdEncoding.EncodeToString([]byte(cmd)) | ||
| var ports_list []servers.Network | ||
| for _, net := range nets { | ||
| if net.networkID == "" { | ||
| return nil, fmt.Errorf("No network was found or provided. Please check your machine configuration and try again") | ||
| } | ||
| allPages, err := ports.List(is.networkClient, ports.ListOpts{ | ||
| Name: name, | ||
| NetworkID: net.networkID, | ||
| }).AllPages() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Searching for existing port for server err: %v", err) | ||
| var port ports.Port | ||
| secGroups := &securityGroups | ||
| addrPairs := &allowedAddressPairs | ||
| if net.portSecurity != nil && *net.portSecurity == false { | ||
| secGroups = &[]string{} | ||
| addrPairs = &[]ports.AddressPair{} | ||
| } | ||
| portList, err := ports.ExtractPorts(allPages) | ||
| if _, ok := netsWithoutAllowedAddressPairs[net.networkID]; ok { | ||
| addrPairs = &[]ports.AddressPair{} | ||
| } | ||
|
|
||
| port, err = CreatePort(is, net.portName, net, secGroups, addrPairs) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Searching for existing port for server err: %v", err) | ||
| return nil, fmt.Errorf("Failed to create port err: %v", err) | ||
| } | ||
| var port ports.Port | ||
| if len(portList) == 0 { | ||
| // create server port | ||
| if _, ok := netsWithoutAllowedAddressPairs[net.networkID]; ok { | ||
| // create ports without address pairs | ||
| port, err = CreatePort(is, name, net, &securityGroups, &[]ports.AddressPair{}) | ||
| } else { | ||
| port, err = CreatePort(is, name, net, &securityGroups, &allowedAddressPairs) | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Failed to create port err: %v", err) | ||
| } | ||
| } else { | ||
| port = portList[0] | ||
|
|
||
| // Update the port with the correct port security settings | ||
| // TODO(egarcia): figure out if possible to make this part of the prior create and update api calls | ||
| updateOpts := portsecurity.PortUpdateOptsExt{ | ||
| UpdateOptsBuilder: ports.UpdateOpts{}, | ||
| PortSecurityEnabled: net.portSecurity, | ||
| } | ||
| err = ports.Update(is.networkClient, port.ID, updateOpts).ExtractInto(&portWithPortSecurityExtensions) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Failed to update port security on port %s: %v", port.ID, err) | ||
| } | ||
|
|
||
| portTags := deduplicateList(append(machineTags, port.Tags...)) | ||
| portTags := deduplicateList(append(machineTags, net.portTags...)) | ||
| _, err = attributestags.ReplaceAll(is.networkClient, "ports", port.ID, attributestags.ReplaceAllOpts{ | ||
| Tags: portTags}).Extract() | ||
| if err != nil { | ||
|
|
@@ -522,31 +565,13 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust | |
| }) | ||
|
|
||
| if config.Trunk == true { | ||
| allPages, err := trunks.List(is.networkClient, trunks.ListOpts{ | ||
| trunkCreateOpts := trunks.CreateOpts{ | ||
| Name: name, | ||
| PortID: port.ID, | ||
| }).AllPages() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Searching for existing trunk for server err: %v", err) | ||
| } | ||
| trunkList, err := trunks.ExtractTrunks(allPages) | ||
| trunk, err := trunks.Create(is.networkClient, trunkCreateOpts).Extract() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Searching for existing trunk for server err: %v", err) | ||
| } | ||
| var trunk trunks.Trunk | ||
| if len(trunkList) == 0 { | ||
| // create trunk with the previous port as parent | ||
| trunkCreateOpts := trunks.CreateOpts{ | ||
| Name: name, | ||
| PortID: port.ID, | ||
| } | ||
| newTrunk, err := trunks.Create(is.networkClient, trunkCreateOpts).Extract() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Create trunk for server err: %v", err) | ||
| } | ||
| trunk = *newTrunk | ||
| } else { | ||
| trunk = trunkList[0] | ||
| return nil, fmt.Errorf("Create trunk for server err: %v", err) | ||
| } | ||
|
|
||
| _, err = attributestags.ReplaceAll(is.networkClient, "trunks", trunk.ID, attributestags.ReplaceAllOpts{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.