Update the network sdk and add more validations
This commit is contained in:
@@ -6,66 +6,44 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-05-01/network"
|
||||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/api"
|
||||
)
|
||||
|
||||
const (
|
||||
subnetPath = "subscriptions/{{.subscriptionId}}/resourcegroups/{{.resourceGroupName}}/providers/Microsoft.Network/virtualNetworks/{{.vnetName}}/subnets/{{.subnetName}}"
|
||||
subnetAction = "Microsoft.Network/virtualNetworks/subnets/action"
|
||||
)
|
||||
|
||||
// Subnet represents an Azure subnet
|
||||
type Subnet struct {
|
||||
Name string
|
||||
ID string
|
||||
Properties *SubnetProperties
|
||||
}
|
||||
var (
|
||||
delegationName = "aciDelegation"
|
||||
serviceName = "Microsoft.ContainerInstance/containerGroups"
|
||||
)
|
||||
|
||||
// SubnetProperties are the properties for a subne
|
||||
type SubnetProperties struct {
|
||||
AddressPrefix string `json:"addressPrefix,omitempty"`
|
||||
// NewSubnetWithContainerInstanceDelegation creates the subnet instance with ACI delegation
|
||||
func NewSubnetWithContainerInstanceDelegation(name, addressPrefix string) *network.Subnet {
|
||||
subnet := network.Subnet{
|
||||
Name: &name,
|
||||
SubnetPropertiesFormat: &network.SubnetPropertiesFormat{
|
||||
AddressPrefix: &addressPrefix,
|
||||
Delegations: &[]network.Delegation{
|
||||
network.Delegation{
|
||||
Name: &delegationName,
|
||||
ServiceDelegationPropertiesFormat: &network.ServiceDelegationPropertiesFormat{
|
||||
ServiceName: &serviceName,
|
||||
Actions: &[]string{subnetAction},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// IPConfigurationProfiles and Delegations are new fields not available in the SDK yet
|
||||
IPConfigurationProfiles []SubnetIPConfigurationProfile `json:"ipConfigurationProfiles"`
|
||||
Delegations []Delegation
|
||||
|
||||
// copied from official go SDK, none of these are used here except to make sure we don't nil out some data on fetched objects.
|
||||
// NetworkSecurityGroup - The reference of the NetworkSecurityGroup resource.
|
||||
NetworkSecurityGroup *network.SecurityGroup `json:"networkSecurityGroup,omitempty"`
|
||||
// RouteTable - The reference of the RouteTable resource.
|
||||
RouteTable *network.RouteTable `json:"routeTable,omitempty"`
|
||||
// ServiceEndpoints - An array of service endpoints.
|
||||
ServiceEndpoints *[]network.ServiceEndpointPropertiesFormat `json:"serviceEndpoints,omitempty"`
|
||||
// IPConfigurations - Gets an array of references to the network interface IP configurations using subnet.
|
||||
IPConfigurations *[]network.IPConfiguration `json:"ipConfigurations,omitempty"`
|
||||
// ResourceNavigationLinks - Gets an array of references to the external resources using subnet.
|
||||
ResourceNavigationLinks *[]network.ResourceNavigationLink `json:"resourceNavigationLinks,omitempty"`
|
||||
// ProvisioningState - The provisioning state of the resource.
|
||||
ProvisioningState *string `json:"provisioningState,omitempty"`
|
||||
}
|
||||
|
||||
// SubnetIPConfigurationProfile stores the ID for an assigned network profile
|
||||
type SubnetIPConfigurationProfile struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Delegation stores the subnet delegation details
|
||||
type Delegation struct {
|
||||
Name string
|
||||
ID string
|
||||
ETag string
|
||||
Properties DelegationProperties
|
||||
}
|
||||
|
||||
// DelegationProperties stores the properties for a delegation
|
||||
type DelegationProperties struct {
|
||||
ServiceName string
|
||||
Actions []string
|
||||
return &subnet
|
||||
}
|
||||
|
||||
// GetSubnet gets the subnet from the specified resourcegroup/vnet
|
||||
func (c *Client) GetSubnet(resourceGroup, vnet, name string) (*Subnet, error) {
|
||||
func (c *Client) GetSubnet(resourceGroup, vnet, name string) (*network.Subnet, error) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -100,7 +78,7 @@ func (c *Client) GetSubnet(resourceGroup, vnet, name string) (*Subnet, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var subnet Subnet
|
||||
var subnet network.Subnet
|
||||
if err := json.NewDecoder(resp.Body).Decode(&subnet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -108,7 +86,7 @@ func (c *Client) GetSubnet(resourceGroup, vnet, name string) (*Subnet, error) {
|
||||
}
|
||||
|
||||
// CreateOrUpdateSubnet creates a new or updates an existing subnet in the defined resourcegroup/vnet
|
||||
func (c *Client) CreateOrUpdateSubnet(resourceGroup, vnet string, s *Subnet) (*Subnet, error) {
|
||||
func (c *Client) CreateOrUpdateSubnet(resourceGroup, vnet string, s *network.Subnet) (*network.Subnet, error) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -132,7 +110,7 @@ func (c *Client) CreateOrUpdateSubnet(resourceGroup, vnet string, s *Subnet) (*S
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
"subscriptionId": c.auth.SubscriptionID,
|
||||
"resourceGroupName": resourceGroup,
|
||||
"subnetName": s.Name,
|
||||
"subnetName": *s.Name,
|
||||
"vnetName": vnet,
|
||||
}); err != nil {
|
||||
return nil, errors.Wrap(err, "expanding URL with parameters failed")
|
||||
@@ -150,7 +128,7 @@ func (c *Client) CreateOrUpdateSubnet(resourceGroup, vnet string, s *Subnet) (*S
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var subnet Subnet
|
||||
var subnet network.Subnet
|
||||
if err := json.NewDecoder(resp.Body).Decode(&subnet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user