Skip to content

[v8] Add lifecycle flag to buildpacks related commands #3496

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

Open
wants to merge 4 commits into
base: v8
Choose a base branch
from
Open
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: 2 additions & 1 deletion actor/actionerror/buildpack_not_found_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import "fmt"
type BuildpackNotFoundError struct {
BuildpackName string
StackName string
Lifecycle string
}

func (e BuildpackNotFoundError) Error() string {
return fmt.Sprintf("Buildpack not found - Name: '%s'; Stack: '%s'", e.BuildpackName, e.StackName)
return fmt.Sprintf("Buildpack not found - Name: '%s'; Stack: '%s', Lifecyle: '%s'", e.BuildpackName, e.StackName, e.Lifecycle)
}
60 changes: 34 additions & 26 deletions actor/v7action/buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,60 @@ type Downloader interface {
Download(url string, tmpDirPath string) (string, error)
}

func (actor Actor) GetBuildpacks(labelSelector string) ([]resources.Buildpack, Warnings, error) {
queries := []ccv3.Query{ccv3.Query{Key: ccv3.OrderBy, Values: []string{ccv3.PositionOrder}}}
func (actor Actor) GetBuildpacks(labelSelector string, lifecycle string) ([]resources.Buildpack, Warnings, error) {
queries := []ccv3.Query{}
if labelSelector != "" {
queries = append(queries, ccv3.Query{Key: ccv3.LabelSelectorFilter, Values: []string{labelSelector}})
}

if lifecycle != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question What happens when specifying this flag against an older CAPI without cloudfoundry/cloud_controller_ng#3898 ? Ideally it should fail gracefully. We may need a guard like https://github.com/cloudfoundry/cli/blob/main/command/v7/push_command.go#L583

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left it at the next patch version for now, will adjust if needed when the version is released

queries = append(queries, ccv3.Query{Key: ccv3.LifecycleFilter, Values: []string{lifecycle}})
}

buildpacks, warnings, err := actor.CloudControllerClient.GetBuildpacks(queries...)

return buildpacks, Warnings(warnings), err
}

// GetBuildpackByNameAndStack returns a buildpack with the provided name and
// stack. If `buildpackStack` is not specified, and there are multiple
// GetBuildpackByNameAndStackAndLifecycle returns a buildpack with the provided name, stack,
// and lifecycle. If `buildpackStack` is not specified, and there are multiple
// buildpacks with the same name, it will return the one with no stack, if
// present.
func (actor Actor) GetBuildpackByNameAndStack(buildpackName string, buildpackStack string) (resources.Buildpack, Warnings, error) {
// present. If `buildpackLifecycle` is not specified and there are multiple buildpacks with
// the same name, it will return the one with the default_app_lifecycle, if present.
func (actor Actor) GetBuildpackByNameAndStackAndLifecycle(buildpackName string, buildpackStack string, buildpackLifecycle string) (resources.Buildpack, Warnings, error) {
var (
buildpacks []resources.Buildpack
warnings ccv3.Warnings
err error
)

if buildpackStack == "" {
buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
queries := []ccv3.Query{{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
}}

if buildpackStack != "" {
queries = append(queries, ccv3.Query{
Key: ccv3.StackFilter,
Values: []string{buildpackStack},
})
} else {
buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(
ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
},
ccv3.Query{
Key: ccv3.StackFilter,
Values: []string{buildpackStack},
},
)
}

if buildpackLifecycle != "" {
queries = append(queries, ccv3.Query{
Key: ccv3.LifecycleFilter,
Values: []string{buildpackLifecycle},
})
}

buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(queries...)

if err != nil {
return resources.Buildpack{}, Warnings(warnings), err
}

if len(buildpacks) == 0 {
return resources.Buildpack{}, Warnings(warnings), actionerror.BuildpackNotFoundError{BuildpackName: buildpackName, StackName: buildpackStack}
return resources.Buildpack{}, Warnings(warnings), actionerror.BuildpackNotFoundError{BuildpackName: buildpackName, StackName: buildpackStack, Lifecycle: buildpackLifecycle}
}

if len(buildpacks) > 1 {
Expand All @@ -87,9 +95,9 @@ func (actor Actor) CreateBuildpack(buildpack resources.Buildpack) (resources.Bui
return buildpack, Warnings(warnings), err
}

func (actor Actor) UpdateBuildpackByNameAndStack(buildpackName string, buildpackStack string, buildpack resources.Buildpack) (resources.Buildpack, Warnings, error) {
func (actor Actor) UpdateBuildpackByNameAndStackAndLifecycle(buildpackName string, buildpackStack string, buildpackLifecycle string, buildpack resources.Buildpack) (resources.Buildpack, Warnings, error) {
var warnings Warnings
foundBuildpack, getWarnings, err := actor.GetBuildpackByNameAndStack(buildpackName, buildpackStack)
foundBuildpack, getWarnings, err := actor.GetBuildpackByNameAndStackAndLifecycle(buildpackName, buildpackStack, buildpackLifecycle)
warnings = append(warnings, getWarnings...)

if err != nil {
Expand Down Expand Up @@ -250,9 +258,9 @@ func Zipit(source, target, prefix string) error {
return err
}

func (actor Actor) DeleteBuildpackByNameAndStack(buildpackName string, buildpackStack string) (Warnings, error) {
func (actor Actor) DeleteBuildpackByNameAndStackAndLifecycle(buildpackName string, buildpackStack string, buildpackLifecycle string) (Warnings, error) {
var allWarnings Warnings
buildpack, getBuildpackWarnings, err := actor.GetBuildpackByNameAndStack(buildpackName, buildpackStack)
buildpack, getBuildpackWarnings, err := actor.GetBuildpackByNameAndStackAndLifecycle(buildpackName, buildpackStack, buildpackLifecycle)
allWarnings = append(allWarnings, getBuildpackWarnings...)
if err != nil {
return allWarnings, err
Expand Down
Loading
Loading