From 45e4a225f91da73c2b997eadf0b5e47b6a514b60 Mon Sep 17 00:00:00 2001 From: Mark Gerrits Date: Wed, 11 Apr 2018 01:56:15 +0200 Subject: [PATCH] [feature] Prevent overwriting existing cluster resources in output directories (#2581) * Prevent overwriting existing folder when using the deploy command --- cmd/deploy.go | 6 ++++++ docs/kubernetes/deploy.md | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 1ff4b0bc7a..87d9b63e49 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -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 @@ -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) @@ -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) diff --git a/docs/kubernetes/deploy.md b/docs/kubernetes/deploy.md index b6bd6843ed..734fd7cdd5 100644 --- a/docs/kubernetes/deploy.md +++ b/docs/kubernetes/deploy.md @@ -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: @@ -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//` 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.