Skip to content

Commit

Permalink
Merge pull request #617 in SPKR/keel-nflx from currentVersion to master
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 09f4c783ead79715799654ae800e76d92086d7eb
Merge: d9bda5c41 729313f24
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Fri Oct 8 13:37:40 2021 -0700

    Merge branch 'currentVersion' of ssh://stash.corp.netflix.com:7999/spkr/keel-nflx into currentVersion

commit d9bda5c41c2b526ab742177506f2510092cabfc2
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Fri Oct 8 13:36:57 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit be24e4c1a55dba90863c42b572586b1e8b36bd95
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Thu Oct 7 13:58:56 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit a0a14f31072eb5afed2897d3c6d9bf19873e3468
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Wed Oct 6 21:19:34 2021 -0700

    feat(latestVersion): add latest approved version of an artifact

commit 729313f24f87ef46b01b3395ecc714ddb0f492f3
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Fri Oct 8 13:36:57 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit b3140d16f0eed00aca669fab84895177e178feac
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Thu Oct 7 14:04:37 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit e707108ab9f34e99e6cad187b7bd52e1a44d6185
Merge: 1121e4cf0 afffa4f4c
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Thu Oct 7 13:59:47 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit 1121e4cf0ff542dde60236f38b6f3b95978cbe17
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Thu Oct 7 13:58:56 2021 -0700

    feat(latestVersion): adding latest version + bug fixes

commit be603f5d50505246776a4cb51bb45a7d68f163a2
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Wed Oct 6 21:19:34 2021 -0700

    feat(latestVersion): add latest approved version of an artifact

commit afffa4f4cd35070ffb0d4dfcd70a8d10ce085757
Author: Gal Yardeni <gyardeni@netflix.com>
Date:   Wed Oct 6 21:19:34 2021 -0700

    feat(latestVersion): add latest approved version of an artifact

(cherry picked from commit 12b26f1388d2931901bba3137d579b5a2b8bcfb2)
  • Loading branch information
