def _do_compute_rcontroller(gs, cluster_guid, rcontroller, g): assert isinstance(gs, global_state.GlobalState) assert utilities.valid_string(cluster_guid) assert utilities.is_wrapped_object(rcontroller, 'ReplicationController') assert isinstance(g, ContextGraph) rcontroller_id = rcontroller['id'] rcontroller_guid = 'ReplicationController:' + rcontroller_id g.add_resource(rcontroller_guid, rcontroller['annotations'], 'ReplicationController', rcontroller['timestamp'], rcontroller['properties']) # Cluster contains Rcontroller g.add_relation(cluster_guid, rcontroller_guid, 'contains') # Pods that are monitored by this replication controller. # Use the rcontroller['spec']['selector'] key/value pairs to find matching # pods. selector = utilities.get_attribute( rcontroller, ['properties', 'spec', 'selector']) if selector: if not isinstance(selector, types.DictType): msg = ('Rcontroller id=%s has an invalid "replicaSelector" value' % rcontroller_id) gs.logger_error(msg) raise collector_error.CollectorError(msg) for pod in kubernetes.get_selected_pods(gs, selector): pod_guid = 'Pod:' + pod['id'] # Rcontroller monitors Pod g.add_relation(rcontroller_guid, pod_guid, 'monitors') else: gs.logger_error('Rcontroller id=%s has no "spec.selector" attribute', rcontroller_id)
def _do_compute_rcontroller(gs, cluster_guid, rcontroller, g): assert isinstance(gs, global_state.GlobalState) assert utilities.valid_string(cluster_guid) assert utilities.is_wrapped_object(rcontroller, 'ReplicationController') assert isinstance(g, ContextGraph) rcontroller_id = rcontroller['id'] rcontroller_guid = 'ReplicationController:' + rcontroller_id g.add_resource(rcontroller_guid, rcontroller['annotations'], 'ReplicationController', rcontroller['timestamp'], rcontroller['properties']) # Cluster contains Rcontroller g.add_relation(cluster_guid, rcontroller_guid, 'contains') # Pods that are monitored by this replication controller. # Use the rcontroller['spec']['selector'] key/value pairs to find matching # pods. selector = utilities.get_attribute(rcontroller, ['properties', 'spec', 'selector']) if selector: if not isinstance(selector, types.DictType): msg = ('Rcontroller id=%s has an invalid "replicaSelector" value' % rcontroller_id) gs.logger_error(msg) raise collector_error.CollectorError(msg) for pod in kubernetes.get_selected_pods(gs, selector): pod_guid = 'Pod:' + pod['id'] # Rcontroller monitors Pod g.add_relation(rcontroller_guid, pod_guid, 'monitors') else: gs.logger_error('Rcontroller id=%s has no "spec.selector" attribute', rcontroller_id)
def _do_compute_service(gs, cluster_guid, service, g): assert isinstance(gs, global_state.GlobalState) assert utilities.valid_string(cluster_guid) assert utilities.is_wrapped_object(service, 'Service') assert isinstance(g, ContextGraph) service_id = service['id'] service_guid = 'Service:' + service_id g.add_resource(service_guid, service['annotations'], 'Service', service['timestamp'], service['properties']) # Cluster contains Service. g.add_relation(cluster_guid, service_guid, 'contains') # Pods load balanced by this service (use the service['spec', 'selector'] # key/value pairs to find matching Pods) selector = utilities.get_attribute( service, ['properties', 'spec', 'selector']) if selector: if not isinstance(selector, types.DictType): msg = 'Service id=%s has an invalid "selector" value' % service_id gs.logger_error(msg) raise collector_error.CollectorError(msg) for pod in kubernetes.get_selected_pods(gs, selector): pod_guid = 'Pod:' + pod['id'] # Service loadBalances Pod g.add_relation(service_guid, pod_guid, 'loadBalances') else: gs.logger_error('Service id=%s has no "selector" attribute', service_id)
def _do_compute_service(gs, cluster_guid, service, g): assert isinstance(gs, global_state.GlobalState) assert utilities.valid_string(cluster_guid) assert utilities.is_wrapped_object(service, 'Service') assert isinstance(g, ContextGraph) service_id = service['id'] service_guid = 'Service:' + service_id g.add_resource(service_guid, service['annotations'], 'Service', service['timestamp'], service['properties']) # Cluster contains Service. g.add_relation(cluster_guid, service_guid, 'contains') # Pods load balanced by this service (use the service['spec', 'selector'] # key/value pairs to find matching Pods) selector = utilities.get_attribute(service, ['properties', 'spec', 'selector']) if selector: if not isinstance(selector, types.DictType): msg = 'Service id=%s has an invalid "selector" value' % service_id gs.logger_error(msg) raise collector_error.CollectorError(msg) for pod in kubernetes.get_selected_pods(gs, selector): pod_guid = 'Pod:' + pod['id'] # Service loadBalances Pod g.add_relation(service_guid, pod_guid, 'loadBalances') else: gs.logger_error('Service id=%s has no "selector" attribute', service_id)