Skip to content

Commit

Permalink
uprade nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
hagay3 committed Jul 13, 2024
1 parent 90d0612 commit 1a7531b
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 63 deletions.
20 changes: 10 additions & 10 deletions client/src/it/scala/skuber/DeploymentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor

it should "create a deployment" in { k8s =>

val createdDeployment = k8s.create(getNginxDeployment(deploymentName1, "1.7.9")).valueT
val createdDeployment = k8s.create(getNginxDeployment(deploymentName1, "1.27.0")).valueT
assert(createdDeployment.name == deploymentName1)

val getDeployment = k8s.get[Deployment](deploymentName1).valueT
Expand All @@ -72,7 +72,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor

it should "create a deployment in specific namespace" in { k8s =>
createNamespace(namespace1, k8s)
val createdDeployment = k8s.create(getNginxDeployment(deploymentSpecific1, "1.7.9"), Some(namespace1)).valueT
val createdDeployment = k8s.create(getNginxDeployment(deploymentSpecific1, "1.27.0"), Some(namespace1)).valueT
createdDeployment.name shouldBe deploymentSpecific1

val getDeployment = k8s.get[Deployment](deploymentSpecific1, Some(namespace1)).valueT
Expand All @@ -85,7 +85,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor

it should "update a deployment in specific namespace" in { k8s =>
createNamespace(namespace2, k8s)
val createdDeployment = k8s.create(getNginxDeployment(deploymentSpecific2, "1.7.9"), Some(namespace2)).valueT
val createdDeployment = k8s.create(getNginxDeployment(deploymentSpecific2, "1.27.0"), Some(namespace2)).valueT
createdDeployment.name shouldBe deploymentSpecific2

val expectedReplicas = 2
Expand All @@ -106,7 +106,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor


it should "upgrade the newly created deployment" in { k8s =>
k8s.create(getNginxDeployment(deploymentName2, "1.7.9")).valueT
k8s.create(getNginxDeployment(deploymentName2, "1.27.0")).valueT
Thread.sleep(5000)
val getDeployment = k8s.get[Deployment](deploymentName2).valueT
println(s"DEPLOYMENT TO UPDATE ==> $getDeployment")
Expand All @@ -127,7 +127,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor


it should "delete a deployment" in { k8s =>
val d = k8s.create(getNginxDeployment(deploymentName3, "1.7.9")).valueT
val d = k8s.create(getNginxDeployment(deploymentName3, "1.27.0")).valueT
assert(d.name == deploymentName3)

k8s.delete[Deployment](deploymentName3).valueT
Expand All @@ -146,7 +146,7 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor
it should "delete a deployment in specific namespace" in { k8s =>
createNamespace(namespace3, k8s)

val d = k8s.create(getNginxDeployment(deploymentSpecific3, "1.7.9"), Some(namespace3)).valueT
val d = k8s.create(getNginxDeployment(deploymentSpecific3, "1.27.0"), Some(namespace3)).valueT
assert(d.name == deploymentSpecific3)

k8s.delete[Deployment](deploymentSpecific3, namespace = Some(namespace3)).valueT
Expand All @@ -165,8 +165,8 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor
it should "deleteAll - delete all deployments in specific namespace" in { k8s =>
createNamespace(namespace4, k8s)

k8s.create(getNginxDeployment(deploymentSpecific41, "1.7.9"), Some(namespace4)).valueT
k8s.create(getNginxDeployment(deploymentSpecific42, "1.7.9"), Some(namespace4)).valueT
k8s.create(getNginxDeployment(deploymentSpecific41, "1.27.0"), Some(namespace4)).valueT
k8s.create(getNginxDeployment(deploymentSpecific42, "1.27.0"), Some(namespace4)).valueT


k8s.deleteAll[DeploymentList](namespace = Some(namespace4)).valueT
Expand All @@ -193,8 +193,8 @@ class DeploymentSpec extends K8SFixture with Eventually with Matchers with Befor
it should "list deployment in specific namespace" in { k8s =>
createNamespace(namespace5, k8s)

k8s.create(getNginxDeployment(deploymentSpecific51, "1.7.9"), Some(namespace5)).valueT
k8s.create(getNginxDeployment(deploymentSpecific52, "1.7.9"), Some(namespace5)).valueT
k8s.create(getNginxDeployment(deploymentSpecific51, "1.27.0"), Some(namespace5)).valueT
k8s.create(getNginxDeployment(deploymentSpecific52, "1.27.0"), Some(namespace5)).valueT

val expectedDeploymentList = List(deploymentSpecific51, deploymentSpecific52)
val actualDeploymentList =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DynamicKubernetesClientImplTest extends K8SFixture with Eventually with Ma
"containers": [
{
"name": "nginx",
"image": "nginx:1.7.9",
"image": "nginx:1.27.0",
"ports": [
{
"containerPort": 80,
Expand Down Expand Up @@ -127,7 +127,7 @@ class DynamicKubernetesClientImplTest extends K8SFixture with Eventually with Ma
"containers": [
{
"name": "nginx",
"image": "nginx:1.7.9",
"image": "nginx:1.27.0",
"ports": [
{
"containerPort": 80,
Expand Down
12 changes: 6 additions & 6 deletions client/src/it/scala/skuber/ExecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf

it should "execute a command in the running pod" in { k8s =>
println("START: execute a command in the running pod")
k8s.create(getNginxPod(podName1, "1.7.9")).valueT
k8s.create(getNginxPod(podName1, "1.27.0")).valueT
Thread.sleep(5000)

eventually(timeout(30.seconds), interval(3.seconds)) {
Expand All @@ -60,7 +60,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf

it should "execute a command in the specified container of the running pod" in { k8s =>
println("START: execute a command in the specified container of the running pod")
k8s.create(getNginxPod(podName2, "1.7.9")).valueT
k8s.create(getNginxPod(podName2, "1.27.0")).valueT
Thread.sleep(5000)

eventually(timeout(30.seconds), interval(3.seconds)) {
Expand All @@ -79,7 +79,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf

it should "execute a command that outputs to stderr in the running pod" in { k8s =>
println("START: execute a command that outputs to stderr in the running pod")
k8s.create(getNginxPod(podName3, "1.7.9")).valueT
k8s.create(getNginxPod(podName3, "1.27.0")).valueT
Thread.sleep(5000)
var output = ""
val stdout: Sink[String, Future[Done]] = Sink.foreach(output += _)
Expand All @@ -96,7 +96,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf
it should "execute a command in an interactive shell of the running pod - specific namespace" in { k8s =>
println("START: execute a command in an interactive shell of the running pod")
createNamespace(namespace1, k8s)
k8s.create(getNginxPod(podName4, "1.7.9"), namespace = Some(namespace1)).valueT
k8s.create(getNginxPod(podName4, "1.27.0"), namespace = Some(namespace1)).valueT
Thread.sleep(5000)
val stdin = Source.single("whoami\n")
var output = ""
Expand All @@ -115,7 +115,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf

it should "throw an exception without stdin, stdout nor stderr in the running pod" in { k8s =>
println("START: throw an exception without stdin, stdout nor stderr in the running pod")
k8s.create(getNginxPod(podName5, "1.7.9")).valueT
k8s.create(getNginxPod(podName5, "1.27.0")).valueT
Thread.sleep(5000)
whenReady {
val res = k8s.exec(podName5, Seq("whoami")).withTimeout().failed
Expand All @@ -132,7 +132,7 @@ class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAf

it should "throw an exception against an unexisting pod" in { k8s =>
println("START: throw an exception against an unexisting pod")
k8s.create(getNginxPod(podName6, "1.7.9")).valueT
k8s.create(getNginxPod(podName6, "1.27.0")).valueT
Thread.sleep(5000)
whenReady(k8s.exec(podName6 + "x", Seq("whoami")).withTimeout().failed) { result =>
println("FINISH: throw an exception against an unexisting pod")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HorizontalPodAutoscalerV2Beta1Spec extends K8SFixture with Eventually with
it should "create a HorizontalPodAutoscaler" in { k8s =>

println(horizontalPodAutoscaler1)
k8s.create(getNginxDeployment(deployment1, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment1, "1.27.0")).valueT
val result = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler1).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand All @@ -71,7 +71,7 @@ class HorizontalPodAutoscalerV2Beta1Spec extends K8SFixture with Eventually with

it should "update a HorizontalPodAutoscaler" in { k8s =>

k8s.create(getNginxDeployment(deployment2, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment2, "1.27.0")).valueT
val created = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler2).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand Down Expand Up @@ -101,7 +101,7 @@ class HorizontalPodAutoscalerV2Beta1Spec extends K8SFixture with Eventually with

it should "delete a HorizontalPodAutoscaler" in { k8s =>

k8s.create(getNginxDeployment(deployment3, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment3, "1.27.0")).valueT
val created = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler3).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HorizontalPodAutoscalerV2Spec extends K8SFixture with Eventually with Matc
it should "create a HorizontalPodAutoscaler" taggedAs HorizontalPodAutoscalerV2Tag in { k8s =>

println(horizontalPodAutoscaler1)
k8s.create(getNginxDeployment(deployment1, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment1, "1.27.0")).valueT
val result = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler1).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand All @@ -82,7 +82,7 @@ class HorizontalPodAutoscalerV2Spec extends K8SFixture with Eventually with Matc

it should "update a HorizontalPodAutoscaler" taggedAs HorizontalPodAutoscalerV2Tag in { k8s =>

k8s.create(getNginxDeployment(deployment2, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment2, "1.27.0")).valueT
val created = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler2).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand Down Expand Up @@ -112,7 +112,7 @@ class HorizontalPodAutoscalerV2Spec extends K8SFixture with Eventually with Matc

it should "delete a HorizontalPodAutoscaler" taggedAs HorizontalPodAutoscalerV2Tag in { k8s =>

k8s.create(getNginxDeployment(deployment3, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment3, "1.27.0")).valueT
val created = k8s.create(HorizontalPodAutoscaler(horizontalPodAutoscaler3).withSpec(HorizontalPodAutoscaler.Spec("v1", "Deployment", "nginx")
.withMinReplicas(1)
.withMaxReplicas(2)
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/K8SFixture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait K8SFixture extends FixtureAnyFlatSpec {

def getNginxContainer(version: String): Container = Container(name = "nginx", image = "nginx:" + version).exposePort(80)

def getNginxDeployment(name: String, version: String = "1.7.9", labels: Map[String, String] = Map.empty): Deployment = {
def getNginxDeployment(name: String, version: String = "1.27.0", labels: Map[String, String] = Map.empty): Deployment = {
import LabelSelector.dsl._
val nginxContainer = getNginxContainer(version)
val nginxTemplate = Pod.Template.Spec.named("nginx").addContainer(nginxContainer).addLabel("app" -> "nginx")
Expand Down
10 changes: 5 additions & 5 deletions client/src/it/scala/skuber/PatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA
behavior of "Patch"

it should "patch a pod with strategic merge patch by default" in { k8s =>
k8s.create(getNginxPod(pod1, "1.7.9")).withTimeout().futureValue
k8s.create(getNginxPod(pod1, "1.27.0")).withTimeout().futureValue
Thread.sleep(5000)
val randomString = randomUUID().toString
val patchData = MetadataPatch(labels = Some(Map("foo" -> randomString)), annotations = None)
Expand All @@ -55,7 +55,7 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA
}

it should "patch a pod with strategic merge patch" in { k8s =>
k8s.create(getNginxPod(pod2, "1.7.9")).valueT
k8s.create(getNginxPod(pod2, "1.27.0")).valueT
Thread.sleep(5000)
val randomString = randomUUID().toString
val patchData = MetadataPatch(labels = Some(Map("foo" -> randomString)), annotations = None, strategy = StrategicMergePatchStrategy)
Expand All @@ -70,7 +70,7 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA
}

it should "patch a pod with json merge patch" in { k8s =>
k8s.create(getNginxPod(pod3, "1.7.9")).valueT
k8s.create(getNginxPod(pod3, "1.27.0")).valueT
Thread.sleep(5000)
val randomString = randomUUID().toString
val patchData = MetadataPatch(labels = Some(Map("foo" -> randomString)), annotations = None, strategy = JsonMergePatchStrategy)
Expand All @@ -85,7 +85,7 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA


it should "patch a pod with json patch" in { k8s =>
k8s.create(getNginxPod(pod4, "1.7.9")).valueT
k8s.create(getNginxPod(pod4, "1.27.0")).valueT
Thread.sleep(5000)
val randomString = randomUUID().toString

Expand All @@ -105,7 +105,7 @@ class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndA

it should "patch a pod with json patch - specific namespace" in { k8s =>
createNamespace(namespace5, k8s)
k8s.create(getNginxPod(pod5, "1.7.9"), Some(namespace5)).valueT
k8s.create(getNginxPod(pod5, "1.27.0"), Some(namespace5)).valueT
Thread.sleep(5000)
val randomString = randomUUID().toString

Expand Down
6 changes: 3 additions & 3 deletions client/src/it/scala/skuber/PodDisruptionBudgetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PodDisruptionBudgetSpec extends K8SFixture with Matchers with BeforeAndAft

it should "create a PodDisruptionBudget" in { k8s =>
println("START: create a PodDisruptionBudget")
k8s.create(getNginxDeployment(deployment1, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment1, "1.27.0")).valueT
import LabelSelector.dsl._
val labelSelector = LabelSelector(IsEqualRequirement("app", "nginx"))
val result = k8s.create(PodDisruptionBudget(budget1).withMinAvailable(Left(1)).withLabelSelector(labelSelector)).valueT
Expand All @@ -70,7 +70,7 @@ class PodDisruptionBudgetSpec extends K8SFixture with Matchers with BeforeAndAft

it should "update a PodDisruptionBudget" in { k8s =>
println("START: update a PodDisruptionBudget")
val deployment = k8s.create(getNginxDeployment(deployment2, "1.7.9")).withTimeout()
val deployment = k8s.create(getNginxDeployment(deployment2, "1.27.0")).withTimeout()
deployment.futureValue
import LabelSelector.dsl._
val labelSelector = LabelSelector(IsEqualRequirement("app", "nginx"))
Expand All @@ -95,7 +95,7 @@ class PodDisruptionBudgetSpec extends K8SFixture with Matchers with BeforeAndAft

it should "delete a PodDisruptionBudget" in { k8s =>
println("START: delete a PodDisruptionBudget")
k8s.create(getNginxDeployment(deployment3, "1.7.9")).valueT
k8s.create(getNginxDeployment(deployment3, "1.27.0")).valueT
import LabelSelector.dsl._
val labelSelector = LabelSelector(IsEqualRequirement("app", "nginx"))
val pdb = k8s.create(PodDisruptionBudget(budget3).withMinAvailable(Left(1)).withLabelSelector(labelSelector)).valueT
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/PodLogSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PodLogSpec extends K8SFixture with Eventually with Matchers with BeforeAnd
}

it should "get log of a pod" in { k8s =>
k8s.create(getNginxPod(podName, "1.7.9")).valueT
k8s.create(getNginxPod(podName, "1.27.0")).valueT
Thread.sleep(3000)
eventually(timeout(30.seconds), interval(3.seconds)) {
val source = k8s.getPodLogSource(podName, LogQueryParams(follow = Some(false))).futureValue
Expand Down
12 changes: 6 additions & 6 deletions client/src/it/scala/skuber/PodSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAft

it should "create a pod" in { k8s =>
val podName1: String = randomUUID().toString
val p = k8s.create(getNginxPod(podName1, "1.7.9")).valueT
val p = k8s.create(getNginxPod(podName1, "1.27.0")).valueT
p.name shouldBe podName1
}

it should "get the newly created pod" in { k8s =>
val podName2: String = randomUUID().toString
k8s.create(getNginxPod(podName2, "1.7.9")).valueT
k8s.create(getNginxPod(podName2, "1.27.0")).valueT
eventually(timeout(30.seconds), interval(3.seconds)) {
val p = k8s.get[Pod](podName2).valueT
p.name shouldBe podName2
Expand All @@ -45,7 +45,7 @@ class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAft

it should "check for newly created pod and container to be ready" in { k8s =>
val podName3: String = randomUUID().toString
k8s.create(getNginxPod(podName3, "1.7.9")).valueT
k8s.create(getNginxPod(podName3, "1.27.0")).valueT
eventually(timeout(20.seconds), interval(3.seconds)) {
val podRetrieved = k8s.get[Pod](podName3).valueT
val podStatus = podRetrieved.status.get
Expand Down Expand Up @@ -73,7 +73,7 @@ class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAft

it should "delete a pod" in { k8s =>
val podName4: String = randomUUID().toString
k8s.create(getNginxPod(podName4, "1.7.9")).valueT
k8s.create(getNginxPod(podName4, "1.27.0")).valueT
k8s.delete[Pod](podName4).valueT

whenReady(k8s.get[Namespace](podName4).withTimeout().failed) { result =>
Expand All @@ -88,8 +88,8 @@ class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAft
it should "delete selected pods" in { k8s =>
val podName5: String = randomUUID().toString + "-foo"
val podName6: String = randomUUID().toString + "-bar"
k8s.create(getNginxPod(podName5, "1.7.9", labels = Map("foo" -> "1"))).valueT
k8s.create(getNginxPod(podName6, "1.7.9", labels = Map("bar" -> "2"))).valueT
k8s.create(getNginxPod(podName5, "1.27.0", labels = Map("foo" -> "1"))).valueT
k8s.create(getNginxPod(podName6, "1.27.0", labels = Map("bar" -> "2"))).valueT
Thread.sleep(5000)
k8s.deleteAllSelected[PodList](LabelSelector(LabelSelector.ExistsRequirement("foo"))).valueT

Expand Down
10 changes: 5 additions & 5 deletions client/src/it/scala/skuber/WatchContinuouslySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// it should "continuously watch changes on a resource - deployments" in { k8s =>
// import skuber.api.client.EventType
//
// val deploymentOne = getNginxDeployment(deployment1, "1.7.9")
// val deploymentTwo = getNginxDeployment(deployment2, "1.7.9")
// val deploymentOne = getNginxDeployment(deployment1, "1.27.0")
// val deploymentTwo = getNginxDeployment(deployment2, "1.27.0")
//
// val stream = k8s.list[DeploymentList].withTimeout().map { l =>
// k8s.watchAllContinuously[Deployment](Some(l.resourceVersion))
Expand Down Expand Up @@ -106,7 +106,7 @@
// it should "continuously watch changes on a named resource obj from the beginning - deployment" in { k8s =>
// import skuber.api.client.EventType
//
// val deployment = getNginxDeployment(deployment3, "1.7.9")
// val deployment = getNginxDeployment(deployment3, "1.27.0")
//
// k8s.create(deployment).valueT.name shouldBe deployment3
// eventually {
Expand Down Expand Up @@ -155,7 +155,7 @@
// it should "continuously watch changes on a named resource from the beginning - deployment" in { k8s =>
// import skuber.api.client.EventType
//
// val deployment = getNginxDeployment(deployment4, "1.7.9")
// val deployment = getNginxDeployment(deployment4, "1.27.0")
//
// k8s.create(deployment).valueT.name shouldBe deployment4
// eventually {
Expand Down Expand Up @@ -200,7 +200,7 @@
//
// createNamespace(namespace5, k8s)
//
// val deployment = getNginxDeployment(deployment5, "1.7.9")
// val deployment = getNginxDeployment(deployment5, "1.27.0")
//
// k8s.create(deployment, Some(namespace5)).valueT.name shouldBe deployment5
// eventually {
Expand Down
Loading

0 comments on commit 1a7531b

Please sign in to comment.