From 72b2f4461a6d8632f587603e4459ecc02ad53d2e Mon Sep 17 00:00:00 2001 From: i343759 Date: Thu, 9 Apr 2026 11:45:22 +0300 Subject: [PATCH] Fix switchblade Initialize() multi-stack buildpack deletion When multiple buildpacks share the same name across different stacks (e.g. ruby_buildpack for cflinuxfs4 and cflinuxfs5), cf delete-buildpack requires -s to disambiguate. Without it, the command fails with: 'Multiple buildpacks named ruby_buildpack found. Specify a stack name by using a -s flag.' Parse the stack field from the /v3/buildpacks API response and iterate over all resources, deleting each with the appropriate -s flag. This fixes the CF integration test failure in Initialize() when both cflinuxfs4 and cflinuxfs5 stacks are deployed. --- .../internal/cloudfoundry/initialize.go | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/initialize.go b/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/initialize.go index dc7f18d00..3ad043215 100644 --- a/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/initialize.go +++ b/vendor/github.com/cloudfoundry/switchblade/internal/cloudfoundry/initialize.go @@ -43,7 +43,8 @@ func (i Initialize) Run(buildpacks []Buildpack) error { if err == nil { var payload struct { Resources []struct { - Position int `json:"position"` + Position int `json:"position"` + Stack string `json:"stack"` } `json:"resources"` } err = json.NewDecoder(buffer).Decode(&payload) @@ -55,13 +56,19 @@ func (i Initialize) Run(buildpacks []Buildpack) error { position = strconv.Itoa(payload.Resources[0].Position) } - err = i.cli.Execute(pexec.Execution{ - Args: []string{"delete-buildpack", "-f", buildpack.Name}, - Stdout: logs, - Stderr: logs, - }) - if err != nil { - return fmt.Errorf("failed to delete buildpack: %s\n\nOutput:\n%s", err, logs) + for _, resource := range payload.Resources { + args := []string{"delete-buildpack", "-f", buildpack.Name} + if resource.Stack != "" { + args = append(args, "-s", resource.Stack) + } + err = i.cli.Execute(pexec.Execution{ + Args: args, + Stdout: logs, + Stderr: logs, + }) + if err != nil { + return fmt.Errorf("failed to delete buildpack: %s\n\nOutput:\n%s", err, logs) + } } }