Skip to content

Commit

Permalink
fix --auto-suffix when dnsPrefix is defined in apimodel json file (Az…
Browse files Browse the repository at this point in the history
  • Loading branch information
serbrech authored and Terje Torkelsen committed Mar 15, 2018
1 parent f5d0180 commit cf128cc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
14 changes: 6 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ func autofillApimodel(dc *deployCmd) {
if dc.dnsPrefix == "" {
log.Fatalf("apimodel: missing masterProfile.dnsPrefix and --dns-prefix was not specified")
}
log.Warnf("apimodel: missing masterProfile.dnsPrefix will use %q", dc.dnsPrefix)
dc.containerService.Properties.MasterProfile.DNSPrefix = dc.dnsPrefix
}

dnsPrefix := dc.dnsPrefix
if dc.autoSuffix {
suffix := strconv.FormatInt(time.Now().Unix(), 16)
dnsPrefix = dnsPrefix + "-" + suffix
}

log.Warnf("apimodel: missing masterProfile.dnsPrefix will use %q", dnsPrefix)
dc.containerService.Properties.MasterProfile.DNSPrefix = dnsPrefix
if dc.autoSuffix {
suffix := strconv.FormatInt(time.Now().Unix(), 16)
dc.containerService.Properties.MasterProfile.DNSPrefix += "-" + suffix
}

if dc.outputDirectory == "" {
Expand Down
50 changes: 49 additions & 1 deletion cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,27 @@ const ExampleAPIModel = `{
}
`

const ExampleAPIModelWithDNSPrefix = `{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": { "orchestratorType": "Kubernetes", "kubernetesConfig": { "useManagedIdentity": %s, "etcdVersion" : "2.3.8" } },
"masterProfile": { "count": 1, "dnsPrefix": "mytestcluster", "vmSize": "Standard_D2_v2" },
"agentPoolProfiles": [ { "name": "linuxpool1", "count": 2, "vmSize": "Standard_D2_v2", "availabilityProfile": "AvailabilitySet" } ],
"windowsProfile": { "adminUsername": "azureuser", "adminPassword": "replacepassword1234$" },
"linuxProfile": { "adminUsername": "azureuser", "ssh": { "publicKeys": [ { "keyData": "" } ] }
},
"servicePrincipalProfile": { "clientId": "%s", "secret": "%s" }
}
}
`

func getExampleAPIModel(useManagedIdentity bool, clientID, clientSecret string) string {
return getAPIModel(ExampleAPIModel, useManagedIdentity, clientID, clientSecret)
}

func getAPIModel(baseAPIModel string, useManagedIdentity bool, clientID, clientSecret string) string {
return fmt.Sprintf(
ExampleAPIModel,
baseAPIModel,
strconv.FormatBool(useManagedIdentity),
clientID,
clientSecret)
Expand All @@ -46,6 +64,36 @@ func TestAutofillApimodelAllowsPrespecifiedCreds(t *testing.T) {
testAutodeployCredentialHandling(t, false, "clientID", "clientSecret")
}

func TestAutoSufixWithDnsPrefixInApiModel(t *testing.T) {
apiloader := &api.Apiloader{
Translator: nil,
}

apimodel := getAPIModel(ExampleAPIModelWithDNSPrefix, false, "clientID", "clientSecret")
cs, ver, err := apiloader.DeserializeContainerService([]byte(apimodel), false, false, nil)
if err != nil {
t.Fatalf("unexpected error deserializing the example apimodel: %s", err)
}
deployCmd := &deployCmd{
apimodelPath: "./this/is/unused.json",
outputDirectory: "_test_output",
location: "westus",
autoSuffix: true,
containerService: cs,
apiVersion: ver,

client: &armhelpers.MockACSEngineClient{},
}
autofillApimodel(deployCmd)

defer os.RemoveAll(deployCmd.outputDirectory)

if deployCmd.containerService.Properties.MasterProfile.DNSPrefix == "mytestcluster" {
t.Fatalf("expected %s-{timestampsuffix} but got %s", "mytestcluster", deployCmd.containerService.Properties.MasterProfile.DNSPrefix)
}

}

func testAutodeployCredentialHandling(t *testing.T, useManagedIdentity bool, clientID, clientSecret string) {
apiloader := &api.Apiloader{
Translator: nil,
Expand Down

0 comments on commit cf128cc

Please sign in to comment.