[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:
@@ -3,11 +3,10 @@ package aci
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/resourcegroups"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -20,23 +19,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Check if the AZURE_AUTH_LOCATION variable is already set.
|
||||
// If it is not set, set it to the root of this project in a credentials.json file.
|
||||
if os.Getenv("AZURE_AUTH_LOCATION") == "" {
|
||||
// Check if the credentials.json file exists in the root of this project.
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
dir := filepath.Dir(filename)
|
||||
file := filepath.Join(dir, "../../../../credentials.json")
|
||||
|
||||
// Check if the file exists.
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
log.Fatalf("Either set AZURE_AUTH_LOCATION or add a credentials.json file to the root of this project.")
|
||||
}
|
||||
|
||||
// Set the environment variable for the authentication file.
|
||||
os.Setenv("AZURE_AUTH_LOCATION", file)
|
||||
}
|
||||
|
||||
// Create a resource group name with uuid.
|
||||
uid := uuid.New()
|
||||
resourceGroup += "-" + uid.String()[0:6]
|
||||
@@ -45,8 +27,13 @@ func init() {
|
||||
// The TestMain function creates a resource group for testing
|
||||
// and deletes in when it's done.
|
||||
func TestMain(m *testing.M) {
|
||||
auth, err := azure.NewAuthenticationFromFile("../../../../credentials.json")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load Azure authentication file: %v", err)
|
||||
}
|
||||
|
||||
// Check if the resource group exists and create it if not.
|
||||
rgCli, err := resourcegroups.NewClient()
|
||||
rgCli, err := resourcegroups.NewClient(auth)
|
||||
if err != nil {
|
||||
log.Fatalf("creating new resourcegroups client failed: %v", err)
|
||||
}
|
||||
@@ -84,11 +71,17 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
var err error
|
||||
client, err = NewClient()
|
||||
auth, err := azure.NewAuthenticationFromFile("../../../../credentials.json")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load Azure authentication file: %v", err)
|
||||
}
|
||||
|
||||
c, err := NewClient(auth)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client = c
|
||||
}
|
||||
|
||||
func TestCreateContainerGroupFails(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user