зеркало из https://github.com/microsoft/oe-engine.git
support existing VNET
This commit is contained in:
Родитель
e40d551351
Коммит
3ac068b87f
|
@ -42,28 +42,53 @@
|
|||
"description": "Password or ssh key value."
|
||||
}
|
||||
},
|
||||
{{if .MasterProfile.IsCustomVNET}}
|
||||
"vnetSubnetID": {
|
||||
"vnetNewOrExisting": {
|
||||
"type": "string",
|
||||
"defaultValue": "new",
|
||||
"allowedValues": [
|
||||
"new",
|
||||
"existing"
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Sets the vnet subnet of the VM."
|
||||
},
|
||||
"type": "string"
|
||||
"description": "Determines whether or not a new virtual network should be provisioned. Existing virtual networks must have been provisioned in US East. //unless you really need it for the preview, I would just create a new vnet - so the location mismatch doesn't cause problems"
|
||||
}
|
||||
},
|
||||
{{else}}
|
||||
"subnet": {
|
||||
"defaultValue": "{{.MasterProfile.Subnet}}",
|
||||
"vnetName": {
|
||||
"type": "string",
|
||||
"defaultValue": "[concat(resourceGroup().name, '-vnet')]",
|
||||
"metadata": {
|
||||
"description": "Name of the virtual network (alphanumeric, hyphen, underscore, period)."
|
||||
},
|
||||
"minLength": 2,
|
||||
"maxLength": 64
|
||||
},
|
||||
"vnetResourceGroupName": {
|
||||
"type": "string",
|
||||
"defaultValue": "[resourceGroup().name]",
|
||||
"metadata": {
|
||||
"description": "Name of the resource group for the existing virtual network."
|
||||
}
|
||||
},
|
||||
"vnetAddress": {
|
||||
"type": "string",
|
||||
"defaultValue": "{{.MasterProfile.VnetAddress}}",
|
||||
"metadata": {
|
||||
"description": "VNET address space"
|
||||
}
|
||||
},
|
||||
"subnetName": {
|
||||
"type": "string",
|
||||
"defaultValue": "[concat(parameters('vmName'), '-subnet')]",
|
||||
"metadata": {
|
||||
"description": "Name of the subnet."
|
||||
}
|
||||
},
|
||||
"subnetAddress": {
|
||||
"type": "string",
|
||||
"defaultValue": "{{.MasterProfile.SubnetAddress}}",
|
||||
"metadata": {
|
||||
"description": "Sets the subnet of the VM."
|
||||
},
|
||||
"type": "string"
|
||||
},
|
||||
{{end}}
|
||||
"staticIP": {
|
||||
"defaultValue": "{{.MasterProfile.StaticIP}}",
|
||||
"metadata": {
|
||||
"description": "Sets the static IP of the VM"
|
||||
},
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"osImageName": {
|
||||
{{GetOSImageNames}}
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
{{if not .MasterProfile.IsCustomVNET}}
|
||||
{
|
||||
"condition": "[equals(parameters('vnetNewOrExisting'), 'new')]",
|
||||
"apiVersion": "[variables('apiVersionDefault')]",
|
||||
"dependsOn": [
|
||||
{{GetVNETSubnetDependencies}}
|
||||
],
|
||||
"location": "[parameters('location')]",
|
||||
"name": "[variables('virtualNetworkName')]",
|
||||
"name": "[parameters('vnetName')]",
|
||||
"properties": {
|
||||
"addressSpace": {
|
||||
"addressPrefixes": [
|
||||
{{GetVNETAddressPrefixes}}
|
||||
"[parameters('vnetAddress')]"
|
||||
]
|
||||
},
|
||||
"subnets": [
|
||||
{{GetVNETSubnets true}}
|
||||
{
|
||||
"name": "[parameters('subnetName')]",
|
||||
"properties": {
|
||||
"addressPrefix": "[parameters('subnetAddress')]"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "Microsoft.Network/virtualNetworks"
|
||||
},
|
||||
{{end}}
|
||||
{
|
||||
"apiVersion": "[variables('apiVersionDefault')]",
|
||||
"location": "[parameters('location')]",
|
||||
|
@ -40,9 +41,8 @@
|
|||
{
|
||||
"apiVersion": "[variables('apiVersionDefault')]",
|
||||
"dependsOn": [
|
||||
{{if not .MasterProfile.IsCustomVNET}}
|
||||
"[variables('vnetID')]",
|
||||
{{end}}
|
||||
"[variables('publicIPAddressName')]",
|
||||
"[parameters('vnetName')]",
|
||||
"[variables('nsgID')]"
|
||||
],
|
||||
"location": "[parameters('location')]",
|
||||
|
@ -52,8 +52,7 @@
|
|||
{
|
||||
"name": "ipConfigNode",
|
||||
"properties": {
|
||||
"privateIPAddress": "[variables('staticIP')]",
|
||||
"privateIPAllocationMethod": "Static",
|
||||
"privateIPAllocationMethod": "Dynamic",
|
||||
"subnet": {
|
||||
"id": "[variables('vnetSubnetID')]"
|
||||
},
|
||||
|
|
11
parts/vars.t
11
parts/vars.t
|
@ -27,16 +27,7 @@
|
|||
"nsgName": "acc-nsg",
|
||||
"nsgID": "[resourceId('Microsoft.Network/networkSecurityGroups',variables('nsgName'))]",
|
||||
"publicIPAddressName": "acc-ip",
|
||||
{{if .MasterProfile.IsCustomVNET}}
|
||||
"vnetSubnetID": "[parameters('vnetSubnetID')]",
|
||||
{{else}}
|
||||
"subnet": "[parameters('subnet')]",
|
||||
"subnetName": "accSubnet",
|
||||
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
|
||||
"vnetSubnetID": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
|
||||
"virtualNetworkName": "acc-vnet",
|
||||
{{end}}
|
||||
"staticIP": "[parameters('staticIP')]",
|
||||
"vnetSubnetID": "[resourceId(parameters('vnetResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets/', parameters('vnetName'), parameters('subnetName'))]",
|
||||
{{GetOSImageReferences}},
|
||||
{{GetVMPlans}},
|
||||
"plan": "[variables('plans')[parameters('osImageName')]]",
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// CidrFirstIP returns the first IP of the provided subnet.
|
||||
|
@ -41,17 +39,3 @@ func IP4BroadcastAddress(n *net.IPNet) net.IP {
|
|||
}
|
||||
return last
|
||||
}
|
||||
|
||||
// GetVNETSubnetIDComponents extract subscription, resourcegroup, vnetname, subnetname from the vnetSubnetID
|
||||
func GetVNETSubnetIDComponents(vnetSubnetID string) (string, string, string, string, error) {
|
||||
vnetSubnetIDRegex := `^\/subscriptions\/([^\/]*)\/resourceGroups\/([^\/]*)\/providers\/Microsoft.Network\/virtualNetworks\/([^\/]*)\/subnets\/([^\/]*)$`
|
||||
re, err := regexp.Compile(vnetSubnetIDRegex)
|
||||
if err != nil {
|
||||
return "", "", "", "", err
|
||||
}
|
||||
submatches := re.FindStringSubmatch(vnetSubnetID)
|
||||
if len(submatches) != 5 {
|
||||
return "", "", "", "", fmt.Errorf("Unable to parse vnetSubnetID. Please use a vnetSubnetID with format /subscriptions/SUB_ID/resourceGroups/RG_NAME/providers/Microsoft.Network/virtualNetworks/VNET_NAME/subnets/SUBNET_NAME")
|
||||
}
|
||||
return submatches[1], submatches[2], submatches[3], submatches[4], nil
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ const (
|
|||
DefaultVMName = "accVM"
|
||||
// DefaultGeneratorCode specifies the source generator of the cluster template.
|
||||
DefaultGeneratorCode = "oe-engine"
|
||||
// DefaultStaticIP specifies default static IP address
|
||||
DefaultStaticIP = "10.0.0.4"
|
||||
// DefaultVnet specifies default vnet address space
|
||||
DefaultVnet = "10.0.0.0/16"
|
||||
// DefaultSubnet specifies default subnet
|
||||
DefaultSubnet = "10.0.0.0/24"
|
||||
// DefaultStorageAccountType specifies default storage account type
|
||||
|
|
|
@ -64,17 +64,15 @@ type WindowsProfile struct {
|
|||
|
||||
// MasterProfile represents the definition of the master cluster
|
||||
type MasterProfile struct {
|
||||
VMName string `json:"vmName"`
|
||||
OSImageName string `json:"osImageName"`
|
||||
StorageType string `json:"storageAccountType"`
|
||||
VMSize string `json:"vmSize"`
|
||||
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty"`
|
||||
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
|
||||
VnetCidr string `json:"vnetCidr,omitempty"`
|
||||
StaticIP string `json:"staticIP,omitempty"`
|
||||
Subnet string `json:"subnet"`
|
||||
HTTPSourceAddressPrefix string `json:"HTTPSourceAddressPrefix,omitempty"`
|
||||
Accessible bool `json:"accessible,omitempty"`
|
||||
VMName string `json:"vmName"`
|
||||
OSImageName string `json:"osImageName"`
|
||||
StorageType string `json:"storageAccountType"`
|
||||
VMSize string `json:"vmSize"`
|
||||
VnetResourceGroup string `json:"vnetResourceGroup,omitempty"`
|
||||
VnetName string `json:"vnetName,omitempty"`
|
||||
VnetAddress string `json:"vnetAddress,omitempty"`
|
||||
SubnetName string `json:"subnetName,omitempty"`
|
||||
SubnetAddress string `json:"subnetAddress,omitempty"`
|
||||
}
|
||||
|
||||
// DiagnosticsProfile setting to enable/disable capturing
|
||||
|
@ -135,7 +133,7 @@ func (p *Properties) IsLinux() bool {
|
|||
|
||||
// IsCustomVNET returns true if the customer brought their own VNET
|
||||
func (m *MasterProfile) IsCustomVNET() bool {
|
||||
return len(m.VnetSubnetID) > 0
|
||||
return len(m.VnetResourceGroup) > 0 && len(m.VnetName) > 0 && len(m.SubnetName) > 0
|
||||
}
|
||||
|
||||
// HasSecrets returns true if the customer specified secrets to install
|
||||
|
|
|
@ -2,7 +2,6 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -51,9 +50,6 @@ func (a *Properties) Validate(isUpdate bool) error {
|
|||
if e := a.validateWindowsProfile(); e != nil {
|
||||
return e
|
||||
}
|
||||
if e := a.validateVNET(); e != nil {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -68,11 +64,6 @@ func (a *Properties) validateMasterProfile() error {
|
|||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
if len(m.StaticIP) > 0 {
|
||||
if net.ParseIP(m.StaticIP) == nil {
|
||||
return fmt.Errorf("StaticIP '%s' is an invalid IP address", m.StaticIP)
|
||||
}
|
||||
}
|
||||
if len(m.OSImageName) > 0 {
|
||||
if _, ok := OsImageMap[m.OSImageName]; !ok {
|
||||
return fmt.Errorf("OS image '%s' is not supported", m.OSImageName)
|
||||
|
@ -116,30 +107,6 @@ func (a *Properties) validateWindowsProfile() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *Properties) validateVNET() error {
|
||||
isCustomVNET := a.MasterProfile.IsCustomVNET()
|
||||
|
||||
if isCustomVNET {
|
||||
_, _, _, _, e := common.GetVNETSubnetIDComponents(a.MasterProfile.VnetSubnetID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
statisIP := net.ParseIP(a.MasterProfile.StaticIP)
|
||||
if statisIP == nil {
|
||||
return fmt.Errorf("MasterProfile.StaticIP (with VNET Subnet specification) '%s' is an invalid IP address", a.MasterProfile.StaticIP)
|
||||
}
|
||||
|
||||
if a.MasterProfile.VnetCidr != "" {
|
||||
_, _, err := net.ParseCIDR(a.MasterProfile.VnetCidr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MasterProfile.VnetCidr '%s' contains invalid cidr notation", a.MasterProfile.VnetCidr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateKeyVaultSecrets(secrets []KeyVaultSecrets, requireCertificateStore bool) error {
|
||||
for _, s := range secrets {
|
||||
if len(s.VaultCertificates) == 0 {
|
||||
|
|
|
@ -38,15 +38,12 @@ func setMasterNetworkDefaults(a *api.Properties, isUpgrade bool) {
|
|||
}
|
||||
|
||||
if !a.MasterProfile.IsCustomVNET() {
|
||||
a.MasterProfile.Subnet = api.DefaultSubnet
|
||||
// StaticIP is not reset if it is upgrade and some value already exists
|
||||
if !isUpgrade || len(a.MasterProfile.StaticIP) == 0 {
|
||||
a.MasterProfile.StaticIP = api.DefaultStaticIP
|
||||
if len(a.MasterProfile.VnetAddress) == 0 {
|
||||
a.MasterProfile.VnetAddress = api.DefaultVnet
|
||||
}
|
||||
if len(a.MasterProfile.SubnetAddress) == 0 {
|
||||
a.MasterProfile.SubnetAddress = api.DefaultSubnet
|
||||
}
|
||||
}
|
||||
|
||||
if a.MasterProfile.HTTPSourceAddressPrefix == "" {
|
||||
a.MasterProfile.HTTPSourceAddressPrefix = "*"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,25 +88,6 @@ func getStorageAccountType(sizeName string) (string, error) {
|
|||
return "Standard_LRS", nil
|
||||
}
|
||||
|
||||
func getVNETAddressPrefixes(properties *api.Properties) string {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString(`"[variables('subnet')]"`)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func getVNETSubnetDependencies(properties *api.Properties) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getVNETSubnets(properties *api.Properties, addNSG bool) string {
|
||||
return `{
|
||||
"name": "[variables('subnetName')]",
|
||||
"properties": {
|
||||
"addressPrefix": "[variables('subnet')]"
|
||||
}
|
||||
}`
|
||||
}
|
||||
|
||||
func getLBRule(name string, port int) string {
|
||||
return fmt.Sprintf(` {
|
||||
"name": "LBRule%d",
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/Microsoft/oe-engine/pkg/api"
|
||||
)
|
||||
|
||||
|
@ -20,17 +18,18 @@ func getParameters(cs *api.OpenEnclave, generatorCode string) (paramsMap, error)
|
|||
}
|
||||
|
||||
if properties.MasterProfile.IsCustomVNET() {
|
||||
addValue(parametersMap, "vnetSubnetID", properties.MasterProfile.VnetSubnetID)
|
||||
addValue(parametersMap, "vnetNewOrExisting", "existing")
|
||||
addValue(parametersMap, "vnetResourceGroupName", properties.MasterProfile.VnetResourceGroup)
|
||||
addValue(parametersMap, "vnetName", properties.MasterProfile.VnetName)
|
||||
addValue(parametersMap, "subnetName", properties.MasterProfile.SubnetName)
|
||||
} else {
|
||||
addValue(parametersMap, "subnet", properties.MasterProfile.Subnet)
|
||||
addValue(parametersMap, "vnetNewOrExisting", "new")
|
||||
addValue(parametersMap, "subnetAddress", properties.MasterProfile.SubnetAddress)
|
||||
}
|
||||
addValue(parametersMap, "staticIP", properties.MasterProfile.StaticIP)
|
||||
addValue(parametersMap, "vmName", properties.MasterProfile.VMName)
|
||||
addValue(parametersMap, "vmSize", properties.MasterProfile.VMSize)
|
||||
addValue(parametersMap, "osImageName", properties.MasterProfile.OSImageName)
|
||||
if properties.MasterProfile.OSDiskSizeGB > 0 {
|
||||
addValue(parametersMap, "diskSizeGB", strconv.Itoa(properties.MasterProfile.OSDiskSizeGB))
|
||||
}
|
||||
|
||||
if properties.LinuxProfile != nil {
|
||||
addValue(parametersMap, "adminUsername", properties.LinuxProfile.AdminUsername)
|
||||
if len(properties.LinuxProfile.AdminPassword) > 0 {
|
||||
|
|
|
@ -112,9 +112,6 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.OpenEnclave) template.Fun
|
|||
"IsPrivateCluster": func() bool {
|
||||
return false
|
||||
},
|
||||
"GetVNETSubnetDependencies": func() string {
|
||||
return getVNETSubnetDependencies(cs.Properties)
|
||||
},
|
||||
"GetLBRules": func(name string, ports []int) string {
|
||||
return getLBRules(name, ports)
|
||||
},
|
||||
|
@ -124,12 +121,6 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.OpenEnclave) template.Fun
|
|||
"GetSecurityRules": func(ports []int) string {
|
||||
return getSecurityRules(ports)
|
||||
},
|
||||
"GetVNETAddressPrefixes": func() string {
|
||||
return getVNETAddressPrefixes(cs.Properties)
|
||||
},
|
||||
"GetVNETSubnets": func(addNSG bool) string {
|
||||
return getVNETSubnets(cs.Properties, addNSG)
|
||||
},
|
||||
"GetCustomData": func() string {
|
||||
script := getProvisionScript(provisionScript, map[string]string{"PACKAGE_BASE_URL": cs.PackageBaseURL})
|
||||
str := getSingleLineCustomData(
|
||||
|
|
Загрузка…
Ссылка в новой задаче