// 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
}
// 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
}