Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

fix: fix ARM dependency issues with vm user-specified extensions on node pools #2398

Merged
merged 3 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions pkg/engine/vmextensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,39 +234,53 @@ func CreateAgentVMASAKSBillingExtension(cs *api.ContainerService, profile *api.A
func CreateCustomExtensions(properties *api.Properties) []DeploymentARM {
var extensionsARM []DeploymentARM

for _, extensionProfile := range properties.ExtensionProfiles {
if properties.MasterProfile != nil {
if properties.MasterProfile != nil {
// The first extension needs to depend on the master cse created for all nodes
// Each proceeding extension needs to depend on the previous one to avoid ARM conflicts in the Compute RP
nextDependsOn := "[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')), '/extensions/cse-master-', copyIndex(variables('masterOffset')))]"

for _, extensionProfile := range properties.ExtensionProfiles {
masterOptedForExtension, singleOrAll := validateProfileOptedForExtension(extensionProfile.Name, properties.MasterProfile.Extensions)
if masterOptedForExtension {
data, e := getMasterLinkedTemplateText(properties.OrchestratorProfile.OrchestratorType, extensionProfile, singleOrAll)
if e != nil {
fmt.Println(e.Error())
}
var ext DeploymentARM
if err := json.Unmarshal([]byte(data), &ext); err != nil {
fmt.Println(err.Error())
e = json.Unmarshal([]byte(data), &ext)
if e != nil {
fmt.Println(e.Error())
}
ext.DependsOn = []string{nextDependsOn}
nextDependsOn = *ext.Name
extensionsARM = append(extensionsARM, ext)
}

}
}

for _, agentPoolProfile := range properties.AgentPoolProfiles {
poolProfileExtensions := agentPoolProfile.Extensions
poolOptedForExtension, singleOrAll := validateProfileOptedForExtension(extensionProfile.Name, poolProfileExtensions)
for _, agentPoolProfile := range properties.AgentPoolProfiles {
// The first extension needs to depend on the agent cse created for all nodes
// Each proceeding extension needs to depend on the previous one to avoid ARM conflicts in the Compute RP
nextDependsOn := fmt.Sprintf("[concat('Microsoft.Compute/virtualMachines/', variables('%[1]sVMNamePrefix'), copyIndex(variables('%[1]sOffset')), '/extensions/cse-agent-', copyIndex(variables('%[1]sOffset')))]", agentPoolProfile.Name)

for _, extensionProfile := range properties.ExtensionProfiles {
poolOptedForExtension, singleOrAll := validateProfileOptedForExtension(extensionProfile.Name, agentPoolProfile.Extensions)
if poolOptedForExtension {
data, e := getAgentPoolLinkedTemplateText(agentPoolProfile, properties.OrchestratorProfile.OrchestratorType, extensionProfile, singleOrAll)
if e != nil {
fmt.Println(e.Error())
}
var ext DeploymentARM
if err := json.Unmarshal([]byte(data), &ext); err != nil {
fmt.Println(err.Error())
e = json.Unmarshal([]byte(data), &ext)
if e != nil {
fmt.Println(e.Error())
}
ext.DependsOn = []string{nextDependsOn}
nextDependsOn = *ext.Name
extensionsARM = append(extensionsARM, ext)
}

}
}

return extensionsARM
}
44 changes: 41 additions & 3 deletions pkg/engine/vmextensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ func TestCreateCustomExtensions(t *testing.T) {
Version: "v1",
RootURL: "https://raw.githubusercontent.com/Azure/aks-engine/master/",
},
{
Name: "hello-world-k8s",
Version: "v1",
RootURL: "https://raw.githubusercontent.com/Azure/aks-engine/master/",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
{
Expand All @@ -501,6 +506,9 @@ func TestCreateCustomExtensions(t *testing.T) {
{
Name: "winrm",
},
{
Name: "hello-world-k8s",
},
},
},
},
Expand All @@ -516,7 +524,7 @@ func TestCreateCustomExtensions(t *testing.T) {
"count": "[sub(variables('windowspool1Count'), variables('windowspool1Offset'))]",
"name": "winrmExtensionLoop",
},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('windowspool1VMNamePrefix'), copyIndex(variables('windowspool1Offset')), '/extensions/cse', '-agent-', copyIndex(variables('windowspool1Offset')))]"},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('windowspool1VMNamePrefix'), copyIndex(variables('windowspool1Offset')), '/extensions/cse-agent-', copyIndex(variables('windowspool1Offset')))]"},
},
DeploymentExtended: resources.DeploymentExtended{
Name: to.StringPtr("[concat(variables('windowspool1VMNamePrefix'), copyIndex(variables('windowspool1Offset')), 'winrm')]"),
Expand Down Expand Up @@ -545,7 +553,7 @@ func TestCreateCustomExtensions(t *testing.T) {
"count": "[sub(variables('windowspool2Count'), variables('windowspool2Offset'))]",
"name": "winrmExtensionLoop",
},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')), '/extensions/cse', '-agent-', copyIndex(variables('windowspool2Offset')))]"},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')), '/extensions/cse-agent-', copyIndex(variables('windowspool2Offset')))]"},
},
DeploymentExtended: resources.DeploymentExtended{
Name: to.StringPtr("[concat(variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')), 'winrm')]"),
Expand All @@ -567,13 +575,43 @@ func TestCreateCustomExtensions(t *testing.T) {
Type: to.StringPtr("Microsoft.Resources/deployments"),
},
},
{
DeploymentARMResource: DeploymentARMResource{
APIVersion: "[variables('apiVersionDeployments')]",
Copy: map[string]string{
"count": "[sub(variables('windowspool2Count'), variables('windowspool2Offset'))]",
"name": "helloWorldExtensionLoop",
},
DependsOn: []string{"[concat(variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')), 'winrm')]"},
},
DeploymentExtended: resources.DeploymentExtended{
Name: to.StringPtr("[concat(variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')), 'HelloWorldK8s')]"),
Properties: &resources.DeploymentPropertiesExtended{
TemplateLink: &resources.TemplateLink{
URI: to.StringPtr("https://raw.githubusercontent.com/Azure/aks-engine/master/extensions/hello-world-k8s/v1/template.json"),
ContentVersion: to.StringPtr("1.0.0.0"),
},
Parameters: map[string]interface{}{
"apiVersionDeployments": map[string]interface{}{"value": "[variables('apiVersionDeployments')]"},
"artifactsLocation": map[string]interface{}{"value": "https://raw.githubusercontent.com/Azure/aks-engine/master/"},
"extensionParameters": map[string]interface{}{"value": "[parameters('hello-world-k8sParameters')]"},
"targetVMName": map[string]interface{}{"value": "[concat(variables('windowspool2VMNamePrefix'), copyIndex(variables('windowspool2Offset')))]"},
"targetVMType": map[string]interface{}{"value": "agent"},
"vmIndex": map[string]interface{}{"value": "[copyIndex(variables('windowspool2Offset'))]"},
},
Mode: resources.DeploymentMode("Incremental"),
},
Type: to.StringPtr("Microsoft.Resources/deployments"),
},
},
}

diff := cmp.Diff(extensions, expectedDeployments)

if diff != "" {
t.Errorf("unexpected diff while expecting equal structs: %s", diff)
}

properties = &api.Properties{
OrchestratorProfile: &api.OrchestratorProfile{
OrchestratorType: Kubernetes,
Expand Down Expand Up @@ -607,7 +645,7 @@ func TestCreateCustomExtensions(t *testing.T) {
"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
"name": "helloWorldExtensionLoop",
},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')), '/extensions/cse', '-master-', copyIndex(variables('masterOffset')))]"},
DependsOn: []string{"[concat('Microsoft.Compute/virtualMachines/', variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')), '/extensions/cse-master-', copyIndex(variables('masterOffset')))]"},
},
DeploymentExtended: resources.DeploymentExtended{
Name: to.StringPtr("[concat(variables('masterVMNamePrefix'), copyIndex(variables('masterOffset')), 'HelloWorldK8s')]"),
Expand Down