Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ gemfile: kubernetes/Gemfile
rvm:
- 2.6

before_install:
- gem update --system
- gem install bundler

script:
- cd kubernetes
- bundle exec rubocop ./src
Expand Down
1 change: 1 addition & 0 deletions kubernetes/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gemspec
group :development, :test do
gem 'rake', '~> 12.0.0'
gem 'rubocop', '~> 0.65.0'
gem 'webmock', '~> 3.5.1'
end
10 changes: 5 additions & 5 deletions kubernetes/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GEM
ethon (0.12.0)
ffi (>= 1.3.0)
ffi (1.10.0)
hashdiff (0.3.8)
hashdiff (0.3.9)
jaro_winkler (1.5.2)
json (2.1.0)
parallel (1.14.0)
Expand Down Expand Up @@ -58,14 +58,14 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
safe_yaml (1.0.4)
safe_yaml (1.0.5)
sys-uname (1.0.4)
ffi (>= 1.0.0)
typhoeus (1.3.1)
ethon (>= 0.9.0)
unicode-display_width (1.4.1)
vcr (3.0.3)
webmock (1.24.6)
webmock (3.5.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
Expand All @@ -83,7 +83,7 @@ DEPENDENCIES
rspec (~> 3.6, >= 3.6.0)
rubocop (~> 0.65.0)
vcr (~> 3.0, >= 3.0.1)
webmock (~> 1.24, >= 1.24.3)
webmock (~> 3.5.1)

BUNDLED WITH
1.16.1
2.0.1
2 changes: 2 additions & 0 deletions kubernetes/spec/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/BlockLength:
Max: 99
3 changes: 3 additions & 0 deletions kubernetes/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
require 'kubernetes'
require 'helpers/file_fixtures'

require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)

# The following was generated by the `rspec --init` command. Conventionally,
# all specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down
3 changes: 0 additions & 3 deletions kubernetes/spec/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
require 'helpers/file_fixtures'

require 'kubernetes/utils'

# rubocop:disable BlockLength
describe Kubernetes do
describe '.load_incluster_config' do
let(:incluster_config) do
Expand Down Expand Up @@ -115,4 +113,3 @@
end
end
end
# rubocop:enable BlockLength
54 changes: 54 additions & 0 deletions kubernetes/spec/watch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,60 @@
Kubernetes::Watch.new(nil)
end

it 'should connect correctly with resource version' do
config = Kubernetes::Configuration.new
config.scheme = 'http'
config.host = 'k8s.io:8080'
client = Kubernetes::ApiClient.new(config)
url = 'http://k8s.io:8080/some/path?watch=true&resourceVersion=foo'

WebMock.stub_request(:get, url)
.with(
headers: {
'Authorization' => '',
'Content-Type' => 'application/json',
'Expect' => '',
'User-Agent' => 'Swagger-Codegen/1.0.0-alpha2/ruby'
}
)
.to_return(status: 200, body: "{}\n", headers: {})

watch = Kubernetes::Watch.new(client)
result = []
watch.connect('/some/path', 'foo') do |obj|
result << obj
end
end

it 'should connect correctly' do
config = Kubernetes::Configuration.new
config.scheme = 'http'
config.host = 'k8s.io:8080'
client = Kubernetes::ApiClient.new(config)
body = "{ \"foo\": \"bar\" }\n{ \"baz\": \"blah\" }\n{}\n"

WebMock.stub_request(:get, 'http://k8s.io:8080/some/path?watch=true')
.with(
headers: {
'Authorization' => '',
'Content-Type' => 'application/json',
'Expect' => '',
'User-Agent' => 'Swagger-Codegen/1.0.0-alpha2/ruby'
}
)
.to_return(status: 200, body: body, headers: {})

watch = Kubernetes::Watch.new(client)
result = []
watch.connect('/some/path', nil) do |obj|
result << obj
end

expect(result.length).to eq(3)
expect(result[0]['foo']).to eq('bar')
expect(result[1]['baz']).to eq('blah')
end

it 'should parse chunks correctly' do
client = Kubernetes::Watch.new(nil)
last = ''
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/src/kubernetes/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/MethodLength:
Max: 50
2 changes: 1 addition & 1 deletion kubernetes/src/kubernetes/config/kube_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def list_context_names(config_file = KUBE_CONFIG_DEFAULT_LOCATION)
attr_accessor :path
attr_writer :config

def initialize(path, config_hash = nil)
def initialize(path = nil, config_hash = nil)
@path = path
@config = config_hash
end
Expand Down
11 changes: 9 additions & 2 deletions kubernetes/src/kubernetes/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ def initialize(client)
@client = client
end

def connect(path, &_block)
def make_url(path, resource_version)
query = '?watch=true'
query += "&resourceVersion=#{resource_version}" if resource_version
path + query
end

def connect(path, resource_version = nil, &_block)
opts = { auth_names: ['BearerToken'] }
request = @client.build_request('GET', path + '?watch=true', opts)
url = make_url(path, resource_version)
request = @client.build_request('GET', url, opts)
last = ''
request.on_body do |chunk|
last, pieces = split_lines(last, chunk)
Expand Down