Skip to content

Commit

Permalink
First pass at dropping vip
Browse files Browse the repository at this point in the history
- migration is bad based on failing tests around "no undo"
  • Loading branch information
moleske committed Apr 21, 2024
1 parent 337bf71 commit 91bd57d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 54 deletions.
45 changes: 0 additions & 45 deletions app/models/runtime/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module VCAP::CloudController
class Route < Sequel::Model
class InvalidOrganizationRelation < CloudController::Errors::InvalidRelation; end

class OutOfVIPException < CloudController::Errors::InvalidRelation; end

many_to_one :domain
many_to_one :space, after_set: :validate_changed_space
one_through_one :organization, join_table: Space.table_name, left_key: :id, left_primary_key: :space_id, right_primary_key: :id, right_key: :organization_id
Expand Down Expand Up @@ -109,7 +107,6 @@ def validate
validate_total_routes
validate_ports
validate_total_reserved_route_ports if port && port > 0
errors.add(:name, :vip_offset) if vip_offset_exceeds_range?

RouteValidator.new(self).validate
rescue RoutingApi::UaaUnavailable
Expand Down Expand Up @@ -191,59 +188,17 @@ def internal?
domain.internal
end

def vip
vip_offset && internal_route_vip_range.nth(vip_offset).to_s
end

def wildcard_host?
host == '*'
end

private

def vip_offset_exceeds_range?
return false if vip_offset.nil?
return true if vip_offset <= 0

vip_offset > internal_route_vip_range_len
end

def before_destroy
destroy_route_bindings
super
end

def find_next_vip_offset
# This code courtesy of Jeremy Evans as part of discussion on
# https://groups.google.com/d/msg/sequel-talk/3GJ8_mOgJ9U/roWJ2sWHAwAJ
# See SQL self-joins for the reasoning behind this

n = Route.exclude(vip_offset: 1).
exclude { vip_offset - 1 =~ Route.select(:vip_offset) }.order(:vip_offset).get { vip_offset - 1 } ||
(return (Route.max(:vip_offset) || 0) + 1)
Route.where { vip_offset < n }.reverse(:vip_offset).get { vip_offset + 1 } || 1
end

def before_save
return unless internal? && vip_offset.nil?

len = internal_route_vip_range_len
raise OutOfVIPException.new('out of vip_offset slots') if self.class.exclude(vip_offset: nil).count >= len

self.vip_offset = find_next_vip_offset
end

def internal_route_vip_range_len
internal_route_vip_range.len - 2
end

def internal_route_vip_range
@internal_route_vip_range ||= begin
internal_route_vip_range = Config.config.get(:internal_route_vip_range)
NetAddr::IPv4Net.parse(internal_route_vip_range)
end
end

def destroy_route_bindings
errors = RouteBindingDelete.new.delete(route_binding_dataset)
raise errors.first unless errors.empty?
Expand Down
2 changes: 0 additions & 2 deletions config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ credhub_api:
credential_references:
interpolate_service_bindings: true

internal_route_vip_range: '127.128.0.0/9'

locket:
host: 'locket.service.cf.internal'
port: 8891
Expand Down
9 changes: 9 additions & 0 deletions db/migrations/20240421055057_drop_vip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Sequel.migration do
no_transaction # to use the 'concurrently' option
change do
alter_table :routes do
drop_index :vip_offset, unique: true, name: :routes_vip_offset_index, concurrently: true
drop_column :vip_offset
end
end
end
2 changes: 0 additions & 2 deletions lib/cloud_controller/config_schemas/base/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ class ApiSchema < VCAP::Config
max_labels_per_resource: Integer,
max_annotations_per_resource: Integer,

internal_route_vip_range: String,

default_app_lifecycle: String,
custom_metric_tag_prefix_list: Array,

Expand Down
1 change: 0 additions & 1 deletion lib/cloud_controller/config_schemas/base/worker_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class WorkerSchema < VCAP::Config

max_labels_per_resource: Integer,
max_annotations_per_resource: Integer,
internal_route_vip_range: String,
custom_metric_tag_prefix_list: Array
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class RouteSyncerSchema < VCAP::Config
keys: Hash,
current_key_label: String,
optional(:pbkdf2_hmac_iterations) => Integer
},

internal_route_vip_range: String

}
}
end

Expand Down

0 comments on commit 91bd57d

Please sign in to comment.