Skip to content

Commit

Permalink
Allow cnb apps to be retrieved (#3995)
Browse files Browse the repository at this point in the history
  • Loading branch information
modulo11 authored Sep 27, 2024
1 parent 152f5a0 commit f917ee2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
15 changes: 13 additions & 2 deletions app/fetchers/app_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@ def filter(message, dataset)
end

if message.requested?(:lifecycle_type)
if message.lifecycle_type == BuildpackLifecycleDataModel::LIFECYCLE_TYPE
case message.lifecycle_type
when BuildpackLifecycleDataModel::LIFECYCLE_TYPE
dataset = dataset.where(
guid: BuildpackLifecycleDataModel.
where(Sequel.~(app_guid: nil)).
select(:app_guid)
)
elsif message.lifecycle_type == DockerLifecycleDataModel::LIFECYCLE_TYPE
when DockerLifecycleDataModel::LIFECYCLE_TYPE
dataset = dataset.exclude(
guid: BuildpackLifecycleDataModel.
where(Sequel.~(app_guid: nil)).
select(:app_guid)
).exclude(
guid: CNBLifecycleDataModel.
where(Sequel.~(app_guid: nil)).
select(:app_guid)
)
when CNBLifecycleDataModel::LIFECYCLE_TYPE
dataset = dataset.where(
guid: CNBLifecycleDataModel.
where(Sequel.~(app_guid: nil)).
select(:app_guid)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/messages/base_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class LifecycleTypeParamValidator < ActiveModel::Validator
def validate(record)
return unless record.requested?(:lifecycle_type)

valid_lifecycle_types = [BuildpackLifecycleDataModel::LIFECYCLE_TYPE, DockerLifecycleDataModel::LIFECYCLE_TYPE]
valid_lifecycle_types = [BuildpackLifecycleDataModel::LIFECYCLE_TYPE, DockerLifecycleDataModel::LIFECYCLE_TYPE, CNBLifecycleDataModel::LIFECYCLE_TYPE]
return if valid_lifecycle_types.include?(record.lifecycle_type)

record.errors.add(:base, message: "Invalid lifecycle_type: '#{record.lifecycle_type}'")
Expand Down
4 changes: 3 additions & 1 deletion lib/cloud_controller/diego/task_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def build

task_env = task_env.merge('VCAP_PLATFORM_OPTIONS' => credhub_url) if credhub_url.present? && cred_interpolation_enabled?

task_env = task_env.merge('LANG' => DEFAULT_LANG) if app.lifecycle_type == BuildpackLifecycleDataModel::LIFECYCLE_TYPE
if app.lifecycle_type == BuildpackLifecycleDataModel::LIFECYCLE_TYPE || app.lifecycle_type == CNBLifecycleDataModel::LIFECYCLE_TYPE
task_env = task_env.merge('LANG' => DEFAULT_LANG)
end
task_env = task_env.merge('DATABASE_URL' => app.database_uri) if app.database_uri

task_env
Expand Down
12 changes: 11 additions & 1 deletion spec/unit/fetchers/app_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ module VCAP::CloudController
end

context 'when a lifecycle_type is provided' do
let!(:docker_app) { AppModel.make(name: 'docker-app', space_guid: space.guid) }
let!(:docker_app) { AppModel.make(:docker, name: 'docker-app', space_guid: space.guid) }
let!(:cnb_app) { AppModel.make(:cnb, name: 'cnb-app', space_guid: space.guid) }

before do
docker_app.buildpack_lifecycle_data = nil
docker_app.save
cnb_app.save
end

context 'of type buildpack' do
Expand All @@ -183,6 +185,14 @@ module VCAP::CloudController
end
end

context 'of type cnb' do
let(:filters) { { lifecycle_type: 'cnb' } }

it 'returns all of the cnb apps' do
expect(apps.all).to contain_exactly(cnb_app)
end
end

context 'of type docker' do
let(:filters) { { lifecycle_type: 'docker' } }

Expand Down
9 changes: 9 additions & 0 deletions spec/unit/lib/cloud_controller/diego/task_environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ module VCAP::CloudController::Diego
end
end

context 'when the task is for a cnb app' do
let(:app) { VCAP::CloudController::AppModel.make(:cnb) }

it 'sets the LANG environment variable' do
constructed_envs = TaskEnvironment.new(app, task, space).build
expect(constructed_envs).to include('LANG' => 'en_US.UTF-8')
end
end

context 'when the app has a route associated with it' do
let(:expected_vcap_application) do
{
Expand Down
8 changes: 7 additions & 1 deletion spec/unit/messages/base_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,18 @@ def self.model_name
end
end

it 'is valid with an allowed lifecycle_type value' do
it 'is valid with docker lifecycle_type value' do
message = fake_class.new({ lifecycle_type: 'docker' })

expect(message).to be_valid
end

it 'is valid with cnb lifecycle_type value' do
message = fake_class.new({ lifecycle_type: 'cnb' })

expect(message).to be_valid
end

it 'is NOT valid with not allowed lifecycle_type value' do
message = fake_class.new({ lifecycle_type: 'stuff' })

Expand Down

0 comments on commit f917ee2

Please sign in to comment.