diff --git a/daisy/README.md b/daisy/README.md index 6272e2916..551bcff98 100644 --- a/daisy/README.md +++ b/daisy/README.md @@ -224,7 +224,7 @@ the Disk JSON representation. Daisy uses the same representation with a few modi | Field Name | Type | Description of Modification | | - | - | - | -| Name | string | If ExactName is false, the **literal** disk name will have a generated suffix for the running instance of the workflow. | +| Name | string | If RealName is unset, the **literal** disk name will have a generated suffix for the running instance of the workflow. | | SourceImage | string | Either image [partial URLs](#glossary-partialurl) or workflow-internal image names are valid. | | Type | string | *Optional.* Defaults to "pd-standard". Either disk type [partial URLs](#glossary-partialurl) or disk type names are valid. | @@ -235,7 +235,7 @@ Added fields: | Project | string | *Optional.* Defaults to workflow's Project. The GCP project in which to create the disk. | | Zone | string | *Optional.* Defaults to workflow's Zone. The GCE zone in which to create the disk. | | NoCleanup | bool | *Optional.* Defaults to false. Set this to true if you do not want Daisy to automatically delete this disk when the workflow terminates. | -| ExactName | bool | *Optional.* Defaults to false. Set this to true if you want Daisy to name this GCE disk exactly the same as Name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | +| RealName | bool | *Optional.* If set Daisy will use this as the resource name instead generating a name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | Example: the first is a standard PD disk created from a source image, the second is a blank PD SSD. @@ -261,7 +261,7 @@ the Image JSON representation. Daisy uses the same representation with a few mod | Field Name | Type | Description of Modification | | - | - | - | -| Name | string | If ExactName is false, the **literal** image name will have a generated suffix for the running instance of the workflow. | +| Name | string | If RealName is unset, the **literal** image name will have a generated suffix for the running instance of the workflow. | | RawDisk.Source | string | Either a GCS Path or a key from Sources are valid. | | SourceDisk | string | Either disk [partial URLs](#glossary-partialurl) or workflow-internal disk names are valid. | @@ -271,7 +271,7 @@ Added fields: | - | - | - | | Project | string | *Optional.* Defaults to the workflow Project. The GCP project in which to create this image. | | NoCleanup | bool | *Optional.* Defaults to false. Set this to true if you do not want Daisy to automatically delete this image when the workflow terminates. | -| ExactName | bool | *Optional.* Defaults to false. Set this to true if you want Daisy to name this GCE image exactly the same as Name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | +| RealName | bool | *Optional.* If set Daisy will use this as the resource name instead generating a name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | This CreateImages example creates an image from a source disk. ```json @@ -288,7 +288,7 @@ This CreateImages example creates an image from a source disk. This CreateImages example creates three images. `image1` is created from a source from the workflow's `Sources` and will not be cleaned up by Daisy. `image2` is created from a source from a GCS Path and will use -the exact name, "image2". Lastly, `image3` is created from a disk from +`my-image2` as the resource name. Lastly, `image3` is created from a disk from the workflow and will be created in a different project from the workflow's specified Project. ```json @@ -306,7 +306,7 @@ workflow's specified Project. "RawDisk": { "Source": "gs://my-bucket/image.tar.gz" }, - "ExactName": true + "RealName": "my-image2" }, { "Name": "image3", @@ -323,7 +323,7 @@ the Instance JSON representation. Daisy uses the same representation with a few | Field Name | Type | Description of Modification | | - | - | - | -| Name | string | If ExactName is false, the **literal** instance name will have a generated suffix for the running instance of the workflow. | +| Name | string | If RealName is unset, the **literal** instance name will have a generated suffix for the running instance of the workflow. | | Disks[].Boot | bool | *Now unused.* First disk automatically has boot = true. All others are set to false. | | Disks[].InitializeParams.DiskType | string | *Optional.* Will prepend "projects/PROJECT/zones/ZONE/diskTypes/" as needed. This allows user to provide "pd-ssd" or "pd-standard" as the DiskType. | | Disks[].InitializeParams.SourceImage | string | Either image [partial URLs](#glossary-partialurl) or workflow-internal image names are valid. | @@ -344,7 +344,7 @@ Added fields: | Project | string | *Optional.* Defaults to workflow's Project. The GCP project in which to create the disk. | | Zone | string | *Optional.* Defaults to workflow's Zone. The GCE zone in which to create the disk. | | NoCleanup | bool | *Optional.* Defaults to false. Set this to true if you do not want Daisy to automatically delete this disk when the workflow terminates. | -| ExactName | bool | *Optional.* Defaults to false. Set this to true if you want Daisy to name this GCE disk exactly the same as Name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | +| RealName | bool | *Optional.* If set Daisy will use this as the resource name instead generating a name. **Be advised**: this circumvents Daisy's efforts to prevent resource name collisions. | This CreateInstances step example creates an instance with two attached disks, with machine type n1-standard-4, and with metadata "key" = "value". diff --git a/daisy/step_create_disks.go b/daisy/step_create_disks.go index fabfb5dd8..4d810fa15 100644 --- a/daisy/step_create_disks.go +++ b/daisy/step_create_disks.go @@ -40,12 +40,13 @@ type CreateDisk struct { Project string `json:",omitempty"` // Should this resource be cleaned up after the workflow? NoCleanup bool - // Should we use the user-provided reference name as the actual - // resource name? - ExactName bool + // If set Daisy will use this as the resource name instead generating a name. + RealName string `json:",omitempty"` // The name of the disk as known internally to Daisy. daisyName string + // Deprecated: Use RealName instead. + ExactName bool } // MarshalJSON is a hacky workaround to prevent CreateDisk from using @@ -57,8 +58,13 @@ func (c *CreateDisk) MarshalJSON() ([]byte, error) { func (c *CreateDisks) populate(ctx context.Context, s *Step) error { for _, cd := range *c { cd.daisyName = cd.Name - if !cd.ExactName { - cd.Name = s.w.genName(cd.daisyName) + if cd.ExactName && cd.RealName == "" { + cd.RealName = cd.Name + } + if cd.RealName != "" { + cd.Name = cd.RealName + } else { + cd.Name = s.w.genName(cd.Name) } cd.Project = strOr(cd.Project, s.w.Project) cd.Zone = strOr(cd.Zone, s.w.Zone) diff --git a/daisy/step_create_disks_test.go b/daisy/step_create_disks_test.go index fd9e24e55..abe93f40f 100644 --- a/daisy/step_create_disks_test.go +++ b/daisy/step_create_disks_test.go @@ -54,7 +54,13 @@ func TestCreateDisksPopulate(t *testing.T) { { "ExactName case", &CreateDisk{Disk: compute.Disk{Name: "foo"}, ExactName: true}, - &CreateDisk{Disk: compute.Disk{Name: "foo", Type: defType}, daisyName: "foo", Project: w.Project, Zone: w.Zone, ExactName: true}, + &CreateDisk{Disk: compute.Disk{Name: "foo", Type: defType}, daisyName: "foo", Project: w.Project, Zone: w.Zone, ExactName: true, RealName: "foo"}, + false, + }, + { + "RealName case", + &CreateDisk{Disk: compute.Disk{Name: "foo"}, RealName: "foo-foo"}, + &CreateDisk{Disk: compute.Disk{Name: "foo-foo", Type: defType}, daisyName: "foo", Project: w.Project, Zone: w.Zone, RealName: "foo-foo"}, false, }, { diff --git a/daisy/step_create_images.go b/daisy/step_create_images.go index 17992f088..6fe5a5619 100644 --- a/daisy/step_create_images.go +++ b/daisy/step_create_images.go @@ -37,12 +37,13 @@ type CreateImage struct { Project string `json:",omitempty"` // Should this resource be cleaned up after the workflow? NoCleanup bool - // Should we use the user-provided reference name as the actual - // resource name? - ExactName bool + // If set Daisy will use this as the resource name instead generating a name. + RealName string `json:",omitempty"` // The name of the disk as known internally to Daisy. daisyName string + // Deprecated: Use RealName instead. + ExactName bool } // MarshalJSON is a hacky workaround to prevent CreateImage from using @@ -58,8 +59,13 @@ func (c *CreateImages) populate(ctx context.Context, s *Step) error { for _, ci := range *c { // Prepare field values: name, Name, RawDisk.Source, Description ci.daisyName = ci.Name - if !ci.ExactName { - ci.Name = s.w.genName(ci.daisyName) + if ci.ExactName && ci.RealName == "" { + ci.RealName = ci.Name + } + if ci.RealName != "" { + ci.Name = ci.RealName + } else { + ci.Name = s.w.genName(ci.Name) } ci.Project = strOr(ci.Project, s.w.Project) ci.Description = strOr(ci.Description, fmt.Sprintf("Image created by Daisy in workflow %q on behalf of %s.", s.w.Name, s.w.username)) diff --git a/daisy/step_create_instances.go b/daisy/step_create_instances.go index 03af0a097..43562044b 100644 --- a/daisy/step_create_instances.go +++ b/daisy/step_create_instances.go @@ -41,7 +41,6 @@ type CreateInstance struct { // OAuth2 scopes to give the instance. If none are specified // https://www.googleapis.com/auth/devstorage.read_only will be added. Scopes []string `json:",omitempty"` - // StartupScript is the Sources path to a startup script to use in this step. // This will be automatically mapped to the appropriate metadata key. StartupScript string `json:",omitempty"` @@ -51,11 +50,13 @@ type CreateInstance struct { Zone string `json:",omitempty"` // Should this resource be cleaned up after the workflow? NoCleanup bool - // Should we use the user-provided reference name as the actual resource name? - ExactName bool + // If set Daisy will use this as the resource name instead generating a name. + RealName string `json:",omitempty"` // The name of the disk as known internally to Daisy. daisyName string + // Deprecated: Use RealName instead. + ExactName bool } // MarshalJSON is a hacky workaround to prevent CreateInstance from using @@ -222,7 +223,12 @@ func (c *CreateInstances) populate(ctx context.Context, s *Step) error { for _, ci := range *c { // General fields preprocessing. ci.daisyName = ci.Name - if !ci.ExactName { + if ci.ExactName && ci.RealName == "" { + ci.RealName = ci.Name + } + if ci.RealName != "" { + ci.Name = ci.RealName + } else { ci.Name = s.w.genName(ci.Name) } ci.Project = strOr(ci.Project, s.w.Project) diff --git a/daisy/step_create_instances_test.go b/daisy/step_create_instances_test.go index 76e838fcd..405dc82ad 100644 --- a/daisy/step_create_instances_test.go +++ b/daisy/step_create_instances_test.go @@ -124,17 +124,17 @@ func TestCreateInstancePopulate(t *testing.T) { "nondefault zone/project case", &CreateInstance{ Instance: compute.Instance{Name: "foo", Description: desc, Disks: []*compute.AttachedDisk{{Source: "foo"}}}, - Project: "pfoo", Zone: "zfoo", ExactName: true, + Project: "pfoo", Zone: "zfoo", RealName: "inst-pfoo", }, &CreateInstance{ Instance: compute.Instance{ - Name: "foo", Description: desc, + Name: "inst-pfoo", Description: desc, Disks: []*compute.AttachedDisk{{Boot: true, Source: "foo", Mode: defDM}}, MachineType: "projects/pfoo/zones/zfoo/machineTypes/n1-standard-1", NetworkInterfaces: []*compute.NetworkInterface{{Network: "projects/pfoo/global/networks/default", AccessConfigs: defAcs}}, ServiceAccounts: defSAs, }, - Metadata: defMD, Scopes: defSs, Project: "pfoo", Zone: "zfoo", daisyName: "foo", ExactName: true, + Metadata: defMD, Scopes: defSs, Project: "pfoo", Zone: "zfoo", daisyName: "foo", RealName: "inst-pfoo", }, false, },