Skip to content

Commit

Permalink
Detect Nodes Network MTU
Browse files Browse the repository at this point in the history
This commit adds the support to detect the Nodes
Network MTU so that the Namespace Networks use the
same MTU as the host.
  • Loading branch information
MaysaMacedo committed Oct 29, 2020
1 parent 6bb5d45 commit a918dd9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bindata/network/kuryr/003-config.yaml
Expand Up @@ -60,7 +60,7 @@ data:
pod_security_groups = {{ default "default" .PodSecurityGroups }}
resource_tags = {{ default "" .ResourceTags }}
external_svc_net = {{ .ExternalNetwork }}
#network_device_mtu = 1500
network_device_mtu = {{ .NodesNetworkMTU }}
[neutron]
auth_type = {{ default "password" .OpenStackCloud.AuthType }}
Expand Down
1 change: 1 addition & 0 deletions pkg/bootstrap/types.go
Expand Up @@ -9,6 +9,7 @@ type KuryrBootstrapResult struct {
PodSubnetpool string
WorkerNodesRouter string
WorkerNodesSubnet string
NodesNetworkMTU int
PodSecurityGroups []string
ExternalNetwork string
ClusterID string
Expand Down
3 changes: 3 additions & 0 deletions pkg/network/kuryr.go
Expand Up @@ -112,6 +112,9 @@ func renderKuryr(conf *operv1.NetworkSpec, bootstrapResult *bootstrap.BootstrapR
data.Data["WebhookCert"] = b.WebhookCert
data.Data["WebhookKey"] = b.WebhookKey

// Nodes Network MTU
data.Data["NodesNetworkMTU"] = b.NodesNetworkMTU

manifests, err := render.RenderDir(filepath.Join(manifestDir, "network/kuryr"), &data)
if err != nil {
return nil, errors.Wrap(err, "failed to render manifests")
Expand Down
6 changes: 6 additions & 0 deletions pkg/platform/openstack/kuryr_bootstrap.go
Expand Up @@ -330,6 +330,11 @@ func BootstrapKuryr(conf *operv1.NetworkSpec, kubeClient client.Client) (*bootst
if err != nil {
return nil, errors.Wrap(err, "failed to find worker nodes subnet")
}
mtu, err := getOpenStackNetworkMTU(client, workerSubnet.NetworkID)
if err != nil {
return nil, errors.Wrap(err, "failed to get network MTU")
}
log.Printf("Found Nodes Network MTU %d", mtu)

log.Printf("Found worker nodes subnet %s", workerSubnet.ID)
router, err := ensureOpenStackRouter(client, generateName("external-router", clusterID), tag, workerSubnet.NetworkID)
Expand Down Expand Up @@ -642,6 +647,7 @@ func BootstrapKuryr(conf *operv1.NetworkSpec, kubeClient client.Client) (*bootst
PodSubnetpool: podSubnetpoolId,
WorkerNodesRouter: routerId,
WorkerNodesSubnet: workerSubnet.ID,
NodesNetworkMTU: mtu,
PodSecurityGroups: []string{podSgId},
ExternalNetwork: externalNetwork,
ClusterID: clusterID,
Expand Down
16 changes: 16 additions & 0 deletions pkg/platform/openstack/networking.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/mtu"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools"
Expand Down Expand Up @@ -114,6 +115,21 @@ func findOpenStackNetwork(client *gophercloud.ServiceClient, tag string) (networ
}
}

// Gets the MTU of a Network
func getOpenStackNetworkMTU(client *gophercloud.ServiceClient, networkID string) (int, error) {
networkMTU := 0
type NetworkMTU struct {
networks.Network
mtu.NetworkMTUExt
}
var mtu NetworkMTU
err := networks.Get(client, networkID).ExtractInto(&mtu)
if err != nil {
return networkMTU, errors.Wrap(err, "failed to extract network MTU")
}
return mtu.MTU, nil
}

// Looks for a Neutron subnet by name and tag. In case of not found, looks for a
// provided custom subnet by tag. Fails if any not found.
func findOpenStackSubnet(client *gophercloud.ServiceClient, name, tag, clusterID string) (subnets.Subnet, error) {
Expand Down

0 comments on commit a918dd9

Please sign in to comment.