Skip to content

Commit

Permalink
Merge remote-tracking branch master into petrosian
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed May 30, 2023
2 parents 8f53bc7 + f2a2efd commit bcd72da
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 53 deletions.
19 changes: 12 additions & 7 deletions app/models/manageiq/providers/openshift/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.raw_connect(hostname, port, options)
end

def self.openshift_connect(hostname, port, options)
api_group = options[:api_group] || "apps.openshift.io/v1"
api_group = options[:api_group] || "config.openshift.io/v1"
api_path, api_version = api_group.split("/")

options = {:path => "/apis/#{api_path}", :version => api_version}.merge(options)
Expand All @@ -62,6 +62,10 @@ def self.verify_default_credentials(hostname, port, options)

ocp = openshift_connect(hostname, port, options)
!!ocp&.api_valid?
rescue Kubeclient::ResourceNotFoundError
# If the /apis/config.openshift.io/v1 endpoint isn't available then we have
# connected to an unsupported version of openshift
raise MiqException::Error, _("Unsupported OpenShift version")
end

def self.api_group_for_kind(kind)
Expand Down Expand Up @@ -96,15 +100,16 @@ def connect_client(kind, api_version, method_name)
if version
@clients[api_version] ||= connect(:service => 'kubernetes', :version => version, :path => '/apis/' + api)
else
kubernetes_client_key = File.join("/api", api_version)
@clients[kubernetes_client_key] ||= connect(:service => 'kubernetes', :version => api_version)

# If we're given an OpenShift object lookup its v4 API Group
api_group = self.class.api_group_for_kind(kind)
path = api_group ? "/apps/#{api_group}" : "/oapi"
if api_group
openshift_client_key = File.join(path, "/apps/#{api_group}")
@clients[openshift_client_key] ||= connect(:api_group => api_group, :version => api_version)
end

openshift_client_key = File.join(path, api_version)
kubernetes_client_key = File.join("/api", api_version)

@clients[openshift_client_key] ||= connect(:api_group => api_group, :version => api_version)
@clients[kubernetes_client_key] ||= connect(:service => 'kubernetes', :version => api_version)
@clients[openshift_client_key].respond_to?(method_name) ? @clients[openshift_client_key] : @clients[kubernetes_client_key]
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/manageiq-providers-openshift.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/manageiq/providers/openshift.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require "manageiq/providers/openshift/engine"
require "manageiq/providers/openshift/version"

15 changes: 15 additions & 0 deletions spec/models/manageiq/providers/openshift/container_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
describe ManageIQ::Providers::Openshift::ContainerManager do
describe ".verify_default_credentials" do
context "with a v3 cluster" do
it "raises an unsupported exception" do
require "kubeclient"

allow(Kubeclient::Client)
.to receive(:new)
.with(URI.parse("https://openshiftv3:8443/oapi"), "v1", anything)
.and_raise(Kubeclient::ResourceNotFoundError.new(404, "404 Not Found", nil))

expect { described_class.verify_default_credentials("openshiftv3", 8443, {:path => "/oapi"}) }.to raise_error(MiqException::Error, "Unsupported OpenShift version")
end
end
end

it "#catalog_types" do
ems = FactoryBot.create(:ems_openshift)
expect(ems.catalog_types).to include("generic_container_template")
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Dir[ManageIQ::Providers::Kubernetes::Engine.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[File.join(__dir__, "support/**/*.rb")].each { |f| require f }

require "manageiq-providers-openshift"
require "manageiq/providers/openshift"

VCR.configure do |config|
config.ignore_hosts 'codeclimate.com' if ENV['CI']
Expand Down
43 changes: 0 additions & 43 deletions spec/vcr_cassettes/container_template.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bcd72da

Please sign in to comment.