Skip to content

Commit

Permalink
Ensure CAPI version when using CNB lifecycle
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Pannemans <[email protected]>
  • Loading branch information
modulo11 and c0d1ngm0nk3y committed Nov 5, 2024
1 parent f968a40 commit 682628d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/cloudcontroller/ccversion/minimum_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
7 changes: 7 additions & 0 deletions command/v7/create_app_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions command/v7/create_app_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion command/v7/push_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions integration/v7/isolated/app_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
})
Expand Down
2 changes: 2 additions & 0 deletions integration/v7/isolated/create_app_command_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 682628d

Please sign in to comment.