gal-yardeni authored and osoriano committed Sep 2, 2023
1 parent 93d62f7 commit 3a9958b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ data class PublishedArtifact(
name: String,
type: String,
version: String,
reference: String? = null,
status: ArtifactStatus? = null,
createdAt: Instant? = null,
gitMetadata: GitMetadata? = null,
Expand All @@ -43,7 +44,7 @@ data class PublishedArtifact(
) : this(
name = name,
type = type.toLowerCase(),
reference = name,
reference = reference?: name,
version = version,
metadata = (metadata ?: emptyMap()) + mapOf(
"releaseStatus" to status?.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ interface ArtifactRepository : PeriodicallyCheckedRepository<DeliveryArtifact> {
startTime: Instant,
endTime: Instant
): Int

/**
* @return the latest artifact version of [artifact] approved for use in [environmentName]
*
*/
fun getLatestApprovedInEnvArtifactVersion(
config: DeliveryConfig,
artifact: DeliveryArtifact,
environmentName: String
): PublishedArtifact?
}

class NoSuchArtifactException(name: String, type: ArtifactType) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ class CombinedRepository(
override fun getArtifactVersion(artifact: DeliveryArtifact, version: String, status: ArtifactStatus?): PublishedArtifact? =
artifactRepository.getArtifactVersion(artifact, version, status)

override fun getLatestApprovedInEnvArtifactVersion(config: DeliveryConfig, artifact: DeliveryArtifact, environmentName: String): PublishedArtifact? =
artifactRepository.getLatestApprovedInEnvArtifactVersion(config, artifact, environmentName)

override fun updateArtifactMetadata(artifact: PublishedArtifact, artifactMetadata: ArtifactMetadata) =
artifactRepository.updateArtifactMetadata(artifact, artifactMetadata)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ interface KeelRepository : KeelReadOnlyRepository {

fun getArtifactVersion(artifact: DeliveryArtifact, version: String, status: ArtifactStatus? = null): PublishedArtifact?

fun getLatestApprovedInEnvArtifactVersion(config: DeliveryConfig, artifact: DeliveryArtifact, environmentName: String): PublishedArtifact?

fun updateArtifactMetadata(artifact: PublishedArtifact, artifactMetadata: ArtifactMetadata)

fun deleteArtifact(artifact: DeliveryArtifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class SqlArtifactRepository(
PublishedArtifact(
name = name,
type = type,
reference = artifact.reference,
version = version,
status = status,
createdAt = createdAt,
Expand Down Expand Up @@ -1928,6 +1929,19 @@ class SqlArtifactRepository(
.fetchSingleInto<Int>()
}

override fun getLatestApprovedInEnvArtifactVersion(
config: DeliveryConfig,
artifact: DeliveryArtifact,
environmentName: String
): PublishedArtifact? {
latestVersionApprovedIn(config, artifact, environmentName)
?.let { version ->
return getArtifactVersion(artifact, version, null)
}
return null
}


private fun priorVersionDeployedIn(
environmentId: String,
artifactId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ApplicationContext() {
var allVersions: Map<ArtifactAndEnvironment, List<PublishedArtifactInEnvironment>> = emptyMap()

fun getArtifactVersions(deliveryArtifact: DeliveryArtifact, environmentName: String): List<PublishedArtifactInEnvironment>? {
return allVersions[ArtifactAndEnvironment(artifact = deliveryArtifact, environmentName = environmentName)]
return if (allVersions.isNotEmpty()) {
allVersions[ArtifactAndEnvironment(artifact = deliveryArtifact, environmentName = environmentName)]
} else null
}

fun getConfig(): DeliveryConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ class ApplicationFetcher(
))
}

@DgsData(parentType = DgsConstants.MDARTIFACT.TYPE_NAME, field = DgsConstants.MDARTIFACT.LatestApprovedVersion)
fun latestApprovedVersion(dfe: DataFetchingEnvironment): MdArtifactVersionInEnvironment? {
val artifact: MdArtifact = dfe.getSource()
val config = applicationFetcherSupport.getDeliveryConfigFromContext(dfe)
val deliveryArtifact = config.matchingArtifactByReference(artifact.reference) ?: return null

//[gyardeni + rhorev] please note - some values (like MdComparisonLinks) will not be retrieved for MdArtifactVersionInEnvironment
//due to our current dgs model.
keelRepository.getLatestApprovedInEnvArtifactVersion(config, deliveryArtifact, artifact.environment)
?.let {
return it.toDgs(artifact.environment)
}

return null
}

@DgsData(parentType = DgsConstants.MDARTIFACTVERSIONINENVIRONMENT.TYPE_NAME, field = DgsConstants.MDARTIFACTVERSIONINENVIRONMENT.Constraints)
fun artifactConstraints(dfe: DataFetchingEnvironment): CompletableFuture<List<MdConstraint>>? {
val dataLoader: DataLoader<EnvironmentArtifactAndVersion, List<MdConstraint>> = dfe.getDataLoader(ConstraintsDataLoader.Descriptor.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import com.netflix.spinnaker.keel.api.SubnetAwareLocations
import com.netflix.spinnaker.keel.api.TaskStatus
import com.netflix.spinnaker.keel.api.actuation.ExecutionSummary
import com.netflix.spinnaker.keel.api.actuation.RolloutStatus
import com.netflix.spinnaker.keel.api.actuation.RolloutTarget
import com.netflix.spinnaker.keel.api.actuation.RolloutTargetWithStatus
import com.netflix.spinnaker.keel.api.actuation.Stage
import com.netflix.spinnaker.keel.api.artifacts.GitMetadata
import com.netflix.spinnaker.keel.api.artifacts.PublishedArtifact
import com.netflix.spinnaker.keel.bakery.diff.PackageDiff
import com.netflix.spinnaker.keel.graphql.types.MdArtifact
import com.netflix.spinnaker.keel.graphql.types.MdArtifactVersionInEnvironment
import com.netflix.spinnaker.keel.graphql.types.MdCommitInfo
import com.netflix.spinnaker.keel.graphql.types.MdDeployLocation
import com.netflix.spinnaker.keel.graphql.types.MdDeployTarget
Expand Down Expand Up @@ -191,3 +192,18 @@ fun TaskStatus.toDgs(): MdTaskStatus =
TaskStatus.BUFFERED -> MdTaskStatus.BUFFERED
TaskStatus.SKIPPED -> MdTaskStatus.SKIPPED
}

fun PublishedArtifact.toDgs(environmentName: String) =
MdArtifactVersionInEnvironment(
id = "latest-approved-${environmentName}-${reference}-${version}",
version = version,
buildNumber = buildNumber,
createdAt = createdAt,
gitMetadata = if (gitMetadata == null) {
null
} else {
gitMetadata?.toDgs()
},
environment = environmentName,
reference = reference,
)
1 change: 1 addition & 0 deletions keel-web/src/main/resources/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type MdArtifact {
reference: String!
versions(statuses: [MdArtifactStatusInEnvironment!], versions: [String!], limit: Int): [MdArtifactVersionInEnvironment!]
pinnedVersion: MdPinnedVersion
latestApprovedVersion: MdArtifactVersionInEnvironment
resources: [MdResource!]
}

Expand Down

0 comments on commit 3a9958b

Please sign in to comment.