Skip to content

Commit

Permalink
Update CSE command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Xu committed Feb 12, 2020
1 parent 67ec721 commit 1e4e7a4
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 303 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ clean: tools-clean

GIT_BASEDIR = $(shell git rev-parse --show-toplevel 2>/dev/null)
ifneq ($(GIT_BASEDIR),)
LDFLAGS += -X github.com/Azure/baker/pkg/test.JUnitOutDir=$(GIT_BASEDIR)/test/junit
LDFLAGS += -X github.com/Azure/agentbaker/pkg/test.JUnitOutDir=$(GIT_BASEDIR)/test/junit
endif

ginkgoBuild: generate
Expand Down
6 changes: 3 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,16 @@ func (gc *generateCmd) run() error {
fmt.Println("+++++++++++++++++++++++++++++++++++++")
fmt.Printf("Cs%++v", gc.containerService.Properties)

customDataStr := templateGenerator.GetNodeCustomDataStr(gc.containerService, gc.containerService.Properties.AgentPoolProfiles[0])
customDataStr := templateGenerator.GetNodeBootstrappingPayload(gc.containerService, gc.containerService.Properties.AgentPoolProfiles[0])

customDataStr := templateGenerator.GetNodeC(gc.containerService, gc.containerService.Properties.AgentPoolProfiles[0])
cseCmdStr := templateGenerator.GetNodeBootstrappingCmd(gc.containerService, gc.containerService.Properties.AgentPoolProfiles[0])

writer := &engine.ArtifactWriter{
Translator: &i18n.Translator{
Locale: gc.locale,
},
}
if err = writer.WriteTLSArtifacts(gc.containerService, gc.apiVersion, customDataStr, "", gc.outputDirectory, certsGenerated, gc.parametersOnly); err != nil {
if err = writer.WriteTLSArtifacts(gc.containerService, gc.apiVersion, customDataStr, cseCmdStr, gc.outputDirectory, certsGenerated, gc.parametersOnly); err != nil {
return errors.Wrap(err, "writing artifacts")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Azure/baker
module github.com/Azure/agentbaker

go 1.12

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"os"

"github.com/Azure/baker/cmd"
"github.com/Azure/agentbaker/cmd"
colorable "github.com/mattn/go-colorable"
log "github.com/sirupsen/logrus"
)
Expand Down
19 changes: 12 additions & 7 deletions pkg/agent/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (t *TemplateGenerator) getLinuxNodeCSECommand(cs *api.ContainerService, pro
//get parameters
parameters := getParameters(cs, "", "")
//get variable
variables := getCSECommandVariables(cs, "", "")
variables := getCSECommandVariables(cs, profile, parameters, "mockidentityidclientid", "", "")
str, e := t.getSingleLineForTemplate(kubernetesCSECommandString,
profile, t.getBakerFuncMap(cs, parameters, variables))

Expand Down Expand Up @@ -157,16 +157,21 @@ func (t *TemplateGenerator) getSingleLine(textFilename string, profile interface
func (t *TemplateGenerator) getBakerFuncMap(cs *api.ContainerService, params paramsMap, variables paramsMap) template.FuncMap {
funcMap := getContainerServiceFuncMap(cs)

funcMap["GetParameter"] = func(s string) string {
return params[s].(string)
funcMap["GetParameter"] = func(s string) interface{} {
return params[s]
}

funcMap["GetVariable"] = func(s string) string {
return variables[s].(string)
//TODO: GetParameterPropertyLower
funcMap["GetParameterProperty"] = func(s, p string) interface{} {
return params[s].(map[string]interface{})[p]
}

funcMap["GetVariableProperty"] = func(v, p string) string {
return variables[v].(map[string]interface{})[p].(string)
funcMap["GetVariable"] = func(s string) interface{} {
return variables[s]
}

funcMap["GetVariableProperty"] = func(v, p string) interface{} {
return variables[v].(map[string]interface{})[p]
}

return funcMap
Expand Down
20 changes: 1 addition & 19 deletions pkg/agent/cseCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,14 @@
package agent

import (
"fmt"
"strconv"

"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/go-autorest/autorest/to"
)

func getBootstrappingCSE(cs *api.ContainerService, profile *api.AgentPoolProfile) string {
if profile.IsWindows() {
return "[concat('echo %DATE%,%TIME%,%COMPUTERNAME% && powershell.exe -ExecutionPolicy Unrestricted -command \"', '$arguments = ', variables('singleQuote'),'-MasterIP ',parameters('kubernetesEndpoint'),' -KubeDnsServiceIp ',parameters('kubeDnsServiceIp'),' -MasterFQDNPrefix ',variables('masterFqdnPrefix'),' -Location ',variables('location'),' -TargetEnvironment ',parameters('targetEnvironment'),' -AgentKey ',parameters('clientPrivateKey'),' -AADClientId ',variables('servicePrincipalClientId'),' -AADClientSecret ',variables('singleQuote'),variables('singleQuote'),base64(variables('servicePrincipalClientSecret')),variables('singleQuote'),variables('singleQuote'),' -NetworkAPIVersion ',variables('apiVersionNetwork'),' ',variables('singleQuote'), ' ; ', variables('windowsCustomScriptSuffix'), '\" > %SYSTEMDRIVE%\\AzureData\\CustomDataSetupScript.log 2>&1 ; exit $LASTEXITCODE')]"
} else {

runInBackground := ""
nVidiaEnabled := strconv.FormatBool(IsNvidiaEnabledSKU(profile.VMSize))
sgxEnabled := strconv.FormatBool(IsSgxEnabledSKU(profile.VMSize))
auditDEnabled := strconv.FormatBool(to.Bool(profile.AuditDEnabled))
isVHD := strconv.FormatBool(profile.IsVHDDistro())

return fmt.Sprintf("[concat('echo $(date),$(hostname); %s for i in $(seq 1 1200); do grep -Fq \"EOF\" /opt/azure/containers/provision.sh && break; if [ $i -eq 1200 ]; then exit 100; else sleep 1; fi; done; ', variables('provisionScriptParametersCommon'),%s,' IS_VHD=%s GPU_NODE=%s SGX_NODE=%s AUDITD_ENABLED=%s /usr/bin/nohup /bin/bash -c \"/bin/bash /opt/azure/containers/provision.sh >> /var/log/azure/cluster-provision.log 2>&1%s\"')]",
outBoundCmd,
generateUserAssignedIdentityClientIDParameter(cs),
isVHD,
nVidiaEnabled,
sgxEnabled,
auditDEnabled,
runInBackground)
return ""
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/Azure/agentbaker/pkg/templates"
"github.com/blang/semver"
"io/ioutil"
"log"
Expand Down Expand Up @@ -363,7 +364,7 @@ func escapeSingleLine(escapedStr string) string {

// getBase64EncodedGzippedCustomScript will return a base64 of the CSE
func getBase64EncodedGzippedCustomScript(csFilename string, cs *api.ContainerService) string {
b, err := Asset(csFilename)
b, err := templates.Asset(csFilename)
if err != nil {
// this should never happen and this is a bug
panic(fmt.Sprintf("BUG: %s", err.Error()))
Expand Down
64 changes: 50 additions & 14 deletions pkg/agent/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package agent
import (
"fmt"
"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/go-autorest/autorest/to"
"strconv"
"strings"
)

Expand All @@ -25,37 +28,45 @@ func getCustomDataVariables(cs *api.ContainerService, generatorCode string, aksE
}
}

func getCSECommandVariables(cs *api.ContainerService, params paramsMap, generatorCode string, aksEngineVersion string) paramsMap {

func getCSECommandVariables(cs *api.ContainerService, profile *api.AgentPoolProfile, params paramsMap, userAssignedIdentityID, generatorCode string, aksEngineVersion string) paramsMap {
variables := map[string]interface{}{
"outBoundCmd": getOutBoundCmd(cs),
"tenantID": getTenantID(),
"subscriptionId": getSubscriptionID(),
"resourceGroup": getResourceGroupName(),
"location": getLocation(),
"vmType": getVMType(cs),
"agentNamePrefix": fmt.Sprintf("%s-agentpool-%s-", params["orchestratorName"], params["nameSuffix"]),
"primaryAvailabilitySetName": getPrimaryAvailabilitySetName(cs, params),
"primaryScaleSetName": cs.Properties.GetPrimaryScaleSetName(),
"outBoundCmd": getOutBoundCmd(cs),
"tenantID": getTenantID(),
"subscriptionId": getSubscriptionID(),
"resourceGroup": getResourceGroupName(),
"location": getLocation(),
"vmType": getVMType(cs),
"agentNamePrefix": fmt.Sprintf("%s-agentpool-%s-", params["orchestratorName"], params["nameSuffix"]),
"primaryAvailabilitySetName": getPrimaryAvailabilitySetName(cs, params),
"primaryScaleSetName": cs.Properties.GetPrimaryScaleSetName(),
"useManagedIdentityExtension": useManagedIdentity(cs),
"useInstanceMetadata": useInstanceMetadata(cs),
"loadBalancerSku": cs.Properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku,
"excludeMasterFromStandardLB": true,
"maximumLoadBalancerRuleCount": getMaximumLoadBalancerRuleCount(cs),
"userAssignedIdentityID": userAssignedIdentityID,
"isVHD": isVHD(profile),
"gpuNode": strconv.FormatBool(common.IsNvidiaEnabledSKU(profile.VMSize)),
"sgxNode": strconv.FormatBool(common.IsSgxEnabledSKU(profile.VMSize)),
"auditdEnabled": strconv.FormatBool(to.Bool(profile.AuditDEnabled)),
}
variables["nsgName"] = fmt.Sprintf("%snsg", variables["agentNamePrefix"])
variables["routeTableName"] = fmt.Sprintf("%sroutetable", variables["agentNamePrefix"])

profiles := cs.Properties.AgentPoolProfiles
vnetSubnetID := ""
subnetName := ""
vnetID := ""
virtualNetworkName := ""
virtualNetworkResourceGroupName := ""
if cs.Properties.AreAgentProfilesCustomVNET() {
vnetSubnetID = params[fmt.Sprintf("%sVnetSubnetID", profiles[0].Name)].(string)
vnetSubnetID = params[fmt.Sprintf("%sVnetSubnetID", profile.Name)].(string)
subnetName = strings.Split(vnetSubnetID, "/")[10]
virtualNetworkName = strings.Split(vnetSubnetID, "/")[8]
virtualNetworkResourceGroupName = strings.Split(vnetSubnetID, "/")[4]
} else {
virtualNetworkName = fmt.Sprintf("%s-vnet-%s", params["orchestratorName"], params["nameSuffix"])
vnetID = getResourceID("Microsoft.Network/virtualNetworks", virtualNetworkName)
subnetName = fmt.Sprintf("%s-subnet", params["orchestratorName"].(string))
subnetName = fmt.Sprintf("%s-subnet", params["orchestratorName"].(paramsMap)["value"])
vnetSubnetID = getSubResourceID(vnetID, "subnets", subnetName)
variables["vnetID"] = vnetID
}
Expand Down Expand Up @@ -98,6 +109,31 @@ func getPrimaryAvailabilitySetName(cs *api.ContainerService, params paramsMap) s
return fmt.Sprintf("%s-availabilitySet-%s", cs.Properties.AgentPoolProfiles[0].Name, params["nameSuffix"])
}

func useManagedIdentity(cs *api.ContainerService) string {
useManagedIdentity := cs.Properties.OrchestratorProfile.KubernetesConfig != nil &&
cs.Properties.OrchestratorProfile.KubernetesConfig.UseManagedIdentity
return strconv.FormatBool(useManagedIdentity)
}

func useInstanceMetadata(cs *api.ContainerService) string {
useInstanceMetadata := cs.Properties.OrchestratorProfile.KubernetesConfig != nil &&
cs.Properties.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata != nil &&
*cs.Properties.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata
return strconv.FormatBool(useInstanceMetadata)
}

func getMaximumLoadBalancerRuleCount(cs *api.ContainerService) int {
if cs.Properties.OrchestratorProfile.KubernetesConfig != nil {
return cs.Properties.OrchestratorProfile.KubernetesConfig.MaximumLoadBalancerRuleCount
}
return 0
}

func isVHD(profile *api.AgentPoolProfile) string {
//NOTE: update as new distro is introduced
return strconv.FormatBool(profile.IsVHDDistro())
}

func getResourceID(resourceType, resourceName string) string {
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/%s/%s",
getSubscriptionID(),
Expand Down
Loading

0 comments on commit 1e4e7a4

Please sign in to comment.