Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh service catalog entities #276

Merged
merged 9 commits into from
Aug 27, 2018
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::Kubernetes::ContainerManager::ServiceOffering < ::ServiceOffering
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::Kubernetes::ContainerManager::ServiceParametersSet < ::ServiceParametersSet
end
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def kubernetes_auth_options(options)
def kubernetes_version
'v1'
end

def kubernetes_service_catalog_connect(hostname, port, options)
options = {:path => '/apis/servicecatalog.k8s.io', :version => service_catalog_api_version}.merge(options)
Copy link
Contributor

Choose a reason for hiding this comment

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

we have too many ways to connect, what with ems.connect(:service => ...), also I think supporting ems.connect(:path => ...), and code somewhere I can't find now deriving path & version dynamically.

Nothing wrong with this method however 👍. Just wish I had time to clean up some of the other ways...

kubernetes_connect(hostname, port, options)
end

def service_catalog_api_version
'v1beta1'
end
end

PERF_ROLLUP_CHILDREN = :container_nodes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
class ManageIQ::Providers::Kubernetes::Inventory::Collector::ContainerManager < ManageIQ::Providers::Kubernetes::Inventory::Collector
# TODO(lsmola) we need to return iterator for each collection, so we avoid fetching too many items to memory at
# once.
# Hints from cben:
# A slightly open question in kubeclient iterator interface was how it should expose whole-collection resource_version
# (and other metadata). Should iterator yield it with every item, or return it at the end?
# With streaming parse (abonas/kubeclient#254), this depends on order of json. k8s puts items last, so version is
# known by time we start yielding; this is unlikely to change but I feel weird hardcoding this assumption...
# For chunking (abonas/kubeclient#283), we'll have metadata in each chunk, so either API works. Chunking also brings
# risk of getting 410 Gone if we wait too long, not sure how to handle that.

def namespaces
@namespaces ||= connection.get_namespaces
end
Expand All @@ -7,9 +17,21 @@ def pods
@pods ||= connection.get_pods
end

def cluster_service_offerings
@cluster_service_offerings ||= service_catalog_connection.get_cluster_service_classes
end

def cluster_service_parameters_sets
@cluster_service_parameters_sets ||= service_catalog_connection.get_cluster_service_plans
end

private

def connection
@connection ||= manager.connect(:service => "kubernetes")
end

def service_catalog_connection
@service_catalog_connection ||= manager.connect(:service => "kubernetes_service_catalog")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class ManageIQ::Providers::Kubernetes::Inventory::Parser::ContainerManager < Man
def parse
parse_namespaces(collector.namespaces)
parse_pods(collector.pods)

# Service catalog entities
parse_service_offerings(collector.cluster_service_offerings)
parse_service_parameters_sets(collector.cluster_service_parameters_sets)
end

private
Expand Down Expand Up @@ -34,6 +38,45 @@ def parse_pod(pod)
)
end

def parse_service_offerings(service_offeringes)
service_offeringes.each do |service_offering|
parse_service_offering(service_offering)
end
end

def parse_service_offering(service_offering)
persister.service_offerings.build(
:name => service_offering.spec.externalName,
:ems_ref => service_offering.spec.externalID,
:description => service_offering.spec.description,
:extra => {
:metadata => service_offering.metadata,
:spec => service_offering.spec,
:status => service_offering.status
}
)
end

def parse_service_parameters_sets(service_parameters_sets)
service_parameters_sets.each do |service_parameters_set|
parse_service_parameters_set(service_parameters_set)
end
end

def parse_service_parameters_set(service_parameters_set)
persister.service_parameters_sets.build(
:name => service_parameters_set.spec.externalName,
:ems_ref => service_parameters_set.spec.externalID,
:description => service_parameters_set.spec.description,
:service_offering => persister.service_offerings.lazy_find(service_parameters_set.spec.clusterServiceClassRef.name),
:extra => {
:metadata => service_parameters_set.metadata,
:spec => service_parameters_set.spec,
:status => service_parameters_set.status
}
)
end

def parse_base_item(item)
{
:ems_ref => item.metadata.uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def initialize_container_inventory_collections
computer_system_operating_systems
persistent_volumes
persistent_volume_claims
security_contexts).each do |name|
security_contexts
service_offerings
service_parameters_sets).each do |name|

add_collection(container, name)
end
Expand Down