Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch from resource version #251

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ private[client] trait Watchable[F[_], Resource] {

implicit val parserFacade: Facade[Json] = new CirceSupportParser(None, false).facade

def watch(labels: Map[String, String] = Map.empty): Stream[F, Either[String, WatchEvent[Resource]]] = {
val uri = addLabels(labels, config.server.resolve(watchResourceUri))
def watch(
labels: Map[String, String] = Map.empty,
resourceVersion: Option[String] = None
): Stream[F, Either[String, WatchEvent[Resource]]] = {
val uri = addLabels(labels, config.server.resolve(watchResourceUri)).+??("resourceVersion" -> resourceVersion)
val req = Request[F](GET, uri.withQueryParam("watch", "1"))
.withOptionalAuthorization(authorization)
jsonStream(req).map(_.as[WatchEvent[Resource]].leftMap(_.getMessage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ trait WatchableTests[F[_], Resource <: { def metadata: Option[ObjectMeta] }]
private def watchEvents(
expected: Map[String, Set[EventType]],
resourceName: String,
watchingNamespace: Option[String]
watchingNamespace: Option[String],
resourceVersion: Option[String] = None
)(implicit
client: KubernetesClient[F]
) = {
Expand Down Expand Up @@ -120,7 +121,7 @@ trait WatchableTests[F[_], Resource <: { def metadata: Option[ObjectMeta] }]
watchStream = watchingNamespace
.map(watchApi)
.getOrElse(api)
.watch()
.watch(resourceVersion = resourceVersion)
.through(processEvent(receivedEvents, signal))
.evalMap(_ => receivedEvents.get)
.interruptWhen(signal)
Expand Down Expand Up @@ -168,4 +169,22 @@ trait WatchableTests[F[_], Resource <: { def metadata: Option[ObjectMeta] }]
).parTupled
}
}

test(s"watch $resourceName events from a given resourceVersion") {
usingMinikube { implicit client =>
val bootstrapName = s"${resourceName.toLowerCase}-watch-resource-version-test-bootstrap"
val name = s"${resourceName.toLowerCase}-watch-resource-version"
val expected = Set[EventType](EventType.ADDED, EventType.MODIFIED, EventType.DELETED)

for {
_ <- create(defaultNamespace, bootstrapName)
resource <- retry(getChecked(defaultNamespace, bootstrapName))
resourceVersion = resource.metadata.flatMap(_.resourceVersion).get
_ <- (
watchEvents(Map(defaultNamespace -> expected), name, Some(defaultNamespace), Some(resourceVersion)),
F.sleep(100.millis) *> sendEvents(defaultNamespace, name) *> sendToAnotherNamespace(name)
).parTupled
} yield ()
}
}
}
Loading