Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CurrentDropletGUID attribute to application resource [main] #3354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/cloudcontroller/ccv3/constant/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ const (

// RelationshipTypeQuota is a relationship with a Cloud Controller quota (org quota or space quota).
RelationshipTypeQuota RelationshipType = "quota"

// RelationshipTypeCurrentDroplet is a relationship with a Droplet.
RelationshipTypeCurrentDroplet RelationshipType = "current_droplet"
)
15 changes: 12 additions & 3 deletions resources/application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Application struct {
State constant.ApplicationState
// Credentials are used by Cloud Native Buildpacks lifecycle to pull buildpacks
Credentials map[string]interface{}
// CurrentDropletGUID is the unique identifier of the droplet currently attached to the application.
CurrentDropletGUID string
}

// ApplicationNameOnly represents only the name field of a Cloud Controller V3 Application
Expand All @@ -42,10 +44,14 @@ func (a Application) MarshalJSON() ([]byte, error) {
Metadata: a.Metadata,
}

ccApp.Relationships = Relationships{}

if a.SpaceGUID != "" {
ccApp.Relationships = Relationships{
constant.RelationshipTypeSpace: Relationship{GUID: a.SpaceGUID},
}
ccApp.Relationships[constant.RelationshipTypeSpace] = Relationship{GUID: a.SpaceGUID}
}

if a.CurrentDropletGUID != "" {
ccApp.Relationships[constant.RelationshipTypeCurrentDroplet] = Relationship{GUID: a.CurrentDropletGUID}
}

if a.LifecycleType == constant.AppLifecycleTypeDocker {
Expand Down Expand Up @@ -81,6 +87,9 @@ func (a *Application) UnmarshalJSON(data []byte) error {
a.LifecycleType = lifecycle.Type
a.Name = ccApp.Name
a.SpaceGUID = ccApp.Relationships[constant.RelationshipTypeSpace].GUID
if _, ok := ccApp.Relationships[constant.RelationshipTypeCurrentDroplet]; ok {
a.CurrentDropletGUID = ccApp.Relationships[constant.RelationshipTypeCurrentDroplet].GUID
}
a.State = ccApp.State
a.Metadata = ccApp.Metadata

Expand Down
Loading