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

Commit

Permalink
[feature] Prevent overwriting existing cluster resources in output di…
Browse files Browse the repository at this point in the history
…rectories (#2581)

* Prevent overwriting existing folder when using the deploy command
  • Loading branch information
skinny authored and jackfrancis committed Apr 10, 2018
1 parent cf0f10d commit 45e4a22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type deployCmd struct {
dnsPrefix string
autoSuffix bool
outputDirectory string // can be auto-determined from clusterDefinition
forceOverwrite bool
caCertificatePath string
caPrivateKeyPath string
classicMode bool
Expand Down Expand Up @@ -75,6 +76,7 @@ func newDeployCmd() *cobra.Command {
f.StringVar(&dc.caPrivateKeyPath, "ca-private-key-path", "", "path to the CA private key to use for Kubernetes PKI assets")
f.StringVarP(&dc.resourceGroup, "resource-group", "g", "", "resource group to deploy to")
f.StringVarP(&dc.location, "location", "l", "", "location to deploy to")
f.BoolVarP(&dc.forceOverwrite, "force-overwrite", "f", false, "automatically overwrite existing files in the output directory")

addAuthFlags(&dc.authArgs, f)

Expand Down Expand Up @@ -174,6 +176,10 @@ func autofillApimodel(dc *deployCmd) {
dc.outputDirectory = path.Join("_output", dc.containerService.Properties.MasterProfile.DNSPrefix)
}

if _, err := os.Stat(dc.outputDirectory); !dc.forceOverwrite && err == nil {
log.Fatalf(fmt.Sprintf("Output directory already exists and forceOverwrite flag is not set: %s", dc.outputDirectory))
}

if dc.resourceGroup == "" {
dnsPrefix := dc.containerService.Properties.MasterProfile.DNSPrefix
log.Warnf("--resource-group was not specified. Using the DNS prefix from the apimodel as the resource group name: %s", dnsPrefix)
Expand Down
12 changes: 7 additions & 5 deletions docs/kubernetes/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ Run `acs-engine deploy` with the appropriate arguments:
```
$ acs-engine deploy --subscription-id 51ac25de-afdg-9201-d923-8d8e8e8e8e8e \
--dns-prefix contoso-apple --location westus2 \
--auto-suffix --api-model examples/kubernetes.json
--api-model examples/kubernetes.json
WARN[0005] apimodel: missing masterProfile.dnsPrefix will use "contoso-apple-59769a59"
WARN[0005] --resource-group was not specified. Using the DNS prefix from the apimodel as the resource group name: contoso-apple-59769a59
WARN[0005] apimodel: missing masterProfile.dnsPrefix will use "contoso-apple"
WARN[0005] --resource-group was not specified. Using the DNS prefix from the apimodel as the resource group name: contoso-apple
WARN[0008] apimodel: ServicePrincipalProfile was empty, creating application...
WARN[0017] created application with applicationID (7e2d433f-d039-48b8-87dc-83fa4dfa38d4) and servicePrincipalObjectID (db6167e1-aeed-407a-b218-086589759442).
WARN[0017] apimodel: ServicePrincipalProfile was empty, assigning role to application...
INFO[0034] Starting ARM Deployment (contoso-apple-59769a59-1423145182). This will take some time...
INFO[0393] Finished ARM Deployment (contoso-apple-59769a59-1423145182).
INFO[0034] Starting ARM Deployment (contoso-apple-1423145182). This will take some time...
INFO[0393] Finished ARM Deployment (contoso-apple-1423145182).
```

`acs-engine` will output Azure Resource Manager (ARM) templates, SSH keys, and a kubeconfig file in `_output/contoso-apple-59769a59` directory:
Expand All @@ -67,6 +67,8 @@ kubernetes-dashboard is running at https://contoso-apple-59769a59.westus2.clouda
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
```

Administrative note: By default, the directory where acs-engine stores cluster configuration (`_output/contoso-apple` above) won't be overwritten as a result of subsequent attempts to deploy a cluster using the same `--dns-prefix`) To re-use the same resource group name repeatedly, include the `--force-overwrite` command line option with your `acs-engine deploy` command. On a related note, include an `--auto-suffix` option to append a randomly generated suffix to the dns-prefix to form the resource group name, for example if your workflow requires a common prefix across multiple cluster deployments. Using the `--auto-suffix` pattern appends a compressed timestamp to ensure a unique cluster name (and thus ensure that each deployment's configuration artifacts will be stored locally under a discrete `_output/<resource-group-name>/` directory).

**Note**: If the cluster is using an existing VNET please see the [Custom VNET](features.md#feat-custom-vnet) feature documentation for additional steps that must be completed after cluster provisioning.

<a href="#the-long-way"></a>
Expand Down

0 comments on commit 45e4a22

Please sign in to comment.