-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(artifacts): Introduce ArtifactSupplier plugin interface (3 of 3) (…
…#1321) * feat(artifacts): Introduce ArtifactPublisher plugin interface (3 of 3) * chore(pr): Improve logging * fix(pr): Address review feedback * chore(pr): More logging * fix(pr): Ignore statuses for DockerArtifact * chore(logging): Yet more logging improvements * refactor(pr): Rename ArtifactPublisher to ArtifactSupplier * fix(pr): Cleanup left-over file
- Loading branch information
Showing
74 changed files
with
1,067 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
...jackson/src/main/kotlin/com/netflix/spinnaker/keel/json/VersioningStrategyDeserializer.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 14 additions & 6 deletions
20
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/artifacts/DeliveryArtifact.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
package com.netflix.spinnaker.keel.api.artifacts | ||
|
||
enum class ArtifactType { | ||
deb, docker; | ||
|
||
override fun toString() = name | ||
} | ||
typealias ArtifactType = String | ||
|
||
/** | ||
* The release status of an artifact. This may not necessarily be applicable to all | ||
* [DeliveryArtifact] sub-classes. | ||
*/ | ||
enum class ArtifactStatus { | ||
FINAL, CANDIDATE, SNAPSHOT, RELEASE, UNKNOWN | ||
} | ||
|
||
/** | ||
* An artifact as defined in a [DeliveryConfig]. | ||
* | ||
* Unlike other places within Spinnaker, this class does not describe a specific instance of a software artifact | ||
* (i.e. the output of a build that is published to an artifact repository), but rather the high-level properties | ||
* that allow keel and [ArtifactPublisher] plugins to find/process the actual artifacts. | ||
*/ | ||
abstract class DeliveryArtifact { | ||
abstract val name: String | ||
abstract val type: ArtifactType | ||
abstract val versioningStrategy: VersioningStrategy | ||
abstract val reference: String // friendly reference to use within a delivery config | ||
abstract val deliveryConfigName: String? // the delivery config this artifact is a part of | ||
override fun toString() = "$type:$name (ref: $reference)" | ||
open val statuses: Set<ArtifactStatus> = emptySet() | ||
override fun toString() = "${type.toUpperCase()} artifact $name (ref: $reference)" | ||
} |
21 changes: 21 additions & 0 deletions
21
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/artifacts/PublishedArtifact.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.netflix.spinnaker.keel.api.artifacts | ||
|
||
/** | ||
* An immutable data class that represents a published software artifact in the Spinnaker ecosystem. | ||
* | ||
* This class mirrors [com.netflix.spinnaker.kork.artifacts.model.Artifact], but without all the Jackson baggage. | ||
* One notable difference from the kork counterpart is that this class enforces non-nullability of a few | ||
* key fields without which it doesn't make sense for an artifact to exist in Managed Delivery terms. | ||
*/ | ||
data class PublishedArtifact( | ||
val name: String, | ||
val type: String, | ||
val reference: String, | ||
val version: String, | ||
val customKind: Boolean? = null, | ||
val location: String? = null, | ||
val artifactAccount: String? = null, | ||
val provenance: String? = null, | ||
val uuid: String? = null, | ||
val metadata: Map<String, Any?> = emptyMap() | ||
) |
20 changes: 0 additions & 20 deletions
20
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/artifacts/SpinnakerArtifact.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/events/artifacts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/plugins/ArtifactPublisher.kt
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
keel-api/src/main/kotlin/com/netflix/spinnaker/keel/api/plugins/ArtifactSupplier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.netflix.spinnaker.keel.api.plugins | ||
|
||
import com.netflix.spinnaker.keel.api.DeliveryConfig | ||
import com.netflix.spinnaker.keel.api.artifacts.ArtifactStatus | ||
import com.netflix.spinnaker.keel.api.artifacts.ArtifactType | ||
import com.netflix.spinnaker.keel.api.artifacts.BuildMetadata | ||
import com.netflix.spinnaker.keel.api.artifacts.DeliveryArtifact | ||
import com.netflix.spinnaker.keel.api.artifacts.GitMetadata | ||
import com.netflix.spinnaker.keel.api.artifacts.PublishedArtifact | ||
import com.netflix.spinnaker.keel.api.artifacts.VersioningStrategy | ||
import com.netflix.spinnaker.keel.api.events.ArtifactPublishedEvent | ||
import com.netflix.spinnaker.keel.api.support.EventPublisher | ||
import com.netflix.spinnaker.kork.plugins.api.internal.SpinnakerExtensionPoint | ||
|
||
/** | ||
* Keel plugin interface to be implemented by suppliers of artifact information. | ||
* | ||
* The primary responsibility of an [ArtifactSupplier] is to detect new versions of artifacts, using | ||
* whatever mechanism they choose (e.g. they could receive events from another system, | ||
* or poll an artifact repository for artifact versions), and notify keel via the [publishArtifact] | ||
* method, so that the artifact versions can be persisted and evaluated for promotion. | ||
* | ||
* Secondarily, [ArtifactSupplier]s are also periodically called to retrieve the latest available | ||
* version of an artifact. This is so that we don't miss any versions in case of missed or failure | ||
* to handle events in case of downtime, etc. | ||
*/ | ||
interface ArtifactSupplier<T : DeliveryArtifact> : SpinnakerExtensionPoint { | ||
val eventPublisher: EventPublisher | ||
val supportedArtifact: SupportedArtifact<T> | ||
val supportedVersioningStrategies: List<SupportedVersioningStrategy<*>> | ||
|
||
/** | ||
* Publishes an [ArtifactPublishedEvent] to core Keel so that the corresponding artifact version can be | ||
* persisted and evaluated for promotion into deployment environments. | ||
* | ||
* The default implementation of [publishArtifact] simply publishes the event via the [EventPublisher], | ||
* and should *not* be overridden by implementors. | ||
*/ | ||
fun publishArtifact(artifactPublishedEvent: ArtifactPublishedEvent) = | ||
eventPublisher.publishEvent(artifactPublishedEvent) | ||
|
||
/** | ||
* Returns the latest available version for the given [DeliveryArtifact], represented | ||
* as a [PublishedArtifact]. | ||
* | ||
* This function may interact with external systems to retrieve artifact information as needed. | ||
*/ | ||
suspend fun getLatestArtifact(deliveryConfig: DeliveryConfig, artifact: DeliveryArtifact): PublishedArtifact? | ||
|
||
/** | ||
* Given a [PublishedArtifact] supported by this [ArtifactSupplier], return the full representation of | ||
* a version string, if different from [PublishedArtifact.version]. | ||
*/ | ||
fun getFullVersionString(artifact: PublishedArtifact): String = artifact.version | ||
|
||
/** | ||
* Given a [PublishedArtifact] supported by this [ArtifactSupplier], return the display name for the | ||
* artifact version, if different from [PublishedArtifact.version]. | ||
*/ | ||
fun getVersionDisplayName(artifact: PublishedArtifact): String = artifact.version | ||
|
||
/** | ||
* Given a [PublishedArtifact] supported by this [ArtifactSupplier], return the [ArtifactStatus] for | ||
* the artifact, if applicable. | ||
*/ | ||
fun getReleaseStatus(artifact: PublishedArtifact): ArtifactStatus? = null | ||
|
||
/** | ||
* Given a [PublishedArtifact] and a [VersioningStrategy] supported by this [ArtifactSupplier], | ||
* return the [BuildMetadata] for the artifact, if available. | ||
* | ||
* This function is currently *not* expected to make calls to other systems, but only look into | ||
* the metadata available within the [PublishedArtifact] object itself. | ||
*/ | ||
fun getBuildMetadata(artifact: PublishedArtifact, versioningStrategy: VersioningStrategy): BuildMetadata? = null | ||
|
||
/** | ||
* Given a [PublishedArtifact] and a [VersioningStrategy] supported by this [ArtifactSupplier], | ||
* return the [GitMetadata] for the artifact, if available. | ||
* | ||
* This function is currently *not* expected to make calls to other systems, but only look into | ||
* the metadata available within the [PublishedArtifact] object itself. | ||
*/ | ||
fun getGitMetadata(artifact: PublishedArtifact, versioningStrategy: VersioningStrategy): GitMetadata? = null | ||
} | ||
|
||
/** | ||
* Return the [ArtifactSupplier] supporting the specified artifact type. | ||
*/ | ||
fun List<ArtifactSupplier<*>>.supporting(type: ArtifactType) = | ||
find { it.supportedArtifact.name.toLowerCase() == type.toLowerCase() } | ||
?: error("Artifact type '$type' is not supported.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.