From a01a8bdfd9ed2174fbb3395ee31c564b659fb1fa Mon Sep 17 00:00:00 2001 From: David O'Riordan Date: Sun, 15 Oct 2023 19:10:35 +0100 Subject: [PATCH] Migrate integration tests to Scala 3 --- .../it/scala/skuber/CustomResourceSpec.scala | 13 +++++------ akka/src/it/scala/skuber/DeploymentSpec.scala | 5 ++-- akka/src/it/scala/skuber/ExecSpec.scala | 4 ++-- .../skuber/HorizontalPodAutoscalerSpec.scala | 5 +++- akka/src/it/scala/skuber/K8SFixture.scala | 9 ++++---- akka/src/it/scala/skuber/NamespaceSpec.scala | 4 ++-- akka/src/it/scala/skuber/PatchSpec.scala | 4 ++-- .../skuber/PodDisruptionBudgetSpec.scala | 10 ++++---- akka/src/it/scala/skuber/PodLogSpec.scala | 4 ++-- .../scala/skuber/WatchContinuouslySpec.scala | 3 ++- build.sbt | 4 ++-- .../it/scala/skuber/CustomResourceSpec.scala | 23 ++++++++++--------- .../src/it/scala/skuber/DeploymentSpec.scala | 1 + pekko/src/it/scala/skuber/ExecSpec.scala | 5 ++-- .../skuber/HorizontalPodAutoscalerSpec.scala | 3 ++- pekko/src/it/scala/skuber/K8SFixture.scala | 9 ++++---- pekko/src/it/scala/skuber/NamespaceSpec.scala | 4 ++-- pekko/src/it/scala/skuber/PatchSpec.scala | 4 ++-- .../skuber/PodDisruptionBudgetSpec.scala | 6 +++-- pekko/src/it/scala/skuber/PodLogSpec.scala | 4 ++-- .../scala/skuber/WatchContinuouslySpec.scala | 8 +++---- 21 files changed, 70 insertions(+), 62 deletions(-) diff --git a/akka/src/it/scala/skuber/CustomResourceSpec.scala b/akka/src/it/scala/skuber/CustomResourceSpec.scala index 216e66d8..d9e0e5d1 100644 --- a/akka/src/it/scala/skuber/CustomResourceSpec.scala +++ b/akka/src/it/scala/skuber/CustomResourceSpec.scala @@ -8,11 +8,10 @@ import akka.stream.scaladsl._ import org.scalatest.matchers.should.Matchers import org.scalatest.concurrent.Eventually import play.api.libs.json._ - import skuber.api.client.K8SException import skuber.model.ResourceSpecification.{ScaleSubresource, Schema, Subresources} import skuber.model.apiextensions.v1.CustomResourceDefinition -import skuber.model.{CustomResource, ListResource, ResourceDefinition, ResourceSpecification} +import skuber.model.{CustomResource, ListResource, ResourceDefinition, ResourceSpecification, Scale} /** @@ -95,7 +94,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { storage = true, schema = Some(Schema(jsonSchema)), // schema is required since v1 subresources = Some(Subresources() - .withStatusSubresource // enable status subresource + .withStatusSubresource()// enable status subresource .withScaleSubresource(ScaleSubresource(".spec.desiredReplicas", ".status.actualReplicas")) // enable scale subresource ) ) @@ -113,7 +112,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { // This needs to be passed implicitly to the skuber API to enable it to process TestResource requests. // The json paths in the Scale subresource must map to the replica fields in Spec and Status // respectively above - implicit val testResourceDefinition = ResourceDefinition[TestResource]( + implicit val testResourceDefinition: ResourceDefinition[TestResource] = ResourceDefinition[TestResource]( group = "test.skuber.io", version = "v1alpha1", kind = "SkuberTest", @@ -123,8 +122,8 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { // the following implicit values enable the scale and status methods on the skuber API to be called for this type // (these calls will be rejected unless the subresources are enabled on the CRD) - implicit val statusSubEnabled=CustomResource.statusMethodsEnabler[TestResource] - implicit val scaleSubEnabled=CustomResource.scalingMethodsEnabler[TestResource] + implicit val statusSubEnabled: model.HasStatusSubresource[TestResource] =CustomResource.statusMethodsEnabler[TestResource] + implicit val scaleSubEnabled: Scale.SubresourceSpec[TestResource] =CustomResource.scalingMethodsEnabler[TestResource] // Construct an exportable Kubernetes CRD that mirrors the details in the matching implicit resource definition above - // the test will create it on Kubernetes so that the subsequent test requests can be handled by the cluster @@ -228,7 +227,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { trackedEvents += event } - def getCurrentResourceVersion: Future[String] = k8s.list[TestResourceList].map { l => + def getCurrentResourceVersion: Future[String] = k8s.list[TestResourceList]().map { l => l.resourceVersion } def watchAndTrackEvents(sinceVersion: String) = diff --git a/akka/src/it/scala/skuber/DeploymentSpec.scala b/akka/src/it/scala/skuber/DeploymentSpec.scala index 0015cb5a..2951967a 100644 --- a/akka/src/it/scala/skuber/DeploymentSpec.scala +++ b/akka/src/it/scala/skuber/DeploymentSpec.scala @@ -5,11 +5,14 @@ import org.scalatest.concurrent.{Eventually, ScalaFutures} import skuber.model.{Container, LabelSelector, Pod} import skuber.model.apps.v1.Deployment import skuber.api.client.{DeleteOptions,DeletePropagation,K8SException} +import LabelSelector.dsl._ import scala.concurrent.duration._ import scala.concurrent.{Await, Future} import scala.util.{Failure, Success} +import scala.language.{postfixOps, reflectiveCalls} + class DeploymentSpec extends K8SFixture with Eventually with Matchers { val nginxDeploymentName: String = java.util.UUID.randomUUID().toString @@ -29,7 +32,6 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers { it should "upgrade the newly created deployment" in { k8s => k8s.get[Deployment](nginxDeploymentName).flatMap { d => - println(s"DEPLOYMENT TO UPDATE ==> $d") val updatedDeployment = d.updateContainer(getNginxContainer("1.9.1")) k8s.update(updatedDeployment).flatMap { _ => eventually(timeout(200.seconds), interval(5.seconds)) { @@ -61,7 +63,6 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers { def getNginxContainer(version: String): Container = Container(name = "nginx", image = "nginx:" + version).exposePort(80) def getNginxDeployment(name: String, version: String): Deployment = { - import LabelSelector.dsl._ val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/akka/src/it/scala/skuber/ExecSpec.scala b/akka/src/it/scala/skuber/ExecSpec.scala index b57cbd3a..334a1d4c 100644 --- a/akka/src/it/scala/skuber/ExecSpec.scala +++ b/akka/src/it/scala/skuber/ExecSpec.scala @@ -27,14 +27,14 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf Await.result(k8s.create(getNginxPod(nginxPodName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit Await.result(k8s.delete[Pod](nginxPodName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/akka/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala b/akka/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala index 1a7dc21d..50f57fab 100644 --- a/akka/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala +++ b/akka/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala @@ -7,8 +7,12 @@ import skuber.model.autoscaling.v2.HorizontalPodAutoscaler import skuber.model.autoscaling.v2.HorizontalPodAutoscaler.{ResourceMetricSource, UtilizationTarget} import skuber.model.{Container, LabelSelector, Pod, Resource} import skuber.model.apps.v1.Deployment +import LabelSelector.dsl._ + import skuber.api.client._ +import scala.language.{postfixOps, reflectiveCalls} + class HorizontalPodAutoscalerSpec extends K8SFixture with Eventually with Matchers { behavior of "HorizontalPodAutoscalerV2" @@ -85,7 +89,6 @@ class HorizontalPodAutoscalerSpec extends K8SFixture with Eventually with Matche } def getNginxDeployment(name: String, version: String): Deployment = { - import LabelSelector.dsl._ val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/akka/src/it/scala/skuber/K8SFixture.scala b/akka/src/it/scala/skuber/K8SFixture.scala index 1c41d189..94733444 100644 --- a/akka/src/it/scala/skuber/K8SFixture.scala +++ b/akka/src/it/scala/skuber/K8SFixture.scala @@ -4,15 +4,16 @@ import akka.actor.ActorSystem import org.scalatest.FutureOutcome import com.typesafe.config.ConfigFactory import org.scalatest.flatspec.FixtureAsyncFlatSpec - import skuber.akkaclient._ +import scala.concurrent.ExecutionContext + trait K8SFixture extends FixtureAsyncFlatSpec { override type FixtureParam = AkkaKubernetesClient - implicit val system = ActorSystem() - implicit val dispatcher = system.dispatcher + implicit val system: ActorSystem = ActorSystem() + implicit val dispatcher: ExecutionContext = system.dispatcher val config = ConfigFactory.load() @@ -22,7 +23,7 @@ trait K8SFixture extends FixtureAsyncFlatSpec { complete { withFixture(test.toNoArgAsyncTest(k8s)) } lastly { - k8s.close + k8s.close() } } } diff --git a/akka/src/it/scala/skuber/NamespaceSpec.scala b/akka/src/it/scala/skuber/NamespaceSpec.scala index 0b1fe368..1222a8a7 100644 --- a/akka/src/it/scala/skuber/NamespaceSpec.scala +++ b/akka/src/it/scala/skuber/NamespaceSpec.scala @@ -40,14 +40,14 @@ class NamespaceSpec extends K8SFixture with Eventually with Matchers { k8s.usingNamespace(namespace1Name).create(pod1) .map { p => assert(p.name == nginxPodName1) - assert(p.namespace == namespace1Name) + assert(p.metadata.namespace == namespace1Name) } } it should "honor namespace precedence hierarchy: object > client" in { k8s => k8s.usingNamespace(namespace1Name).create(pod2).map { p => assert(p.name == nginxPodName2) - assert(p.namespace == namespace2Name) + assert(p.metadata.namespace == namespace2Name) } } diff --git a/akka/src/it/scala/skuber/PatchSpec.scala b/akka/src/it/scala/skuber/PatchSpec.scala index ff5cecb5..b238fccc 100644 --- a/akka/src/it/scala/skuber/PatchSpec.scala +++ b/akka/src/it/scala/skuber/PatchSpec.scala @@ -23,14 +23,14 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA Await.result(k8s.create(getNginxPod(nginxPodName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit Await.result(k8s.delete[Pod](nginxPodName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/akka/src/it/scala/skuber/PodDisruptionBudgetSpec.scala b/akka/src/it/scala/skuber/PodDisruptionBudgetSpec.scala index 2355dd33..6bae2879 100644 --- a/akka/src/it/scala/skuber/PodDisruptionBudgetSpec.scala +++ b/akka/src/it/scala/skuber/PodDisruptionBudgetSpec.scala @@ -6,14 +6,16 @@ import skuber.api.client.K8SException import skuber.model.{Container, LabelSelector, Pod} import skuber.model.apps.v1.Deployment import skuber.model.policy.v1.PodDisruptionBudget +import LabelSelector.dsl._ + +import scala.language.{postfixOps, reflectiveCalls} class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { behavior of "PodDisruptionBudget" it should "create a PodDisruptionBudget" in { k8s => val name: String = java.util.UUID.randomUUID().toString - k8s.create(getNginxDeployment(name, "1.7.9")) flatMap { d => - import LabelSelector.dsl._ + k8s.create(getNginxDeployment(name, "1.7.9")) flatMap { _ => k8s.create(PodDisruptionBudget(name) .withMinAvailable(Left(1)) .withLabelSelector("app" is "nginx") @@ -26,8 +28,7 @@ class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { it should "update a PodDisruptionBudget" in { k8s => val name: String = java.util.UUID.randomUUID().toString - k8s.create(getNginxDeployment(name, "1.7.9")) flatMap { d => - import LabelSelector.dsl._ + k8s.create(getNginxDeployment(name, "1.7.9")) flatMap { _ => k8s.create(PodDisruptionBudget(name) .withMinAvailable(Left(1)) .withLabelSelector("app" is "nginx") @@ -65,7 +66,6 @@ class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { } def getNginxDeployment(name: String, version: String): Deployment = { - import LabelSelector.dsl._ val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/akka/src/it/scala/skuber/PodLogSpec.scala b/akka/src/it/scala/skuber/PodLogSpec.scala index 44f4ff09..3f1703d8 100644 --- a/akka/src/it/scala/skuber/PodLogSpec.scala +++ b/akka/src/it/scala/skuber/PodLogSpec.scala @@ -29,14 +29,14 @@ class PodLogSpec extends K8SFixture with Eventually with Matchers with BeforeAnd Await.result(k8s.create(getNginxPod(podName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit(config) Await.result(k8s.delete[Pod](podName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/akka/src/it/scala/skuber/WatchContinuouslySpec.scala b/akka/src/it/scala/skuber/WatchContinuouslySpec.scala index d31838ff..22936eb5 100644 --- a/akka/src/it/scala/skuber/WatchContinuouslySpec.scala +++ b/akka/src/it/scala/skuber/WatchContinuouslySpec.scala @@ -25,7 +25,7 @@ class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers wit val deploymentOne = getNginxDeployment(deploymentOneName, "1.7.9") val deploymentTwo = getNginxDeployment(deploymentTwoName, "1.7.9") - val stream = k8s.list[DeploymentList].map { l => + val stream = k8s.list[DeploymentList]().map { l => k8s.watchAllContinuously[Deployment](Some(l.resourceVersion)) .viaMat(KillSwitches.single)(Keep.right) .filter(event => event._object.name == deploymentOneName || event._object.name == deploymentTwoName) @@ -175,6 +175,7 @@ class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers wit def getNginxDeployment(name: String, version: String): Deployment = { import LabelSelector.dsl._ + import scala.language.reflectiveCalls val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/build.sbt b/build.sbt index 16690595..deb43690 100644 --- a/build.sbt +++ b/build.sbt @@ -79,7 +79,7 @@ val pekkoStreamTestkit = pekkoGroup %% "pekko-stream-testkit" % pekkoVersion val pekkoActors = pekkoGroup %% "pekko-actor" % pekkoVersion lazy val pekkoClientDependencies = Seq(pekkoActors, pekkoHttp, pekkoStream, pekkoSlf4j, logback, pekkoStreamTestkit, - scalaCheck % Test, specs2 % Test, mockito % Test, scalaTestMockito % Test, scalaTest % Test) + scalaCheck % Test, specs2 % Test, mockito % Test, scalaTestMockito % Test, scalaTest % "it, test") lazy val pekko = (project in file("pekko")) .configs(IntegrationTest) @@ -106,7 +106,7 @@ val akkaBSLStreamTestKit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaBS val akkaBSLActors = "com.typesafe.akka" %% "akka-actor" % akkaBSLVersion lazy val akkaBSLClientDependencies = Seq(akkaBSLActors, akkaBSLHttp, akkaBSLStream, akkaBSLSlf4j, logback, akkaBSLStreamTestKit, - scalaCheck % Test, specs2 % Test, mockito % Test, scalaTestMockito % Test, scalaTest % Test) + scalaCheck % Test, specs2 % Test, mockito % Test, scalaTestMockito % Test, scalaTest % "it, test") lazy val akka = (project in file("akka")) .configs(IntegrationTest) diff --git a/pekko/src/it/scala/skuber/CustomResourceSpec.scala b/pekko/src/it/scala/skuber/CustomResourceSpec.scala index e1667582..b6f285f2 100644 --- a/pekko/src/it/scala/skuber/CustomResourceSpec.scala +++ b/pekko/src/it/scala/skuber/CustomResourceSpec.scala @@ -9,11 +9,10 @@ import pekko.stream.scaladsl._ import org.scalatest.matchers.should.Matchers import org.scalatest.concurrent.Eventually import play.api.libs.json._ - import skuber.api.client.K8SException import skuber.model.ResourceSpecification.{ScaleSubresource, Schema, Subresources} import skuber.model.apiextensions.v1.CustomResourceDefinition -import skuber.model.{CustomResource, ListResource, ResourceDefinition, ResourceSpecification} +import skuber.model.{CustomResource, ListResource, ResourceDefinition, ResourceSpecification, Scale} /** @@ -96,7 +95,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { storage = true, schema = Some(Schema(jsonSchema)), // schema is required since v1 subresources = Some(Subresources() - .withStatusSubresource // enable status subresource + .withStatusSubresource() // enable status subresource .withScaleSubresource(ScaleSubresource(".spec.desiredReplicas", ".status.actualReplicas")) // enable scale subresource ) ) @@ -114,18 +113,18 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { // This needs to be passed implicitly to the skuber API to enable it to process TestResource requests. // The json paths in the Scale subresource must map to the replica fields in Spec and Status // respectively above - implicit val testResourceDefinition = ResourceDefinition[TestResource]( + implicit val testResourceDefinition: ResourceDefinition[TestResource] = ResourceDefinition[TestResource]( group = "test.skuber.io", version = "v1alpha1", kind = "SkuberTest", - shortNames = List("test","tests"), // not needed, but handy if debugging the tests + shortNames = List("test", "tests"), // not needed, but handy if debugging the tests versions = getVersions() // only needed for creating or updating the CRD, not needed if just manipulating custon resources ) // the following implicit values enable the scale and status methods on the skuber API to be called for this type // (these calls will be rejected unless the subresources are enabled on the CRD) - implicit val statusSubEnabled=CustomResource.statusMethodsEnabler[TestResource] - implicit val scaleSubEnabled=CustomResource.scalingMethodsEnabler[TestResource] + implicit val statusSubEnabled: model.HasStatusSubresource[TestResource] = CustomResource.statusMethodsEnabler[TestResource] + implicit val scaleSubEnabled: Scale.SubresourceSpec[TestResource] = CustomResource.scalingMethodsEnabler[TestResource] // Construct an exportable Kubernetes CRD that mirrors the details in the matching implicit resource definition above - // the test will create it on Kubernetes so that the subsequent test requests can be handled by the cluster @@ -221,6 +220,8 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { import skuber.api.client.{EventType, WatchEvent} import scala.collection.mutable.ListBuffer + import TestResource.testResourceDefinition + val testResourceName=java.util.UUID.randomUUID().toString val testResource = TestResource(testResourceName, TestResource.Spec(1)) @@ -229,7 +230,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { trackedEvents += event } - def getCurrentResourceVersion: Future[String] = k8s.list[TestResourceList].map { l => + def getCurrentResourceVersion: Future[String] = k8s.list[TestResourceList]().map { l => l.resourceVersion } def watchAndTrackEvents(sinceVersion: String) = @@ -243,7 +244,7 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { def createTestResource= k8s.create(testResource) def deleteTestResource= k8s.delete[TestResource](testResourceName) - val killSwitchFut = for { + val killSwitchFut: Future[UniqueKillSwitch] = for { currentTestResourceVersion <- getCurrentResourceVersion (kill, _) <- watchAndTrackEvents(currentTestResourceVersion) testResource <- createTestResource @@ -253,8 +254,8 @@ class CustomResourceSpec extends K8SFixture with Eventually with Matchers { eventually(timeout(200.seconds), interval(3.seconds)) { trackedEvents.size shouldBe 2 trackedEvents(0)._type shouldBe EventType.ADDED - trackedEvents(0)._object.name shouldBe testResource.name - trackedEvents(0)._object.spec shouldBe testResource.spec + trackedEvents(0)._object.name should be(testResource.name) + assert(trackedEvents(0)._object.spec.desiredReplicas == testResource.spec.desiredReplicas) trackedEvents(1)._type shouldBe EventType.DELETED } diff --git a/pekko/src/it/scala/skuber/DeploymentSpec.scala b/pekko/src/it/scala/skuber/DeploymentSpec.scala index d561d90a..060e392b 100644 --- a/pekko/src/it/scala/skuber/DeploymentSpec.scala +++ b/pekko/src/it/scala/skuber/DeploymentSpec.scala @@ -9,6 +9,7 @@ import skuber.api.client.{DeleteOptions,DeletePropagation,K8SException} import scala.concurrent.duration._ import scala.concurrent.Await import scala.util.{Failure, Success} +import scala.language.{postfixOps, reflectiveCalls} class DeploymentSpec extends K8SFixture with Eventually with Matchers { val nginxDeploymentName: String = java.util.UUID.randomUUID().toString diff --git a/pekko/src/it/scala/skuber/ExecSpec.scala b/pekko/src/it/scala/skuber/ExecSpec.scala index 43aaa7f1..557ef875 100644 --- a/pekko/src/it/scala/skuber/ExecSpec.scala +++ b/pekko/src/it/scala/skuber/ExecSpec.scala @@ -16,7 +16,6 @@ import skuber.api.client.K8SException import skuber.json.format._ import skuber.model.{Container, Pod} - import skuber.pekkoclient.k8sInit class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll { @@ -31,14 +30,14 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf Await.result(k8s.create(getNginxPod(nginxPodName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit Await.result(k8s.delete[Pod](nginxPodName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/pekko/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala b/pekko/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala index 13ce247c..e77f468c 100644 --- a/pekko/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala +++ b/pekko/src/it/scala/skuber/HorizontalPodAutoscalerSpec.scala @@ -7,9 +7,11 @@ import skuber.model.autoscaling.v2.HorizontalPodAutoscaler.{ResourceMetricSource import skuber.model.{Container, LabelSelector, Pod, Resource} import skuber.model.apps.v1.Deployment import skuber.api.client._ +import LabelSelector.dsl._ import scala.concurrent.Await import scala.concurrent.duration.DurationInt +import scala.language.{postfixOps, reflectiveCalls} class HorizontalPodAutoscalerSpec extends K8SFixture with Eventually with Matchers { behavior of "HorizontalPodAutoscalerV2" @@ -103,7 +105,6 @@ class HorizontalPodAutoscalerSpec extends K8SFixture with Eventually with Matche } def getNginxDeployment(name: String, version: String): Deployment = { - import LabelSelector.dsl._ val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/pekko/src/it/scala/skuber/K8SFixture.scala b/pekko/src/it/scala/skuber/K8SFixture.scala index e2cccd84..c9dbe542 100644 --- a/pekko/src/it/scala/skuber/K8SFixture.scala +++ b/pekko/src/it/scala/skuber/K8SFixture.scala @@ -4,15 +4,16 @@ import org.apache.pekko.actor.ActorSystem import org.scalatest.FutureOutcome import com.typesafe.config.ConfigFactory import org.scalatest.flatspec.FixtureAsyncFlatSpec - import skuber.pekkoclient._ +import scala.concurrent.ExecutionContext + trait K8SFixture extends FixtureAsyncFlatSpec { override type FixtureParam = PekkoKubernetesClient - implicit val system = ActorSystem() - implicit val dispatcher = system.dispatcher + implicit val system: ActorSystem = ActorSystem() + implicit val dispatcher: ExecutionContext = system.dispatcher val config = ConfigFactory.load() @@ -22,7 +23,7 @@ trait K8SFixture extends FixtureAsyncFlatSpec { complete { withFixture(test.toNoArgAsyncTest(k8s)) } lastly { - k8s.close + k8s.close() } } } diff --git a/pekko/src/it/scala/skuber/NamespaceSpec.scala b/pekko/src/it/scala/skuber/NamespaceSpec.scala index 42a8b114..b53205f4 100644 --- a/pekko/src/it/scala/skuber/NamespaceSpec.scala +++ b/pekko/src/it/scala/skuber/NamespaceSpec.scala @@ -42,14 +42,14 @@ class NamespaceSpec extends K8SFixture with Eventually with Matchers { k8s.usingNamespace(namespace1Name).create(pod1) .map { p => assert(p.name == nginxPodName1) - assert(p.namespace == namespace1Name) + assert(p.metadata.namespace == namespace1Name) } } it should "honor namespace precedence hierarchy: object > client" in { k8s => k8s.usingNamespace(namespace1Name).create(pod2).map { p => assert(p.name == nginxPodName2) - assert(p.namespace == namespace2Name) + assert(p.metadata.namespace == namespace2Name) } } diff --git a/pekko/src/it/scala/skuber/PatchSpec.scala b/pekko/src/it/scala/skuber/PatchSpec.scala index 2455d054..8dae6f41 100644 --- a/pekko/src/it/scala/skuber/PatchSpec.scala +++ b/pekko/src/it/scala/skuber/PatchSpec.scala @@ -24,14 +24,14 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA Await.result(k8s.create(getNginxPod(nginxPodName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit Await.result(k8s.delete[Pod](nginxPodName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/pekko/src/it/scala/skuber/PodDisruptionBudgetSpec.scala b/pekko/src/it/scala/skuber/PodDisruptionBudgetSpec.scala index cb3fbc1b..917be979 100644 --- a/pekko/src/it/scala/skuber/PodDisruptionBudgetSpec.scala +++ b/pekko/src/it/scala/skuber/PodDisruptionBudgetSpec.scala @@ -7,6 +7,9 @@ import skuber.api.client.K8SException import skuber.model.{Container, LabelSelector, Pod} import skuber.model.apps.v1.Deployment import skuber.model.policy.v1.PodDisruptionBudget +import LabelSelector.dsl._ + +import scala.language.{postfixOps, reflectiveCalls} class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { behavior of "PodDisruptionBudget" @@ -14,7 +17,6 @@ class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { it should "create a PodDisruptionBudget" in { k8s => val name: String = java.util.UUID.randomUUID().toString k8s.create(getNginxDeployment(name, "1.7.9")) flatMap { d => - import LabelSelector.dsl._ k8s.create(PodDisruptionBudget(name) .withMinAvailable(Left(1)) .withLabelSelector("app" is "nginx") @@ -66,7 +68,7 @@ class PodDisruptionBudgetSpec extends K8SFixture with Eventually with Matchers { } def getNginxDeployment(name: String, version: String): Deployment = { - import LabelSelector.dsl._ + val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx") diff --git a/pekko/src/it/scala/skuber/PodLogSpec.scala b/pekko/src/it/scala/skuber/PodLogSpec.scala index 9471b40a..eb91eaa9 100644 --- a/pekko/src/it/scala/skuber/PodLogSpec.scala +++ b/pekko/src/it/scala/skuber/PodLogSpec.scala @@ -33,14 +33,14 @@ class PodLogSpec extends K8SFixture with Eventually with Matchers with BeforeAnd Await.result(k8s.create(getNginxPod(podName, "1.7.9")), 3.second) // Let the pod running Thread.sleep(3000) - k8s.close + k8s.close() } override def afterAll(): Unit = { val k8s = k8sInit(config) Await.result(k8s.delete[Pod](podName), 3.second) Thread.sleep(3000) - k8s.close + k8s.close() super.afterAll() } diff --git a/pekko/src/it/scala/skuber/WatchContinuouslySpec.scala b/pekko/src/it/scala/skuber/WatchContinuouslySpec.scala index ffaa78a1..b58851e5 100644 --- a/pekko/src/it/scala/skuber/WatchContinuouslySpec.scala +++ b/pekko/src/it/scala/skuber/WatchContinuouslySpec.scala @@ -2,15 +2,12 @@ package skuber import scala.concurrent.duration._ import scala.concurrent.Await -import scala.language.postfixOps - +import scala.language.{postfixOps, reflectiveCalls} import org.scalatest.matchers.should.Matchers import org.scalatest.concurrent.{Eventually, ScalaFutures} import org.scalatest.time.{Seconds, Span} - import org.apache.pekko.stream.KillSwitches import org.apache.pekko.stream.scaladsl.{Keep, Sink} - import skuber.model.{Container, LabelSelector, Pod} import skuber.model.apps.v1.{Deployment, DeploymentList} @@ -27,7 +24,7 @@ class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers wit val deploymentOne = getNginxDeployment(deploymentOneName, "1.7.9") val deploymentTwo = getNginxDeployment(deploymentTwoName, "1.7.9") - val stream = k8s.list[DeploymentList].map { l => + val stream = k8s.list[DeploymentList]().map { l => k8s.watchAllContinuously[Deployment](Some(l.resourceVersion)) .viaMat(KillSwitches.single)(Keep.right) .filter(event => event._object.name == deploymentOneName || event._object.name == deploymentTwoName) @@ -177,6 +174,7 @@ class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers wit def getNginxDeployment(name: String, version: String): Deployment = { import LabelSelector.dsl._ + import scala.language.reflectiveCalls val nginxContainer = getNginxContainer(version) val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx") Deployment(name).withTemplate(nginxTemplate).withLabelSelector("app" is "nginx")