[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
This commit is contained in:
Robbie Zhang
2018-02-13 19:07:27 -08:00
committed by GitHub
parent d23ac6679c
commit f4ebbfc7a3
15 changed files with 399 additions and 86 deletions

View File

@@ -14,6 +14,7 @@ import (
"time"
"github.com/virtual-kubelet/virtual-kubelet/manager"
client "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/aci"
"k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
@@ -58,11 +59,6 @@ func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operat
p.resourceManager = rm
p.aciClient, err = aci.NewClient()
if err != nil {
return nil, err
}
if config != "" {
f, err := os.Open(config)
if err != nil {
@@ -75,6 +71,61 @@ func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operat
}
}
var azAuth *client.Authentication
if authFilepath := os.Getenv("AZURE_AUTH_LOCATION"); authFilepath != "" {
auth, err := client.NewAuthenticationFromFile(authFilepath)
if err != nil {
return nil, err
}
azAuth = auth
}
if acsFilepath := os.Getenv("ACS_CREDENTIAL_LOCATION"); acsFilepath != "" {
acsCredential, err := NewAcsCredential(acsFilepath)
if err != nil {
return nil, err
}
if acsCredential != nil {
if acsCredential.Cloud != client.PublicCloud.Name {
return nil, fmt.Errorf("ACI only supports Public Azure. '%v' is not supported", acsCredential.Cloud)
}
azAuth = client.NewAuthentication(
acsCredential.Cloud,
acsCredential.ClientID,
acsCredential.ClientSecret,
acsCredential.SubscriptionID,
acsCredential.TenantID)
p.resourceGroup = acsCredential.ResourceGroup
p.region = acsCredential.Region
}
}
if clientID := os.Getenv("AZURE_CLIENT_ID"); clientID != "" {
azAuth.ClientID = clientID
}
if clientSecret := os.Getenv("AZURE_CLIENT_SECRET"); clientSecret != "" {
azAuth.ClientSecret = clientSecret
}
if tenantID := os.Getenv("AZURE_TENANT_ID"); tenantID != "" {
azAuth.TenantID = tenantID
}
if subscriptionID := os.Getenv("AZURE_SUBSCRIPTION_ID"); subscriptionID != "" {
azAuth.SubscriptionID = subscriptionID
}
p.aciClient, err = aci.NewClient(azAuth)
if err != nil {
return nil, err
}
if rg := os.Getenv("ACI_RESOURCE_GROUP"); rg != "" {
p.resourceGroup = rg
}