chopshop-logreader 0.1.2 → 0.2.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: d6832e1640a4f8c99cfbdc2a010d39aac2510891a8505445e7ea5ce7e0f8d981
4
- data.tar.gz: 50d99bafbfa934f38a0a5e4bd7cf730863be08f83af926813beea6ed652b5581
3
+ metadata.gz: 700b48c7aa5c2860daafe085bd725410237027d0ece992f55c28a70ce91ca330
4
+ data.tar.gz: baeb1b8b59e9d457abcb1f27a9ce93597051ca674c02a3bae74c0bda4ee7de96
5
5
  SHA512:
6
- metadata.gz: 02bb0cc3fd4371687cf0a90fc8b6e0b2d60b44e883da50b7b1b659a177fef8079044ef44f7fcfed316f7802fb40ec86763f764bdba5259e8ac73b5d0567756c9
7
- data.tar.gz: 3cdea25e30bc8f814ec426a3a39cd4a561a459679d01a651c70d8da98acb2c0c2d4d9b5b7493dd3229548ee67eb9973c3d9899e2e524c274e84d74c8c7b78ed7
6
+ metadata.gz: 4ded503a09b9214828f3e6ab58190943b56104eb987d2a8a4b0bcadc909791bc98e05133ac2da9ec8d079b902d019fad398ed28b4ea3bd61de6fa333c22b6dd3
7
+ data.tar.gz: 19f55e8b3a0bae8f57056ee002739fed0ab3de135776cfefc4f2f09e51f531021c3df57369a208e3fadef8beb6770769b678ba1efe4db3046cfeee1026e3d3cc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chopshop-logreader (0.1.1)
4
+ chopshop-logreader (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -19,4 +19,4 @@ DEPENDENCIES
19
19
  rake (~> 10.0)
20
20
 
21
21
  BUNDLED WITH
22
- 1.17.2
22
+ 2.2.33
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Chopshop::Logreader
2
2
 
3
+ This is a simple CLI tool that allows you to find & follow the logs for the most recently running kubernetes pod with a given name for a given status (default status is "Running"). As of now there is no support for searching for pods that started running in a given window of time, although that is a possible feature add if requested. if a valid pod is not found, it will ping the API once a second until one is found or the program is exited. This primarily just wraps some `kubectl` commands and handles parsing the output in standard way to quickly find a pod's logs.
3
4
 
4
5
  ## Installation
5
6
 
@@ -11,20 +12,66 @@ gem 'chopshop-logreader'
11
12
 
12
13
  And then execute:
13
14
 
14
- $ bundle
15
+ ```bash
16
+ bundle
17
+ ```
15
18
 
16
19
  Or install it yourself as:
17
20
 
18
- $ gem install chopshop-logreader
21
+ ```bash
22
+ gem install chopshop-logreader
23
+ ```
24
+
25
+ ## Getting started
26
+
27
+ This gem assumes 2 things.
28
+
29
+ 1. you will provide a cloud provider profile (think aws) via one of 3 sources:
30
+ - an option on the command line (`-p PROFILE` or `--profile PROFILE`)
31
+ - via the ENV VAR `AWS_PROFILE`
32
+ - via the ENV VAR `PROFILE`
33
+
34
+ 2. you will provide a tenant via one of 2 sources:
35
+ - an option on the command line (`t TENANT` or `--tenant TENANT`)
36
+ - via the ENV VAR `DEFAULT_TENANT`
37
+
38
+ Ideally you will set those env vars before starting.
19
39
 
20
40
  ## Usage
21
41
 
22
- `chopshop-logreader -h` to get help
23
- example use:
24
- `chopshop-logreader SERVICE_NAME_HERE -n connect -s Running -l 10 -f false`
25
- default use:
26
- `chopshop-logreader profile-reader` expands to `chopshop-logreader profile-reader -n connect -s Running -l -1 -f true`
42
+ to get help:
43
+
44
+ ```bash
45
+ chopshop-logreader -h
46
+ ```
47
+
48
+ example uses:
49
+
50
+ ```bash
51
+ chopshop-logreader SERVICE_NAME_HERE -n connect -s Completed -l 10 -f false
52
+ ```
53
+
54
+ ```bash
55
+ chopshop-logreader SERVICE_NAME_HERE -n connect -s Error -l -1 -f true
56
+ ```
57
+
58
+ ```bash
59
+ chopshop-logreader SERVICE_NAME_HERE -n connect -s Error -l -1 -f true -t some-cool-tenant-name -p my-cool-aws-dev-profile
60
+ ```
61
+
62
+ ### Default Use
63
+
64
+ ```bash
65
+ chopshop-logreader profile-reader
66
+ ```
67
+
68
+ expands to
69
+
70
+ ```bash
71
+ chopshop-logreader profile-reader -n connect -s Running -l -1 -f true
72
+ ```
27
73
 
74
+ the default use also assumes your have set the ENV VARS `DEFAULT_TENANT` and either `AWS_PROFILE` or `PROFILE`
28
75
 
29
76
  ## Development
30
77
 
@@ -43,3 +90,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
43
90
  ## Code of Conduct
44
91
 
45
92
  Everyone interacting in the Chopshop::Logreader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/chopshop-logreader/blob/master/CODE_OF_CONDUCT.md).
