// GetReplicationControllerEvents returns events for particular namespace and replication
// controller or error if occurred.
func GetReplicationControllerEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery,
	namespace, replicationControllerName string) (*common.EventList, error) {

	log.Printf("Getting events related to %s replication controller in %s namespace", replicationControllerName,
		namespace)

	// Get events for replication controller.
	rsEvents, err := resourceEvent.GetEvents(client, namespace, replicationControllerName)

	if err != nil {
		return nil, err
	}

	// Get events for pods in replication controller.
	podEvents, err := getReplicationControllerPodsEvents(client, namespace,
		replicationControllerName)

	if err != nil {
		return nil, err
	}

	apiEvents := append(rsEvents, podEvents...)

	if !resourceEvent.IsTypeFilled(apiEvents) {
		apiEvents = resourceEvent.FillEventsType(apiEvents)
	}

	events := resourceEvent.CreateEventList(apiEvents, dsQuery)

	log.Printf("Found %d events related to %s replication controller in %s namespace",
		len(events.Events), replicationControllerName, namespace)

	return &events, nil
}
Exemplo n.º 2
0
// GetDaemonSetEvents gets events associated to daemon set.
func GetDaemonSetEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace, daemonSetName string) (
	*common.EventList, error) {

	log.Printf("Getting events related to %s daemon set in %s namespace", daemonSetName,
		namespace)

	// Get events for daemon set.
	dsEvents, err := event.GetEvents(client, namespace, daemonSetName)

	if err != nil {
		return nil, err
	}

	// Get events for pods in daemon set.
	podEvents, err := GetDaemonSetPodsEvents(client, namespace, daemonSetName)

	if err != nil {
		return nil, err
	}

	apiEvents := append(dsEvents, podEvents...)

	if !event.IsTypeFilled(apiEvents) {
		apiEvents = event.FillEventsType(apiEvents)
	}

	events := event.CreateEventList(apiEvents, dsQuery)

	log.Printf("Found %d events related to %s daemon set in %s namespace",
		len(events.Events), daemonSetName, namespace)

	return &events, nil
}
Exemplo n.º 3
0
// GetDeploymentEvents returns model events for a deployment with the given name in the given
// namespace
func GetDeploymentEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace string, deploymentName string) (
	*common.EventList, error) {

	deployment, err := client.Extensions().Deployments(namespace).Get(deploymentName)
	if err != nil {
		return nil, err
	}

	selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector)
	if err != nil {
		return nil, err
	}

	options := api.ListOptions{LabelSelector: selector}
	channels := &common.ResourceChannels{
		EventList: common.GetEventListChannelWithOptions(client,
			common.NewSameNamespaceQuery(namespace), options, 1),
	}

	eventRaw := <-channels.EventList.List
	if err := <-channels.EventList.Error; err != nil {
		return nil, err
	}
	dpEvents := eventRaw.Items
	if !event.IsTypeFilled(dpEvents) {
		dpEvents = event.FillEventsType(dpEvents)
	}

	eventList := event.CreateEventList(dpEvents, dsQuery)

	return &eventList, nil
}