Skip to content

Commit

Permalink
add labels to lantern resources
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed May 5, 2024
1 parent fa00159 commit d0b3794
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
9 changes: 9 additions & 0 deletions migrate/20240505_lantern_resource_label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

Sequel.migration do
change do
alter_table(:lantern_resource) do
add_column :label, :text, null: true
end
end
end
6 changes: 4 additions & 2 deletions prog/lantern/lantern_resource_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Prog::Lantern::LanternResourceNexus < Prog::Base

def self.assemble(project_id:, location:, name:, target_vm_size:, target_storage_size_gib:, ha_type: LanternResource::HaType::NONE, parent_id: nil, restore_target: nil,
org_id: nil, db_name: "postgres", db_user: "postgres", db_user_password: nil, superuser_password: nil, repl_password: nil, app_env: Config.rack_env,
lantern_version: Config.lantern_default_version, extras_version: Config.lantern_extras_default_version, minor_version: Config.lantern_minor_default_version, domain: nil, enable_debug: false)
lantern_version: Config.lantern_default_version, extras_version: Config.lantern_extras_default_version, minor_version: Config.lantern_minor_default_version, domain: nil, enable_debug: false,
label: "")
unless (project = Project[project_id])
fail "No existing project"
end
Expand Down Expand Up @@ -77,7 +78,8 @@ def self.assemble(project_id:, location:, name:, target_vm_size:, target_storage
project_id: project_id, location: location, name: name, org_id: org_id, app_env: app_env,
superuser_password: superuser_password, ha_type: ha_type, parent_id: parent_id,
restore_target: restore_target, db_name: db_name, db_user: db_user,
db_user_password: db_user_password, repl_user: repl_user, repl_password: repl_password
db_user_password: db_user_password, repl_user: repl_user, repl_password: repl_password,
label: label
) { _1.id = ubid.to_uuid }
lantern_resource.associate_with_project(project)

Expand Down
1 change: 1 addition & 0 deletions routes/web/project/lantern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CloverWeb
project_id: @project.id,
location: r.params["location"],
name: r.params["name"],
label: r.params["label"],
org_id: r.params["org_id"],
target_vm_size: parsed_size.vm_size,
target_storage_size_gib: parsed_size.storage_size_gib,
Expand Down
1 change: 1 addition & 0 deletions serializers/web/lantern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.base(pg)
ubid: pg.ubid,
path: pg.path,
name: pg.name,
label: pg.label,
state: pg.display_state,
primary?: pg.representative_server&.primary?,
instance_type: pg.representative_server&.instance_type,
Expand Down
23 changes: 22 additions & 1 deletion spec/routes/web/project/lantern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,33 @@
location: "us-central1",
name: "instance-2",
target_vm_size: "n1-standard-2",
label: "test",
target_storage_size_gib: 100,
org_id: 0
)

visit "#{project.path}/lantern"

expect(page.title).to eq("Ubicloud - Lantern Databases")
expect(page).to have_content "instance-2"
expect(page).to have_content "instance-2 (test)"
end

it "show no-label if no label was specified" do
Prog::Lantern::LanternResourceNexus.assemble(
project_id: project.id,
location: "us-central1",
name: "instance-4",
target_vm_size: "n1-standard-2",
target_storage_size_gib: 100,
org_id: 0
)

LanternResource[name: "instance-4"].update(label: nil)

visit "#{project.path}/lantern"

expect(page.title).to eq("Ubicloud - Lantern Databases")
expect(page).to have_content "instance-4 (no-label)"
end
end

Expand All @@ -87,6 +106,7 @@
expect(page.title).to eq("Ubicloud - Create Lantern Database")
name = "new-pg-db"
fill_in "Name", with: name
fill_in "Label", with: "test-label"
choose option: "us-central1"
choose option: "n1-standard-2"
find_by_id("parent_id").find(:xpath, "option[1]").select_option
Expand All @@ -97,6 +117,7 @@
expect(page).to have_content "'#{name}' will be ready in a few minutes"
expect(LanternResource.count).to eq(1)
expect(LanternResource.first.projects.first.id).to eq(project.id)
expect(LanternResource.first.label).to eq("test-label")
end

it "can create new Lantern database with domain" do
Expand Down
13 changes: 13 additions & 0 deletions views/lantern/create.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
}
) %>
</div>
<div class="sm:col-span-3">
<%== render(
"components/form/text",
locals: {
name: "label",
label: "Label",
attributes: {
required: false,
placeholder: "Enter label"
}
}
) %>
</div>
<div class="sm:col-span-3">
<%== render(
"components/form/text",
Expand Down
2 changes: 1 addition & 1 deletion views/lantern/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<tbody class="divide-y divide-gray-200 bg-white">
<% @lantern_databases.each do |pg| %>
<tr>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6" scope="row"><%= pg[:name] %></td>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6" scope="row"><%= pg[:name] %> (<%= (!pg[:label] || pg[:label].empty?) ? "no-label" : pg[:label] %>)</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"><%= pg[:location] %></td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%== render("components/pg_state_label", locals: { state: pg[:state] }) %>
Expand Down
1 change: 1 addition & 0 deletions views/lantern/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<% data = [
["ID", @pg[:ubid]],
["Name", @pg[:name]],
["Label", @pg[:label]],
["Org Id", @pg[:org_id]],
["Instance Type", @pg[:instance_type]],
["Lantern Version", @pg[:lantern_version]],
Expand Down

0 comments on commit d0b3794

Please sign in to comment.