Skip to content

Commit

Permalink
Test coverage for k8 lease and rolling update
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Feb 26, 2024
1 parent b0a94fa commit 6bd8ff2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion native-image-tests/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "native-image-tests"

version := "1.0"

scalaVersion := s"2.13.12"
scalaVersion := "2.13.12"

resolvers += "Akka library repository".at("https://repo.akka.io/maven")

Expand Down Expand Up @@ -47,5 +47,6 @@ nativeImageVersion := "21.0.2"
nativeImageOptions := Seq(
"--no-fallback",
"--verbose",
"--initialize-at-build-time=ch.qos.logback",
"-Dakka.native-image.debug=true"
)
5 changes: 4 additions & 1 deletion native-image-tests/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ akka {
cluster {
downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
}
}
}

# just to keep the class name out of graalvms sight
pod-cost-class = "akka.rollingupdate.kubernetes.PodDeletionCost"
8 changes: 1 addition & 7 deletions native-image-tests/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
</encoder>
</appender>

<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>1024</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="STDOUT" />
</appender>

<root level="INFO">
<appender-ref ref="ASYNC"/>
<appender-ref ref="STDOUT"/>
</root>

</configuration>
29 changes: 27 additions & 2 deletions native-image-tests/src/main/scala/com/lightbend/Main.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
package com.lightbend

import akka.actor.ExtendedActorSystem
import akka.actor.ExtensionId
import akka.actor.typed.ActorSystem
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import akka.cluster.typed.Cluster
import akka.cluster.typed.SelfUp
import akka.cluster.typed.Subscribe
import akka.coordination.lease.LeaseSettings
import akka.management.scaladsl.AkkaManagement

import scala.concurrent.duration.DurationInt

object RootBehavior {

def checkK8Lease(system: ActorSystem[_]): Unit = {
// this throws if not all spray-json metadata in place
new akka.coordination.lease.kubernetes.internal.KubernetesJsonSupport {}

// we can't really set up the lease but it is expected to be constructed via config/reflection, so let's check access
// that native-image can't guess
val exensionNameClass = system.settings.config.getString("akka.coordination.lease.kubernetes.lease-class")
val clazz = system.dynamicAccess.getClassFor[akka.coordination.lease.scaladsl.Lease](exensionNameClass).get
// we cant really call it though, but would get a NoSuchMethod here if it can't be found
clazz.getConstructor(classOf[LeaseSettings], classOf[ExtendedActorSystem])

}

def checkK8RollingUpdate(system: ActorSystem[_]): Unit = {
// this throws if not all spray-json metadata in place
new akka.rollingupdate.kubernetes.KubernetesJsonSupport {}
val extensionClazzName = system.settings.config.getString("pod-cost-class")
system.dynamicAccess.getObjectFor[ExtensionId[_]](extensionClazzName).get
}

def apply(): Behavior[AnyRef] = Behaviors.setup { context =>
Behaviors.withTimers { timers =>
// Note that some exceptions in the log from k8 api discovery is expected, see application.conf
AkkaManagement(context.system).start()
timers.startSingleTimer("Timeout", 30.seconds)
Cluster(context.system).subscriptions ! Subscribe(context.self, classOf[SelfUp])

// FIXME cover k8 lease
// FIXME cover rolling-update
// best effort coverage of k8 lease and rolling update without actually using them
checkK8RollingUpdate(context.system)
checkK8Lease(context.system)

Behaviors.receiveMessagePartial {
case SelfUp(_) =>
Expand Down

0 comments on commit 6bd8ff2

Please sign in to comment.