93
+
94
+ ## Project TODO
95
+
96
+ - add a startup script that will set the default profile/tenant for a user
@@ -24,22 +24,24 @@ module Chopshop
24
24
 
25
25
  def execute!
26
26
  options = @parser.parse
27
+ profile = options.profile || ENV["AWS_PROFILE"] || ENV["PROFILE"]
28
+ tenant = options.tenant || ENV["DEFAULT_TENANT"]
27
29
 
28
30
  container = nil
29
31
  service = ARGV[0]
32
+ `rally-kubectl -e #{profile} -t #{tenant}`
30
33
  puts "looking for valid container"
31
34
  while !container
32
- containers = `kubectl get pods --namespace #{options[:namespace]} | grep #{service}`
35
+ containers = `kubectl get pods --namespace #{options.namespace} | grep #{service}`
33
36
  container = containers.split("\n").map {|line| line.split(" ") }.each do |line|
34
37
  match_data = REGEX.match(line[4])
35
38
  line[5] = TIME_CALCULATOR[match_data.captures[1].downcase] * match_data.captures[0].to_i + TIME_CALCULATOR[match_data.captures[3].downcase] * match_data.captures[2].to_i
36
- end.select{|line| line[2] == options[:status] }.sort_by {|line| line[5] }.first
39
+ end.select{|line| line[2] == options.status }.sort_by {|line| line[5] }.first
37
40
 
38
41
  if container
39
- exec "kubectl logs --follow=#{options[:follow]} --tail=#{options[:lines]} --namespace connect #{container[0]}"
42
+ exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect #{container[0]}"
40
43
  end
41
44
 
42
-
43
45
  print "."
44
46
  sleep 1
45
47
  end
@@ -1,15 +1,19 @@
1
1
  require "optparse"
2
+ require 'ostruct'
2
3
 
3
4
  module Chopshop
4
5
  module Logreader
5
6
  class Parser
6
7
  def parse
7
- options = {
8
+ options = OpenStruct.new(
8
9
  follow: true, # follow output from log file
9
10
  lines: -1, # whole file always,
10
11
  status: "Running", # look for a currently running container
11
- namespace: "connect"
12
- }
12
+ namespace: "connect",
13
+ tenant: nil,
14
+ profile: nil
15
+ )
16
+
13
17
 
14
18
  OptionParser.new do |opts|
15
19
  opts.banner = "Usage: ruby log-reader.rb SERVICE [options]"
@@ -30,6 +34,13 @@ module Chopshop
30
34
  options[:status] = status
31
35
  end
32
36
 
37
+ opts.on("-p [PROFILE]", "--profile [PROFILE]", "chooses the cloud profile to use for permissions. default: nil. You must provide this value or set the ENV VAR AWS_PROFILE' or the ENV VAR 'PROFILE'", String) do |profile|
38
+ options[:profile] = profile
39
+ end
40
+
41
+ opts.on("-t [TENANT]", "--tenant [TENANT]", "sets the kubernetes tenant to look for containers in. default: nil. You must provide this value or set the ENV VAR DEFAULT_TENANT'", String) do |tenant|
42
+ options[:tenant] = tenant
43
+ end
33
44
 
34
45
  opts.on("-h", "--help", "Prints this help") do
35
46
  puts opts
@@ -1,5 +1,5 @@
1
1
  module Chopshop
2
2
  module Logreader
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,7 +1,6 @@
1
1
  module Chopshop
2
2
  module Logreader
3
3
  class Error < StandardError; end
4
- # Your code goes here...
5
4
  end
6
5
  end
7
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chopshop-logreader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Perdue
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-18 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - travis.perdue@rallyhealth.com
58
58
  executables:
@@ -87,7 +87,7 @@ metadata:
87
87
  homepage_uri: https://github.com/tperdue321/chopshop-logreader
88
88
  source_code_uri: https://github.com/tperdue321/chopshop-logreader
89
89
  changelog_uri: https://github.com/tperdue321/chopshop-logreader
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.0.3
106
- signing_key:
105
+ rubygems_version: 3.2.22
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Read logs out of kubernetes
109
109
  test_files: []