// GetEvents returns events for particular namespace and replication controller or error if occurred.
func GetReplicationControllerEvents(client *client.Client, 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.AppendEvents(apiEvents, common.EventList{
		Namespace: namespace,
		Events:    make([]common.Event, 0),
	})

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

	return &events, nil
}
// GetReplicaSetEvents gets events associated to replica set.
func GetReplicaSetEvents(client client.Interface, namespace, replicaSetName string) (
	*common.EventList, error) {

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

	// Get events for replica set.
	rsEvents, err := event.GetEvents(client, namespace, replicaSetName)

	if err != nil {
		return nil, err
	}

	// Get events for pods in replica set.
	podEvents, err := GetReplicaSetPodsEvents(client, namespace, replicaSetName)

	if err != nil {
		return nil, err
	}

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

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

	events := event.AppendEvents(apiEvents, common.EventList{
		Namespace: namespace,
		Events:    make([]common.Event, 0),
	})

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

	return &events, nil
}