Skip to content

Commit

Permalink
feat(emails): notify only default owner for images (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
emjburns authored Nov 13, 2018
1 parent 0a90e17 commit a319221
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.spinnaker.swabbie

import com.google.common.collect.Lists
import com.netflix.frigga.ami.AppVersion
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.config.SwabbieProperties
import com.netflix.spinnaker.kork.core.RetrySupport
Expand Down Expand Up @@ -375,7 +376,7 @@ abstract class AbstractResourceTypeHandler<T : Resource>(
) {
if (markedResource != null && !workConfiguration.dryRun) {
try {
log.info("{} is no longer a candidate because: $reason.", markedResource)
log.info("{} is no longer a candidate because: $reason.", markedResource.uniqueId())
resourceRepository.remove(markedResource)
applicationEventPublisher.publishEvent(UnMarkResourceEvent(markedResource, workConfiguration))
} catch (e: Exception) {
Expand Down Expand Up @@ -612,7 +613,7 @@ abstract class AbstractResourceTypeHandler<T : Resource>(
): List<List<MarkedResource>> {
val partitions = mutableListOf<List<MarkedResource>>()
markedResources.groupBy {
FriggaReflectiveNamer().deriveMoniker(it.resource).app
FriggaReflectiveNamer().deriveMoniker(it.resource).app //todo eb: images don't have an app
}.map {
Lists.partition(it.value, configuration.itemsProcessedBatchSize).forEach {
partitions.add(it)
Expand Down Expand Up @@ -724,16 +725,22 @@ abstract class AbstractResourceTypeHandler<T : Resource>(

private fun sendNotification(
owner: String,
workConfiguration:
WorkConfiguration,
workConfiguration: WorkConfiguration,
resources: List<MarkedResource>
) {
notifiers.forEach { notifier ->
workConfiguration.notificationConfiguration.types.forEach { notificationType ->
if (notificationType.equals(Notifier.NotificationType.EMAIL.name, true)) {
//todo eb: remove once we can skip notifications for emails
val finalOwner = if (resources.first().resourceType.contains("image", ignoreCase = true)) {
workConfiguration.notificationConfiguration.defaultDestination
} else {
owner
}

val notificationContext = mapOf(
"resourceOwner" to owner,
"application" to FriggaReflectiveNamer().deriveMoniker(resources.first()).app,
"resourceOwner" to finalOwner,
"application" to FriggaReflectiveNamer().deriveMoniker(resources.first()).app, //todo eb: this doesn't work for debs
"resources" to resources.map { it.barebones() },
"configuration" to workConfiguration,
"resourceType" to workConfiguration.resourceType.formatted(),
Expand All @@ -743,7 +750,7 @@ abstract class AbstractResourceTypeHandler<T : Resource>(

retrySupport.retry({
notifier.notify(
recipient = owner,
recipient = finalOwner,
messageType = notificationType,
additionalContext = notificationContext
)
Expand Down

0 comments on commit a319221

Please sign in to comment.