Skip to content

Commit

Permalink
Create "RealName" field, deprecate "ExactName" on Create* steps. (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
adjackura authored Sep 13, 2017
1 parent 5b46b47 commit 6a11608
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
16 changes: 8 additions & 8 deletions daisy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand All @@ -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.
Expand All @@ -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. |

Expand All @@ -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
Expand All @@ -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
Expand All @@ -306,7 +306,7 @@ workflow's specified Project.
"RawDisk": {
"Source": "gs://my-bucket/image.tar.gz"
},
"ExactName": true
"RealName": "my-image2"
},
{
"Name": "image3",
Expand All @@ -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. |
Expand All @@ -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".
Expand Down
16 changes: 11 additions & 5 deletions daisy/step_create_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion daisy/step_create_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down
16 changes: 11 additions & 5 deletions daisy/step_create_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
14 changes: 10 additions & 4 deletions daisy/step_create_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions daisy/step_create_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 6a11608

Please sign in to comment.