Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions drivers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (
flAzureUsePrivateIP = "azure-use-private-ip"
flAzureStaticPublicIP = "azure-static-public-ip"
flAzureNoPublicIP = "azure-no-public-ip"
flAzureNoNSG = "azure-no-nsg"
flAzureNoAvailability = "azure-no-availability"
flAzureDNSLabel = "azure-dns"
flAzureStorageType = "azure-storage-type"
flAzureCustomData = "azure-custom-data"
Expand Down Expand Up @@ -112,6 +114,8 @@ type Driver struct {
PrivateIPAddr string
UsePrivateIP bool
NoPublicIP bool
NoNSG bool
NoAvailability bool
DNSLabel string
StaticPublicIP bool
CustomDataFile string // Can provide cloud-config file here
Expand Down Expand Up @@ -274,6 +278,14 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: flAzureNoPublicIP,
Usage: "Do not create a public IP address for the machine",
},
mcnflag.BoolFlag{
Name: flAzureNoNSG,
Comment thread
jiaqiluo marked this conversation as resolved.
Usage: "Do not create a network security group for the machine",
},
mcnflag.BoolFlag{
Name: flAzureNoAvailability,
Usage: "Do not create a AvailabilitySet or AvailabilityZone for the machine",
},
mcnflag.BoolFlag{
Name: flAzureStaticPublicIP,
Usage: "Assign a static public IP address to the machine",
Expand Down Expand Up @@ -360,6 +372,8 @@ func (d *Driver) SetConfigFromFlags(fl drivers.DriverOptions) error {
d.PrivateIPAddr = fl.String(flAzurePrivateIPAddr)
d.UsePrivateIP = fl.Bool(flAzureUsePrivateIP)
d.NoPublicIP = fl.Bool(flAzureNoPublicIP)
d.NoNSG = fl.Bool(flAzureNoNSG)
d.NoAvailability = fl.Bool(flAzureNoAvailability)
d.StaticPublicIP = fl.Bool(flAzureStaticPublicIP)
d.DockerPort = fl.Int(flAzureDockerPort)
d.DNSLabel = fl.String(flAzureDNSLabel)
Expand Down Expand Up @@ -394,7 +408,7 @@ func (d *Driver) PreCreateCheck() (err error) {
}
}

if d.AvailabilityZone != "" {
if d.AvailabilityZone != "" && !d.NoAvailability {
if !d.ManagedDisks {
return fmt.Errorf("Managed Disks must be used when creating resources in specific Availability Zones (--azure-managed-disks)")
}
Expand Down Expand Up @@ -480,13 +494,22 @@ func (d *Driver) Create() error {
return err
}
// availability sets and availability zones cannot be used together. The presence of an Availability Zone indicates that an Availability set should not be created / used
if d.AvailabilityZone == "" {
if err := c.CreateAvailabilitySetIfNotExists(ctx, d.deploymentCtx, d.ResourceGroup, d.AvailabilitySet, d.Location, d.ManagedDisks, int32(d.FaultCount), int32(d.UpdateCount)); err != nil {
return err
if d.NoAvailability {
log.Info("Not creating an availability zone or availability set.")
} else {
// availability sets and availability zones cannot be used together. The presence of an Availability Zone indicates that an Availability set should not be created / used
if d.AvailabilityZone == "" {
if err := c.CreateAvailabilitySetIfNotExists(ctx, d.deploymentCtx, d.ResourceGroup, d.AvailabilitySet, d.Location, d.ManagedDisks, int32(d.FaultCount), int32(d.UpdateCount)); err != nil {
return err
}
}
}
if err := c.CreateNetworkSecurityGroup(ctx, d.deploymentCtx, d.ResourceGroup, d.nsgResource, d.Location, d.nsgUsedInPool, d.deploymentCtx.FirewallRules); err != nil {
return err
if d.NoNSG {
log.Info("Not creating a network security group.")
} else {
if err := c.CreateNetworkSecurityGroup(ctx, d.deploymentCtx, d.ResourceGroup, d.nsgResource, d.Location, d.nsgUsedInPool, d.deploymentCtx.FirewallRules); err != nil {
return err
}
}
vnetResourceGroup, vNetName := parseVirtualNetwork(d.VirtualNetwork, d.ResourceGroup)
if err := c.CreateVirtualNetworkIfNotExists(ctx, vnetResourceGroup, vNetName, d.Location); err != nil {
Expand Down Expand Up @@ -565,7 +588,7 @@ func (d *Driver) Remove() error {
return err
}
// availability sets and availability zones cannot be used together. The absence of any Availability Zones indicates that an Availability set was created and should be deleted.
if d.AvailabilityZone == "" {
if d.AvailabilityZone == "" && !d.NoAvailability {
if err := c.CleanupAvailabilitySetIfExists(ctx, d.ResourceGroup, d.AvailabilitySet); err != nil {
return err
}
Expand Down
15 changes: 9 additions & 6 deletions drivers/azure/azureutil/azureutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ func (a AzureClient) CreateNetworkInterface(ctx context.Context, deploymentCtx *
publicIP = &network.PublicIPAddress{ID: to.StringPtr(publicIPAddressID)}
}

var nsg *network.SecurityGroup
if nsgID != "" {
nsg = &network.SecurityGroup{ID: to.StringPtr(nsgID)}
}

var privateIPAllocMethod = network.Dynamic
if privateIPAddress != "" {
privateIPAllocMethod = network.Static
Expand All @@ -336,9 +341,7 @@ func (a AzureClient) CreateNetworkInterface(ctx context.Context, deploymentCtx *
Location: to.StringPtr(location),
InterfacePropertiesFormat: &network.InterfacePropertiesFormat{
EnableAcceleratedNetworking: to.BoolPtr(enabledAcceleratedNetworking),
NetworkSecurityGroup: &network.SecurityGroup{
ID: to.StringPtr(nsgID),
},
NetworkSecurityGroup: nsg,
IPConfigurations: &[]network.InterfaceIPConfiguration{
{
Name: to.StringPtr("ip"),
Expand Down Expand Up @@ -640,12 +643,12 @@ func (a AzureClient) CreateVirtualMachine(ctx context.Context, resourceGroup, na
// in particular Availability Zones - you can only specify one or the other.
// if a user has provided an availability zone it is assumed that
// no availability sets should be created / used.
if availabilityZone == "" {
if availabilityZone != "" {
vm.Zones = to.StringSlicePtr([]string{availabilityZone})
} else if availabilitySetID != "" {
vm.VirtualMachineProperties.AvailabilitySet = &compute.SubResource{
ID: to.StringPtr(availabilitySetID),
}
} else {
vm.Zones = to.StringSlicePtr([]string{availabilityZone})
}

future, err := virtualMachinesClient.CreateOrUpdate(ctx, resourceGroup, name, vm)
Expand Down