Class: EksCli::VPC::Client
- Inherits:
-
Object
- Object
- EksCli::VPC::Client
- Defined in:
- lib/eks_cli/vpc/client.rb
Instance Method Summary collapse
- #allow_networking(old_vpc_sg_id, peering_connection_id) ⇒ Object
- #client ⇒ Object
- #config ⇒ Object
- #create_vpc_peering_connection ⇒ Object
-
#initialize(cluster_name) ⇒ Client
constructor
A new instance of Client.
- #new_vpc ⇒ Object
- #new_vpc_id ⇒ Object
- #old_vpc ⇒ Object
- #old_vpc_id ⇒ Object
- #point_from(from_vpc, to_vpc, peering_connection_id) ⇒ Object
- #set_inter_vpc_networking(old_vpc_id, old_vpc_sg_id) ⇒ Object
- #update_route_tables(peering_connection_id) ⇒ Object
- #vpc_by_id(id) ⇒ Object
Constructor Details
#initialize(cluster_name) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/eks_cli/vpc/client.rb', line 8 def initialize(cluster_name) @cluster_name = cluster_name end |
Instance Method Details
#allow_networking(old_vpc_sg_id, peering_connection_id) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/eks_cli/vpc/client.rb', line 45 def allow_networking(old_vpc_sg_id, peering_connection_id) Log.info "allowing incoming traffic to sg #{old_vpc_sg_id} from #{config["nodes_sg_id"]} on vpc #{new_vpc.id}" old_sg = Aws::EC2::SecurityGroup.new(old_vpc_sg_id, client: client) res = old_sg.( ip_permissions: [ { from_port: "-1", ip_protocol: "-1", to_port: "-1", user_id_group_pairs: [ { description: "Accept all traffic from nodes on EKS cluster #{@cluster_name}", group_id: config["nodes_sg_id"], vpc_id: new_vpc.id, vpc_peering_connection_id: peering_connection_id, }, ], }, ] ) Log.info "done setting networking (#{res})" end |
#client ⇒ Object
97 98 99 |
# File 'lib/eks_cli/vpc/client.rb', line 97 def client @client ||= Aws::EC2::Client.new(region: config["region"]) end |
#config ⇒ Object
93 94 95 |
# File 'lib/eks_cli/vpc/client.rb', line 93 def config @config ||= Config[@cluster_name] end |
#create_vpc_peering_connection ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eks_cli/vpc/client.rb', line 20 def create_vpc_peering_connection Log.info "creating VPC peering request between #{new_vpc.id} and #{old_vpc.id}" pcr = client.create_vpc_peering_connection({ dry_run: false, peer_vpc_id: old_vpc.id, vpc_id: new_vpc.id, }) Log.info "created peering request #{pcr}" peering_connection_id = pcr.vpc_peering_connection.vpc_peering_connection_id Log.info "accepting peering request" res = client.accept_vpc_peering_connection({ dry_run: false, vpc_peering_connection_id: peering_connection_id, }) Log.info "request accepted: #{res}" return peering_connection_id end |
#new_vpc ⇒ Object
81 82 83 |
# File 'lib/eks_cli/vpc/client.rb', line 81 def new_vpc @new_vpc ||= vpc_by_id(new_vpc_id) end |
#new_vpc_id ⇒ Object
101 102 103 |
# File 'lib/eks_cli/vpc/client.rb', line 101 def new_vpc_id @new_vpc_id ||= config["vpc_id"] end |
#old_vpc ⇒ Object
85 86 87 |
# File 'lib/eks_cli/vpc/client.rb', line 85 def old_vpc @old_vpc end |
#old_vpc_id ⇒ Object
105 106 107 |
# File 'lib/eks_cli/vpc/client.rb', line 105 def old_vpc_id @old_vpc_id end |
#point_from(from_vpc, to_vpc, peering_connection_id) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/eks_cli/vpc/client.rb', line 68 def point_from(from_vpc, to_vpc, peering_connection_id) Log.info "pointing from #{from_vpc.id} to #{to_vpc.id} via #{peering_connection_id}" from_vpc.route_tables.each do |rt| res = client.create_route({ destination_cidr_block: to_vpc.cidr_block, gateway_id: peering_connection_id, route_table_id: rt.id, }) Log.info "set route #{res}" end end |
#set_inter_vpc_networking(old_vpc_id, old_vpc_sg_id) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/eks_cli/vpc/client.rb', line 12 def set_inter_vpc_networking(old_vpc_id, old_vpc_sg_id) @old_vpc = vpc_by_id(old_vpc_id) Log.info "setting vpc networking between #{new_vpc.id} and #{old_vpc.id}" peering_connection_id = create_vpc_peering_connection update_route_tables(peering_connection_id) allow_networking(old_vpc_sg_id, peering_connection_id) end |
#update_route_tables(peering_connection_id) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/eks_cli/vpc/client.rb', line 38 def update_route_tables(peering_connection_id) Log.info "updating route tables" point_from(old_vpc, new_vpc, peering_connection_id) point_from(new_vpc, old_vpc, peering_connection_id) Log.info "done updating route tables" end |
#vpc_by_id(id) ⇒ Object
89 90 91 |
# File 'lib/eks_cli/vpc/client.rb', line 89 def vpc_by_id(id) Aws::EC2::Vpc.new(id, client: client) end |