activek8s 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4d9f8116a425bf5181fe50afc8ae62b1a35ecf43ed2f1374205c6812bfd9194
4
- data.tar.gz: 40c2c73c3978bd95a9994a91a3db6c670622d4cd0dd2959145638e6dcdce82bb
3
+ metadata.gz: cced9ad51fc24f2435e9b38833bbc5c991b63523db450701d7c80dd548669e7e
4
+ data.tar.gz: 11f4f7296e0826865e57c5a86d61157d707b7662f63c8399583606460e8b74e8
5
5
  SHA512:
6
- metadata.gz: 2a69489f1dabd0d97154c3702a7b57ca2fcddfa3e89d194fce0e970e4f278a7a29f55e6cea200b2e523f37f90a73bce0d631bca4ecfd19693c8732fa1f91bfd2
7
- data.tar.gz: d03cfadf665df9030c3b9daa70cea16e81ad62bf4bc10f50e5f6ecc0f16acfb8c0d0fdd3f77ca7803373824aa97fcdd538a9bc23f915d2e28293f0e97d862411
6
+ metadata.gz: cd1a7680bc20702faf6334bdd50c85d0ae3c3cf23e4f0c89730e19c232ea114d3271fa7070932f87e184e326f4fa9f3c5f55bb2c760556205ba9703743c3ddb1
7
+ data.tar.gz: 29696b79bc8487f13336cebfc73417e8aeff99a5f6c45b221de5fb2bf137a4359c6ff6cae9c25996e2657a7bc4eb2135d10e253816f37ef4f6ac4aecea69f409
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activek8s (0.2.3)
4
+ activek8s (0.3.0)
5
5
  childprocess (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -71,4 +71,4 @@ DEPENDENCIES
71
71
  simplecov (~> 0.16.1)
72
72
 
73
73
  BUNDLED WITH
74
- 1.17.1
74
+ 1.17.2
@@ -6,7 +6,8 @@ module Activek8s
6
6
  load 'tasks/deploy.rake'
7
7
  load 'tasks/delete.rake'
8
8
  load 'tasks/port_forward.rake'
9
- load 'tasks/port_forward_many.rake'
9
+ load 'tasks/port_forward_current.rake'
10
+ load 'tasks/port_forward_service.rake'
10
11
  load 'tasks/kibana.rake'
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module Activek8s
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- namespace 'k8s' do
1
+ namespace 'ak8s' do
2
2
  desc 'Builds the deployment.yml file for execution on a cluster'
3
3
  task :build_deployment, [:namespace, :tag] do |_t, args|
4
4
  args.with_defaults(namespace: 'dev', tag: 'latest')
@@ -1,4 +1,4 @@
1
- namespace 'k8s' do
1
+ namespace 'ak8s' do
2
2
  desc 'Deletes the current microservice TAG version on a specific NAMESPACE'
3
3
  task :delete, [:namespace, :tag, :cleanup] do |_t, args|
4
4
  deployment_path = ENV['K8S_DEPLOYMENT_FILE'] || 'kube/last_deployment.yml'
@@ -1,4 +1,4 @@
1
- namespace 'k8s' do
1
+ namespace 'ak8s' do
2
2
  desc 'Deploys the current microservice TAG version on a specific NAMESPACE'
3
3
  task :deploy, [:namespace, :tag, :cleanup] do |_t, args|
4
4
  puts "ARGS: [#{args.namespace}, #{args.tag}, #{args.cleanup}]" unless ENV['K8S_DEBUG'].nil?
@@ -1,4 +1,4 @@
1
- namespace 'k8s' do
1
+ namespace 'ak8s' do
2
2
  desc 'Port forwards kibana to access logs'
3
3
  task :kibana, [:namespace, :port] do |_t, args|
4
4
  args.with_defaults(namespace: 'logging', port: '5601')
@@ -1,24 +1,58 @@
1
- namespace 'k8s' do
2
- desc 'Port forwards a microservice from a specific NAMESPACE to a PORT'
3
- task :port_forward,
4
- [:namespace, :service, :local_port, :target_port] do |_t, args|
5
- begin
6
- service_yaml = File.read('kube/deployment.yml').split('---')[1]
7
- deployment_hash = Psych.load(service_yaml)
8
- own_name = deployment_hash['metadata']['name']
9
- rescue
10
- puts 'WARNING: Unable to load default metadata from "kube/deployment.yml"'
11
- own_name = 'CHECK DOCS AT -> https://github.com/fdoxyz/activek8s'
1
+ require 'childprocess'
2
+
3
+ namespace 'ak8s' do
4
+ desc 'Port forwards many services from a specific NAMESPACE'
5
+ task :port_forward, [:namespace] do |_t, args|
6
+ # Config with defaults setup
7
+ config = YAML.load_file(ENV['AK8S_CONFIG'] || '.ak8s.yml')
8
+ config_namespaces = config.keys.reject { |n| n == 'ak8s' }
9
+ args.with_defaults(namespace: config_namespaces.first)
10
+ raise 'Bad config file format' if args.namespace.nil?
11
+
12
+ # Helper variables setup
13
+ first_port = config.dig('ak8s', 'first_port') || 4200
14
+ namespaced_services = config[args.namespace]['services']
15
+ raise 'No services listed in .ak8s.yml' if namespaced_services.empty?
16
+
17
+ # All services to port forward (an array of hashes)
18
+ services = namespaced_services.each_with_index.map do |service, index|
19
+ port = first_port.to_i + index
20
+ export_env = "#{service['name'].upcase}_ENDPOINT"
21
+ target_port = service['target_port'] || 3000
22
+ service_namespace = service['namespace'] || args.namespace
23
+
24
+ rake_task_params = [
25
+ service_namespace,
26
+ service['name'],
27
+ port,
28
+ target_port
29
+ ].map(&:to_s).join(',')
30
+
31
+ {
32
+ port: port,
33
+ rake_task: "ak8s:port_forward_service[#{rake_task_params}]",
34
+ env: "export #{export_env}=\"http://localhost:#{port}/\""
35
+ }
12
36
  end
13
37
 
14
- args.with_defaults(namespace: 'dev',
15
- service: own_name,
16
- local_port: '3000',
17
- target_port: '3000')
38
+ # Export ENV variables to `services.env`
39
+ env_file = services.map { |service| service[:env] }.join("\n")
40
+ File.write('services.env', env_file)
41
+
42
+ # Execute each 'rake_task' in a child process until CTRL+C is received
43
+ begin
44
+ processes = services.map do |service|
45
+ ChildProcess.build('bin/rake', service[:rake_task])
46
+ end
47
+ processes.each(&:start)
18
48
 
19
- service = "svc/#{args.service}"
20
- port_mapping = "#{args.local_port}:#{args.target_port}"
21
- namespace = "-n #{args.namespace}"
22
- sh %{kubectl port-forward #{service} #{port_mapping} #{namespace}}
49
+ puts 'Services should be port forwarded to localhost in a few seconds.'
50
+ puts 'Execute ". services.env" to source each service URL.'
51
+ loop { sleep 3 }
52
+ rescue Interrupt
53
+ puts "\nExiting child processes..."
54
+ processes.each(&:stop)
55
+ puts 'Done!'
56
+ end
23
57
  end
24
58
  end
@@ -0,0 +1,24 @@
1
+ namespace 'ak8s' do
2
+ desc 'Port forwards the current project using the `kube/deployment.yml` file'
3
+ task :port_forward_current,
4
+ [:namespace, :service, :local_port, :target_port] do |_t, args|
5
+ begin
6
+ service_yaml = File.read('kube/deployment.yml').split('---')[1]
7
+ deployment_hash = Psych.load(service_yaml)
8
+ own_name = deployment_hash['metadata']['name']
9
+ rescue
10
+ docs_location = 'CHECK DOCS AT -> https://github.com/fdoxyz/activek8s'
11
+ raise "WARNING: Unable to load `kube/deployment.yml`. #{docs_location}"
12
+ end
13
+
14
+ args.with_defaults(namespace: 'dev',
15
+ service: own_name,
16
+ local_port: '3000',
17
+ target_port: '3000')
18
+
19
+ service = "svc/#{args.service}"
20
+ port_mapping = "#{args.local_port}:#{args.target_port}"
21
+ namespace = "-n #{args.namespace}"
22
+ sh %{kubectl port-forward #{service} #{port_mapping} #{namespace}}
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ namespace 'ak8s' do
2
+ desc 'Port forwards a microservice from a specific NAMESPACE to a PORT'
3
+ task :port_forward_service,
4
+ [:namespace, :service, :local_port, :target_port] do |_t, args|
5
+
6
+ args.with_defaults(namespace: 'dev',
7
+ service: nil,
8
+ local_port: '3000',
9
+ target_port: '3000')
10
+
11
+ raise 'Invalid service name' if args.service.nil?
12
+
13
+ service = "svc/#{args.service}"
14
+ port_mapping = "#{args.local_port}:#{args.target_port}"
15
+ namespace = "-n #{args.namespace}"
16
+ sh %{kubectl port-forward #{service} #{port_mapping} #{namespace}}
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activek8s
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Valverde Arredondo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-06 00:00:00.000000000 Z
11
+ date: 2019-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess
@@ -135,7 +135,8 @@ files:
135
135
  - lib/tasks/deploy.rake
136
136
  - lib/tasks/kibana.rake
137
137
  - lib/tasks/port_forward.rake
138
- - lib/tasks/port_forward_many.rake
138
+ - lib/tasks/port_forward_current.rake
139
+ - lib/tasks/port_forward_service.rake
139
140
  homepage: https://github.com/fdoxyz/activek8s
140
141
  licenses:
141
142
  - MIT
@@ -155,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  - !ruby/object:Gem::Version
156
157
  version: '0'
157
158
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.7.8
159
+ rubygems_version: 3.0.3
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Kubernetes integration to Rails apps via Rake tasks
@@ -1,42 +0,0 @@
1
- require 'childprocess'
2
-
3
- namespace 'k8s' do
4
- desc 'Port forwards many services from a specific NAMESPACE'
5
- task :port_forward_many, [:namespace, :first_port, :services] do |_t, args|
6
- # default "empty char" separated services to be port-forwarded from ENV
7
- args.with_defaults(namespace: 'dev',
8
- first_port: '3001',
9
- services: ENV['K8S_SERVICES'].to_s)
10
-
11
- # Build 'dynamic' values
12
- services = args.services.split(' ').each_with_index.map do |name, index|
13
- port = args.first_port.to_i + index
14
- export_env = "#{name.upcase}_ENDPOINT"
15
- {
16
- port: port,
17
- rake_task: "k8s:port_forward[#{args.namespace},#{name},#{port},3000]",
18
- env: "export #{export_env}=\"http://localhost:#{port}/\""
19
- }
20
- end
21
-
22
- # Export ENV variables
23
- env_file = services.map { |service| service[:env] }.join("\n")
24
- File.write('services.env', env_file)
25
-
26
- # Execute each 'rake_task' in a child process until CTRL+C is received
27
- begin
28
- processes = services.map do |service|
29
- ChildProcess.build('bin/rake', service[:rake_task])
30
- end
31
- processes.each(&:start)
32
-
33
- puts 'Services should be port forwarded to localhost in a few seconds.'
34
- puts 'Execute ". services.env" to source each service URL.'
35
- loop { sleep 3 }
36
- rescue Interrupt
37
- puts "\nExiting child processes..."
38
- processes.each(&:stop)
39
- puts 'Done!'
40
- end
41
- end
42
- end