Skip to content

Commit

Permalink
Merge pull request #15538 from chewong/azure-cloud-config
Browse files Browse the repository at this point in the history
Populate a bare-minimum Azure cloud config
  • Loading branch information
k8s-ci-robot authored Dec 11, 2019
2 parents c42ce36 + 8918eb7 commit 0c5566a
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions kubetest/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ const (
kubeProxyImageName = "kube-proxy-amd64"
)

const (
vmTypeVMSS = "vmss"
vmTypeStandard = "standard"
availabilityProfileVMSS = "VirtualMachineScaleSets"
)

type aksDeploymentMethod int

const (
Expand Down Expand Up @@ -491,7 +497,7 @@ func getAKSDeploymentMethod(k8sRelease string) aksDeploymentMethod {
return customHyperkube
}

func (c *Cluster) populateApiModelTemplate() error {
func (c *Cluster) populateAPIModelTemplate() error {
var err error
v := AksEngineAPIModel{}
if c.apiModelPath != "" {
Expand Down Expand Up @@ -628,6 +634,15 @@ func (c *Cluster) populateApiModelTemplate() error {
if c.isAzureStackCloud() {
v.Properties.CustomCloudProfile.PortalURL = c.azureCustomCloudURL
}

if len(v.Properties.AgentPoolProfiles) > 0 {
// Default to VirtualMachineScaleSets if AvailabilityProfile is empty
isVMSS := v.Properties.AgentPoolProfiles[0].AvailabilityProfile == "" || v.Properties.AgentPoolProfiles[0].AvailabilityProfile == availabilityProfileVMSS
if err := c.populateAzureCloudConfig(isVMSS); err != nil {
return err
}
}

apiModel, _ := json.MarshalIndent(v, "", " ")
c.apiModelPath = path.Join(c.outputDir, "kubernetes.json")
err = ioutil.WriteFile(c.apiModelPath, apiModel, 0644)
Expand Down Expand Up @@ -769,6 +784,40 @@ func (c *Cluster) createCluster() error {

}

func (c *Cluster) populateAzureCloudConfig(isVMSS bool) error {
// CLOUD_CONFIG is required when running Azure-specific e2e tests
// See https://github.com/kubernetes/kubernetes/blob/master/hack/ginkgo-e2e.sh#L113-L118
cc := map[string]string{
"cloud": c.azureEnvironment,
"tenantId": c.credentials.TenantID,
"subscriptionId": c.credentials.SubscriptionID,
"aadClientId": c.credentials.ClientID,
"aadClientSecret": c.credentials.ClientSecret,
"resourceGroup": c.resourceGroup,
"location": c.location,
}
if isVMSS {
cc["vmType"] = vmTypeVMSS
} else {
cc["vmType"] = vmTypeStandard
}

cloudConfig, err := json.MarshalIndent(cc, "", " ")
if err != nil {
return fmt.Errorf("error creating Azure cloud config: %v", err)
}

cloudConfigPath := path.Join(c.outputDir, "azure.json")
if err := ioutil.WriteFile(cloudConfigPath, cloudConfig, 0644); err != nil {
return fmt.Errorf("cannot write Azure cloud config to file: %v", err)
}
if err := os.Setenv("CLOUD_CONFIG", cloudConfigPath); err != nil {
return fmt.Errorf("error setting CLOUD_CONFIG=%s: %v", cloudConfigPath, err)
}

return nil
}

func (c *Cluster) dockerLogin() error {
cwd, _ := os.Getwd()
log.Printf("CWD %v", cwd)
Expand Down Expand Up @@ -1003,7 +1052,7 @@ func (c *Cluster) Up() error {
c.apiModelPath = templateFile
}

err = c.populateApiModelTemplate()
err = c.populateAPIModelTemplate()
if err != nil {
return fmt.Errorf("failed to populate aks-engine apimodel template: %v", err)
}
Expand All @@ -1026,7 +1075,8 @@ func (c *Cluster) Up() error {
if err != nil {
return fmt.Errorf("error creating cluster: %v", err)
}
return err

return nil
}

func (c *Cluster) BuildK8s(b buildStrategy) error {
Expand Down

0 comments on commit 0c5566a

Please sign in to comment.