Skip to content

Commit

Permalink
kubernetes: verify endpoint api version
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
  • Loading branch information
simon3z committed Apr 24, 2015
1 parent 9c1b700 commit 7fced07
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gem "memoist", "~>0.11.0", :require => false
gem "more_core_extensions", "~>1.2.0", :require => false
gem "nokogiri", "~>1.5.0", :require => false
gem "ovirt", "~>0.4.2", :require => false
gem "kubeclient", ">=0.1.11", :require => false
gem "kubeclient", ">=0.1.12", :require => false
gem "rest-client", :require => false, :git => "git://github.com/rest-client/rest-client.git", :ref => "08480eb86aef1e"
gem "parallel", "~>0.5.21", :require => false
gem "Platform", "=0.4.0", :require => false
Expand Down
5 changes: 3 additions & 2 deletions lib/kubernetes/events/kubernetes_event_monitor.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class KubernetesEventMonitor
def initialize(api_endpoint)
def initialize(api_endpoint, api_version)
@api_endpoint = api_endpoint
@api_version = api_version
end

def inventory
require 'kubeclient'
@inventory ||= Kubeclient::Client.new(@api_endpoint)
@inventory ||= Kubeclient::Client.new(@api_endpoint, @api_version)
# TODO: support real authentication using certificates
@inventory.ssl_options(:verify_ssl => OpenSSL::SSL::VERIFY_NONE)
@inventory
Expand Down
20 changes: 18 additions & 2 deletions vmdb/app/models/ems_kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ class EmsKubernetes < EmsContainer

default_value_for :port, 6443

# This is the API version that we use and support throughout the entire code
# (parsers, events, etc.). It should be explicitly selected here and not
# decided by the user nor out of control in the defaults of kubeclient gem
# because it's not guaranteed that the next default version will work with
# our specific code in ManageIQ.
def self.api_version
'v1beta3'
end

def self.ems_type
@ems_type ||= "kubernetes".freeze
end
Expand All @@ -24,7 +33,7 @@ def self.event_monitor_class
def self.raw_connect(hostname, port)
require 'kubeclient'
api_endpoint = raw_api_endpoint(hostname, port)
kube = Kubeclient::Client.new(api_endpoint)
kube = Kubeclient::Client.new(api_endpoint, api_version)
# TODO: support real authentication using certificates
kube.ssl_options(:verify_ssl => OpenSSL::SSL::VERIFY_NONE)
kube
Expand Down Expand Up @@ -54,7 +63,14 @@ def verify_credentials(auth_type = nil, options = {})
# TODO: support real authentication using certificates
options = options.merge(:auth_type => auth_type)

with_provider_connection(options, &:api_valid?)
with_provider_connection(options) do |connection|
unless (connection.api['versions'] || []).include? api_version
errmsg = "Endpoint not supporting API version: #{api_version}"
raise MiqException::MiqHostError, errmsg
end
end

return true
rescue SocketError,
Errno::ECONNREFUSED,
RestClient::ResourceNotFound,
Expand Down
3 changes: 2 additions & 1 deletion vmdb/lib/workers/event_catcher_kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class EventCatcherKubernetes < EventCatcher
def event_monitor_handle
require 'kubernetes/events/kubernetes_event_monitor'
@event_monitor_handle ||= KubernetesEventMonitor.new(
@ems.api_endpoint
@ems.api_endpoint,
@ems.api_version
)
end

Expand Down

1 comment on commit 7fced07

@JPrause
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this needs to be back-ported, please let the build team know.

Please sign in to comment.