Files
virtual-kubelet/providers/azure/client/aci/client.go
Robbie Zhang f4ebbfc7a3 [Azure] Optimize VK Setup in ACS/AKS (#85)
* Read ACS Credentials for Azure Authentication

Supprt a new environment variable: ACS_CREDENTIAL_LOCATION
Expect the value to be the ACS credential filepath, which is the
/etc/kubernetes/azure.json file generated on the ACS nodes.

If the ACS_CREDENTIAL_LOCATION is specified and loaded,
create the Azure Authentication class from its values.

If the AZURE_AUTHENTICATION_LOCATION is specified and loaded,
its values will overwrite the value above.

Refactor the ACI provider and ACI client to be able to override the SPN by environment variable
2018-02-13 19:07:27 -08:00

44 lines
1.6 KiB
Go

package aci
import (
"fmt"
"net/http"
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
)
const (
// BaseURI is the default URI used for compute services.
BaseURI = "https://management.azure.com"
userAgent = "virtual-kubelet/azure-arm-aci/2017-12-01"
apiVersion = "2017-12-01-preview"
containerGroupURLPath = "subscriptions/{{.subscriptionId}}/resourceGroups/{{.resourceGroup}}/providers/Microsoft.ContainerInstance/containerGroups/{{.containerGroupName}}"
containerGroupListURLPath = "subscriptions/{{.subscriptionId}}/providers/Microsoft.ContainerInstance/containerGroups"
containerGroupListByResourceGroupURLPath = "subscriptions/{{.subscriptionId}}/resourceGroups/{{.resourceGroup}}/providers/Microsoft.ContainerInstance/containerGroups"
containerLogsURLPath = containerGroupURLPath + "/containers/{{.containerName}}/logs"
)
// Client is a client for interacting with Azure Container Instances.
//
// Clients should be reused instead of created as needed.
// The methods of Client are safe for concurrent use by multiple goroutines.
type Client struct {
hc *http.Client
auth *azure.Authentication
}
// NewClient creates a new Azure Container Instances client.
func NewClient(auth *azure.Authentication) (*Client, error) {
if auth == nil {
return nil, fmt.Errorf("Authentication is not supplied for the Azure client")
}
client, err := azure.NewClient(auth, BaseURI, userAgent)
if err != nil {
return nil, fmt.Errorf("Creating Azure client failed: %v", err)
}
return &Client{hc: client.HTTPClient, auth: auth}, nil
}