From 682628d8c4a1e3cf0d363b5a585be724809f30f5 Mon Sep 17 00:00:00 2001 From: Johannes Dillmann Date: Mon, 4 Nov 2024 16:03:50 +0100 Subject: [PATCH] Ensure CAPI version when using CNB lifecycle Co-authored-by: Ralf Pannemans --- api/cloudcontroller/ccversion/minimum_version.go | 2 ++ command/v7/create_app_command.go | 7 +++++++ command/v7/create_app_command_test.go | 2 ++ command/v7/push_command.go | 7 ++++++- integration/v7/isolated/app_command_test.go | 2 ++ integration/v7/isolated/create_app_command_test.go | 2 ++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api/cloudcontroller/ccversion/minimum_version.go b/api/cloudcontroller/ccversion/minimum_version.go index 5158ab18f06..a0092171205 100644 --- a/api/cloudcontroller/ccversion/minimum_version.go +++ b/api/cloudcontroller/ccversion/minimum_version.go @@ -15,4 +15,6 @@ const ( MinVersionSpaceSupporterV3 = "3.104.0" MinVersionLogRateLimitingV3 = "3.124.0" // TODO: update this when we have a CAPI release + + MinVersionCNB = "3.168.0" ) diff --git a/command/v7/create_app_command.go b/command/v7/create_app_command.go index 9b8a1e35baf..a4e034cd6db 100644 --- a/command/v7/create_app_command.go +++ b/command/v7/create_app_command.go @@ -6,6 +6,8 @@ import ( "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" + "code.cloudfoundry.org/cli/command" "code.cloudfoundry.org/cli/command/flag" "code.cloudfoundry.org/cli/resources" ) @@ -47,6 +49,11 @@ func (cmd CreateAppCommand) Execute(args []string) error { } if constant.AppLifecycleType(cmd.AppType) == constant.AppLifecycleTypeCNB { + err := command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCNB) + if err != nil { + return err + } + if len(cmd.Buildpacks) == 0 { return errors.New("buildpack(s) must be provided when using --app-type cnb") } diff --git a/command/v7/create_app_command_test.go b/command/v7/create_app_command_test.go index a1b6cec95fa..2420d8ad401 100644 --- a/command/v7/create_app_command_test.go +++ b/command/v7/create_app_command_test.go @@ -132,6 +132,7 @@ var _ = Describe("create-app Command", func() { fakeConfig.CNBCredentialsReturns(map[string]interface{}{ "foo": "bar", }, nil) + fakeConfig.APIVersionReturns("3.168.0") }) It("creates an app with app type: cnb", func() { @@ -198,6 +199,7 @@ var _ = Describe("create-app Command", func() { Context("due to missing buildpacks when AppType is cnb", func() { BeforeEach(func() { cmd.AppType = "cnb" + fakeConfig.APIVersionReturns("3.168.0") }) It("displays the header and error", func() { diff --git a/command/v7/push_command.go b/command/v7/push_command.go index 85a0af77740..af604ceadbf 100644 --- a/command/v7/push_command.go +++ b/command/v7/push_command.go @@ -16,6 +16,7 @@ import ( "code.cloudfoundry.org/cli/actor/v7pushaction" "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" "code.cloudfoundry.org/cli/api/logcache" "code.cloudfoundry.org/cli/cf/errors" "code.cloudfoundry.org/cli/command" @@ -107,7 +108,6 @@ type PushCommand struct { PathsToVarsFiles []flag.PathWithExistenceCheck `long:"vars-file" description:"Path to a variable substitution file for manifest; can specify multiple times"` Lifecycle constant.AppLifecycleType `long:"lifecycle" description:"App lifecycle type to stage and run the app" default:""` dockerPassword interface{} `environmentName:"CF_DOCKER_PASSWORD" environmentDescription:"Password used for private docker repository"` - cnbCredentials interface{} `environmentName:"CNB_REGISTRY_CREDS" environmentDescription:"Credentials for pulling Cloud Native Buildpacks from private registries"` usage interface{} `usage:"CF_NAME push APP_NAME [-b BUILDPACK_NAME]\n [-c COMMAND] [-f MANIFEST_PATH | --no-manifest] [--lifecycle (buildpack | docker | cnb)] [--no-start] [--no-wait] [-i NUM_INSTANCES]\n [-k DISK] [-m MEMORY] [-l LOG_RATE_LIMIT] [-p PATH] [-s STACK] [-t HEALTH_TIMEOUT] [--task TASK]\n [-u (process | port | http)] [--no-route | --random-route]\n [--var KEY=VALUE] [--vars-file VARS_FILE_PATH]...\n \n CF_NAME push APP_NAME --docker-image [REGISTRY_HOST:PORT/]IMAGE[:TAG] [--docker-username USERNAME]\n [-c COMMAND] [-f MANIFEST_PATH | --no-manifest] [--no-start] [--no-wait] [-i NUM_INSTANCES]\n [-k DISK] [-m MEMORY] [-l LOG_RATE_LIMIT] [-p PATH] [-s STACK] [-t HEALTH_TIMEOUT] [--task TASK]\n [-u (process | port | http)] [--no-route | --random-route ]\n [--var KEY=VALUE] [--vars-file VARS_FILE_PATH]..."` envCFStagingTimeout interface{} `environmentName:"CF_STAGING_TIMEOUT" environmentDescription:"Max wait time for staging, in minutes" environmentDefault:"15"` envCFStartupTimeout interface{} `environmentName:"CF_STARTUP_TIMEOUT" environmentDescription:"Max wait time for app instance startup, in minutes" environmentDefault:"5"` @@ -166,6 +166,11 @@ func (cmd PushCommand) Execute(args []string) error { return err } + err = command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCNB) + if flagOverrides.Lifecycle != "" && err != nil { + return err + } + err = cmd.ValidateFlags() if err != nil { return err diff --git a/integration/v7/isolated/app_command_test.go b/integration/v7/isolated/app_command_test.go index 6da99a57cca..967ea83179b 100644 --- a/integration/v7/isolated/app_command_test.go +++ b/integration/v7/isolated/app_command_test.go @@ -6,6 +6,7 @@ import ( "path" "path/filepath" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" "code.cloudfoundry.org/cli/integration/helpers" . "github.com/onsi/ginkgo/v2" @@ -409,6 +410,7 @@ applications: When("the app is a CNB app", func() { BeforeEach(func() { + helpers.SkipIfVersionLessThan(ccversion.MinVersionCNB) helpers.WithJSHelloWorld(func(appDir string) { Eventually(helpers.CF("push", appName, "-p", appDir, "--lifecycle", "cnb", "-b", "docker://gcr.io/paketo-buildpacks/nodejs:latest")).Should(Exit()) }) diff --git a/integration/v7/isolated/create_app_command_test.go b/integration/v7/isolated/create_app_command_test.go index 680891fe5a8..1bd6afdfcc3 100644 --- a/integration/v7/isolated/create_app_command_test.go +++ b/integration/v7/isolated/create_app_command_test.go @@ -1,6 +1,7 @@ package isolated import ( + "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" "code.cloudfoundry.org/cli/integration/helpers" . "github.com/onsi/ginkgo/v2" @@ -107,6 +108,7 @@ var _ = Describe("create-app command", func() { }) It("creates the app with the cnb app type", func() { + helpers.SkipIfVersionLessThan(ccversion.MinVersionCNB) session := helpers.CF("create-app", appName, "--app-type", "cnb", "-b", "docker://foobar.test") userName, _ := helpers.GetCredentials() Eventually(session).Should(Say("Creating app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))