Skip to content

Commit

Permalink
test: enable multiple subnets per agent pool (Azure#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis authored Jan 11, 2019
1 parent b615a2e commit 5ae54fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
10 changes: 4 additions & 6 deletions test/e2e/azure/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,19 @@ func (a *Account) CreateDeployment(name string, e *engine.Engine) error {
}

// CreateVnet will create a vnet in a resource group
func (a *Account) CreateVnet(vnet, addressPrefixes, subnetName, subnetPrefix string) error {
func (a *Account) CreateVnet(vnet, addressPrefixes string) error {
var cmd *exec.Cmd
if a.TimeoutCommands {
cmd = exec.Command("timeout", "60", "az", "network", "vnet", "create", "-g",
a.ResourceGroup.Name, "-n", vnet, "--address-prefixes", addressPrefixes,
"--subnet-name", subnetName, "--subnet-prefix", subnetPrefix)
a.ResourceGroup.Name, "-n", vnet, "--address-prefixes", addressPrefixes)
} else {
cmd = exec.Command("az", "network", "vnet", "create", "-g",
a.ResourceGroup.Name, "-n", vnet, "--address-prefixes", addressPrefixes,
"--subnet-name", subnetName, "--subnet-prefix", subnetPrefix)
a.ResourceGroup.Name, "-n", vnet, "--address-prefixes", addressPrefixes)
}
util.PrintCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error while trying to create vnet with the following command:\n az network vnet create -g %s -n %s --address-prefixes %s --subnet-name %s --subnet-prefix %s \n Output:%s\n", a.ResourceGroup.Name, vnet, addressPrefixes, subnetName, subnetPrefix, out)
log.Printf("Error while trying to create vnet with the following command:\n az network vnet create -g %s -n %s --address-prefixes %s\n Output:%s\n", a.ResourceGroup.Name, vnet, addressPrefixes, out)
return err
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/engine/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ParseConfig(cwd, clusterDefinition, name string) (*Config, error) {

// Build takes a template path and will inject values based on provided environment variables
// it will then serialize the structs back into json and save it to outputPath
func Build(cfg *config.Config, masterSubnetID string, agentSubnetID string, isVMSS bool) (*Engine, error) {
func Build(cfg *config.Config, masterSubnetID string, agentSubnetIDs []string, isVMSS bool) (*Engine, error) {
config, err := ParseConfig(cfg.CurrentWorkingDir, cfg.ClusterDefinition, cfg.Name)
if err != nil {
log.Printf("Error while trying to build Engine Configuration:%s\n", err)
Expand Down Expand Up @@ -139,14 +139,14 @@ func Build(cfg *config.Config, masterSubnetID string, agentSubnetID string, isVM
if config.CreateVNET {
if isVMSS {
prop.MasterProfile.VnetSubnetID = masterSubnetID
prop.MasterProfile.AgentVnetSubnetID = agentSubnetID
prop.MasterProfile.AgentVnetSubnetID = agentSubnetIDs[0]
for _, p := range prop.AgentPoolProfiles {
p.VnetSubnetID = agentSubnetID
p.VnetSubnetID = agentSubnetIDs[0]
}
} else {
prop.MasterProfile.VnetSubnetID = masterSubnetID
for _, p := range prop.AgentPoolProfiles {
p.VnetSubnetID = masterSubnetID
for i, p := range prop.AgentPoolProfiles {
p.VnetSubnetID = agentSubnetIDs[i]
}
}
}
Expand Down
45 changes: 33 additions & 12 deletions test/e2e/runner/cli_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,64 @@ func (cli *CLIProvisioner) provision() error {

subnetID := ""
vnetName := fmt.Sprintf("%sCustomVnet", cli.Config.Name)
subnetName := fmt.Sprintf("%sCustomSubnet", cli.Config.Name)
masterSubnetID := ""
masterSubnetName := fmt.Sprintf("%sCustomSubnetMaster", cli.Config.Name)
masterSubnetID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", cli.Account.SubscriptionID, cli.Account.ResourceGroup.Name, vnetName, masterSubnetName)
agentSubnetID := ""
agentSubnetIDs := []string{}

if cli.CreateVNET {
if cli.MasterVMSS {
masterSubnetName := fmt.Sprintf("%sCustomSubnetMaster", cli.Config.Name)
agentSubnetName := fmt.Sprintf("%sCustomSubnetAgent", cli.Config.Name)
err = cli.Account.CreateVnet(vnetName, "10.239.0.0/16", masterSubnetName, "10.239.0.0/17")
err = cli.Account.CreateVnet(vnetName, "10.239.0.0/16")
if err != nil {
return errors.Errorf("Error trying to create vnet:%s", err.Error())
}

masterSubnetID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", cli.Account.SubscriptionID, cli.Account.ResourceGroup.Name, vnetName, masterSubnetName)

err = cli.Account.CreateSubnet(vnetName, masterSubnetName, "10.239.0.0/17")
if err != nil {
return errors.Errorf("Error trying to create subnet:%s", err.Error())
}
err = cli.Account.CreateSubnet(vnetName, agentSubnetName, "10.239.128.0/17")
if err != nil {
return errors.Errorf("Error trying to create subnet in vnet:%s", err.Error())
return errors.Errorf("Error trying to create subnet in subnet:%s", err.Error())
}

agentSubnetID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", cli.Account.SubscriptionID, cli.Account.ResourceGroup.Name, vnetName, agentSubnetName)
} else {
err = cli.Account.CreateVnet(vnetName, "10.239.0.0/16", subnetName, "10.239.0.0/16")
config, err := engine.ParseConfig(cli.Config.CurrentWorkingDir, cli.Config.ClusterDefinition, cli.Config.Name)
if err != nil {
log.Printf("Error while trying to build Engine Configuration:%s\n", err)
}
cs, err := engine.ParseInput(config.ClusterDefinitionPath)
if err != nil {
return err
}
err = cli.Account.CreateVnet(vnetName, "10.239.0.0/16")
if err != nil {
return errors.Errorf("Error trying to create vnet:%s", err.Error())
}
subnetID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", cli.Account.SubscriptionID, cli.Account.ResourceGroup.Name, vnetName, subnetName)
err = cli.Account.CreateSubnet(vnetName, masterSubnetName, "10.239.255.0/24")
if err != nil {
return errors.Errorf("Error trying to create subnet:%s", err.Error())
}
for i, pool := range cs.ContainerService.Properties.AgentPoolProfiles {
subnetName := fmt.Sprintf("%sCustomSubnet", pool.Name)
err = cli.Account.CreateSubnet(vnetName, subnetName, fmt.Sprintf("10.239.%d.0/24", i+1))
if err != nil {
return errors.Errorf("Error trying to create subnet:%s", err.Error())
}
subnetID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", cli.Account.SubscriptionID, cli.Account.ResourceGroup.Name, vnetName, subnetName)
agentSubnetIDs = append(agentSubnetIDs, subnetID)
}
}
}

// Lets modify our template and call aks-engine generate on it
var eng *engine.Engine

if cli.CreateVNET && cli.MasterVMSS {
eng, err = engine.Build(cli.Config, masterSubnetID, agentSubnetID, true)
eng, err = engine.Build(cli.Config, masterSubnetID, []string{agentSubnetID}, true)
} else {
eng, err = engine.Build(cli.Config, subnetID, subnetID, false)
eng, err = engine.Build(cli.Config, masterSubnetID, agentSubnetIDs, false)
}

if err != nil {
Expand Down

0 comments on commit 5ae54fb

Please sign in to comment.