Skip to content

Commit

Permalink
✨ support accelerated networking
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed May 29, 2020
1 parent c0d09b2 commit 9a569d9
Show file tree
Hide file tree
Showing 24 changed files with 565 additions and 51 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha2/azuremachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (src *AzureMachine) ConvertTo(dstRaw conversion.Hub) error { // nolint
if len(restored.Spec.UserAssignedIdentities) > 0 {
dst.Spec.UserAssignedIdentities = restored.Spec.UserAssignedIdentities
}
if restored.Spec.AcceleratedNetworking != nil {
dst.Spec.AcceleratedNetworking = restored.Spec.AcceleratedNetworking
}

dst.Spec.FailureDomain = restored.Spec.FailureDomain

Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha2/azuremachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (src *AzureMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nol
if len(restored.Spec.Template.Spec.UserAssignedIdentities) > 0 {
dst.Spec.Template.Spec.UserAssignedIdentities = restored.Spec.Template.Spec.UserAssignedIdentities
}
if restored.Spec.Template.Spec.AcceleratedNetworking != nil {
dst.Spec.Template.Spec.AcceleratedNetworking = restored.Spec.Template.Spec.AcceleratedNetworking
}
dst.Spec.Template.Spec.FailureDomain = restored.Spec.Template.Spec.FailureDomain

return nil
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/v1alpha3/azuremachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ type AzureMachineSpec struct {
// AllocatePublicIP allows the ability to create dynamic public ips for machines where this value is true.
// +optional
AllocatePublicIP bool `json:"allocatePublicIP,omitempty"`

// AcceleratedNetworking enables or disables Azure accelerated networking. If omitted, it will be set based on
// whether the requested VMSize supports accelerated networking.
// If AcceleratedNetworking is set to true with a VMSize that does not support it, Azure will return an error.
// +kubebuilder:validation:nullable
// +optional
AcceleratedNetworking *bool `json:"acceleratedNetworking,omitempty"`
}

// AzureMachineStatus defines the observed state of AzureMachine
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha3/azuremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestAzureMachine_ValidateCreate(t *testing.T) {
},
{
name: "azuremachine with list of user-assigned identities",
machine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:///123"}, {ProviderID: "azure:///456"}}),
machine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:////123"}, {ProviderID: "azure:////456"}}),
wantErr: false,
},
{
Expand Down Expand Up @@ -129,13 +129,13 @@ func TestAzureMachine_ValidateUpdate(t *testing.T) {
},
{
name: "azuremachine with user assigned identities",
oldMachine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:///123"}}),
machine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:///123"}, {ProviderID: "azure:///456"}}),
oldMachine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:////123"}}),
machine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:////123"}, {ProviderID: "azure:////456"}}),
wantErr: false,
},
{
name: "azuremachine with empty user assigned identities",
oldMachine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:///123"}}),
oldMachine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{{ProviderID: "azure:////123"}}),
machine: createMachineWithUserAssignedIdentities(t, []UserAssignedIdentity{}),
wantErr: true,
},
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const (
// by the user to be assigned to Azure resources.
type UserAssignedIdentity struct {
// ProviderID is the identification ID of the user-assigned Identity, the format of an identity is:
// 'azure:///subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'
// 'azure:////subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'
ProviderID string `json:"providerID"`
}

Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions cloud/services/networkinterfaces/networkinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Spec struct {
PublicLoadBalancerName string
InternalLoadBalancerName string
PublicIPName string
AcceleratedNetworking *bool
}

// Get provides information about a network interface.
Expand Down Expand Up @@ -125,6 +126,16 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
nicConfig.PublicIPAddress = &publicIP
}

if nicSpec.AcceleratedNetworking == nil {
// set accelerated networking to the capability of the VMSize
sku := s.MachineScope.AzureMachine.Spec.VMSize
accelNet, err := s.ResourceSkusClient.HasAcceleratedNetworking(ctx, sku)
if err != nil {
return errors.Wrap(err, "failed to get accelerated networking capability")
}
nicSpec.AcceleratedNetworking = to.BoolPtr(accelNet)
}

err = s.Client.CreateOrUpdate(ctx,
s.Scope.ResourceGroup(),
nicSpec.Name,
Expand All @@ -137,6 +148,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
InterfaceIPConfigurationPropertiesFormat: nicConfig,
},
},
EnableAcceleratedNetworking: nicSpec.AcceleratedNetworking,
},
})

Expand Down

0 comments on commit 9a569d9

Please sign in to comment.