Skip to content

Commit

Permalink
Merge branch 'master' into update/bcpkix-jdk15on-1.70
Browse files Browse the repository at this point in the history
  • Loading branch information
hagay3 authored Apr 26, 2022
2 parents 3b50cb9 + 5bbeeb4 commit 937bcfb
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 30 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.14]
scala: [2.12.13, 2.13.6]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.14]
scala: [2.12.15]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -96,12 +96,22 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.14)
- name: Download target directories (2.12.13)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.12.14-${{ matrix.java }}
name: target-${{ matrix.os }}-2.12.13-${{ matrix.java }}

- name: Inflate target directories (2.12.14)
- name: Inflate target directories (2.12.13)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.6)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.6-${{ matrix.java }}

- name: Inflate target directories (2.13.6)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Provides you with a configured client on startup. It is handy to use this for qu
> Just handy shortcut to import skuber inside ammonite-repl:
```scala
import $ivy.`io.github.hagay3::skuber:2.7.3`, skuber._, skuber.json.format._
import $ivy.`io.github.hagay3::skuber:2.7.4`, skuber._, skuber.json.format._
```

### Interactive with sbt
Expand Down Expand Up @@ -120,7 +120,7 @@ To get minikube follow the instructions [here](https://github.com/kubernetes/min
You can use the latest release (for 2.12 or 2.13) by adding to your build:
```sbt
libraryDependencies += "io.github.hagay3" %% "skuber" % "2.7.3"
libraryDependencies += "io.github.hagay3" %% "skuber" % "2.7.4"
```
Meanwhile users of skuber v1 can continue to use the final v1.x release, which is available only on Scala 2.11:
Expand All @@ -139,6 +139,13 @@ If you have an application using the legacy version v1 of Skuber and want to mov
Building the library from source is very straightforward. Simply run `sbt test`in the root directory of the project to build the library (and examples) and run the unit tests to verify the build.
## CI + Build
The CI parameters defined in `build.sbt`.
ci.yaml and clean.yaml are generated automatically with [sbt-github-actions](https://github.com/djspiewak/sbt-github-actions) plugin.
Run `sbt githubWorkflowGenerate` in order to regenerate ci.yaml and clean.yaml.
## License
This code is licensed under the Apache V2.0 license, a copy of which is included [here](LICENSE.txt).
Expand Down
11 changes: 6 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ val scala13Version = "2.13.6"
val currentScalaVersion = scala13Version
val supportedScalaVersion = Seq(scala12Version, scala13Version)

val akkaVersion = "2.6.16"
val akkaVersion = "2.6.19"


val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.15.4"
Expand All @@ -19,21 +19,21 @@ val mockito = "org.mockito" % "mockito-core" % "3.12.4"
val akkaStreamTestKit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion


val snakeYaml = "org.yaml" % "snakeyaml" % "1.29"
val snakeYaml = "org.yaml" % "snakeyaml" % "1.30"

val commonsIO = "commons-io" % "commons-io" % "2.11.0"
val commonsCodec = "commons-codec" % "commons-codec" % "1.15"
val bouncyCastle = "org.bouncycastle" % "bcpkix-jdk15on" % "1.70"


// the client API request/response handing uses Akka Http
val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.2.6"
val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.2.9"
val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion
val akka = "com.typesafe.akka" %% "akka-actor" % akkaVersion

// Skuber uses akka logging, so the examples config uses the akka slf4j logger with logback backend
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion
val logback = "ch.qos.logback" % "logback-classic" % "1.2.6" % Runtime
val logback = "ch.qos.logback" % "logback-classic" % "1.2.11" % Runtime

// the Json formatters are based on Play Json
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2"
Expand Down Expand Up @@ -79,9 +79,10 @@ lazy val commonSettings = Seq(
)
// run sbt githubWorkflowGenerate in order to generate github actions files
inThisBuild(List(
githubWorkflowScalaVersions := supportedScalaVersion,
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "It/compile"))),
githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "It/compile"))),
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
Expand Down
16 changes: 14 additions & 2 deletions client/src/main/scala/skuber/Scale.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ case class Scale(
val newStatus = this.status.map(_.copy(replicas = count)).getOrElse(Scale.Status(replicas=count))
this.copy(status=Some(newStatus))
}

val statusSelectorLabels: Map[String, String] =
status.flatMap(_.selector.map { labels =>
val labelsArr = labels.split(",")
labelsArr.map { singleLabel =>
singleLabel.split("=") match {
case Array(key, value) => key -> value
case _=> singleLabel -> singleLabel
}
}.toMap
}).getOrElse(Map.empty)

}

object Scale {
Expand All @@ -33,14 +45,14 @@ object Scale {

case class Status(
replicas: Int = 0,
selector: Option[LabelSelector] = None,
selector: Option[String] = None,
targetSelector: Option[String] = None
)

object Status {
implicit val scaleStatusFormat: Format[Scale.Status] = (
(JsPath \ "replicas").formatMaybeEmptyInt() and
(JsPath \ "selector").formatNullableLabelSelector and
(JsPath \ "selector").formatNullable[String] and
(JsPath \ "targetSelector").formatNullable[String]
)(Scale.Status.apply _, unlift(Scale.Status.unapply))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ class KubernetesClientImpl private[client] (
val marshalledOptions = Marshal(options)
for {
requestEntity <- marshalledOptions.to[RequestEntity]
request = buildRequest(HttpMethods.DELETE, rd, Some(name))
.withEntity(requestEntity.withContentType(MediaTypes.`application/json`))
response <- invoke(request)
_ <- checkResponseStatus(response)
_ <- ignoreResponseBody(response)
request = buildRequest(HttpMethods.DELETE, rd, Some(name))
.withEntity(requestEntity.withContentType(MediaTypes.`application/json`))
response <- invoke(request)
responseStatusOpt <- checkResponseStatus(response)
_ <- ignoreResponseBody(response, responseStatusOpt)
} yield ()
}

Expand Down Expand Up @@ -696,9 +696,15 @@ class KubernetesClientImpl private[client] (
* @param response the Http Response that we need to drain
* @return A Future[Unit] that will be set to Success or Failure depending on outcome of draining
*/
private def ignoreResponseBody(response: HttpResponse): Future[Unit] = {
response.discardEntityBytes().future.map(done => ())
private def ignoreResponseBody(response: HttpResponse, responseStatusOpt: Option[Status]): Future[Unit] = {
responseStatusOpt match {
case Some(status) =>
throw new K8SException(status)
case _ =>
response.discardEntityBytes().future.map(done => ())
}
}

}

object KubernetesClientImpl {
Expand Down
72 changes: 66 additions & 6 deletions client/src/test/scala/skuber/ext/ScaleSpec.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package skuber.apps
package skuber.ext

import org.specs2.mutable.Specification
import skuber.{Container, LabelSelector, ObjectMeta, Pod, ReplicationController, Scale}
import play.api.libs.json.Json
import skuber.{ObjectMeta, Scale}

/**
* @author David O'Riordan
Expand All @@ -22,7 +22,8 @@ class ScaleSpec extends Specification {
val scale= Scale(
apiVersion="autoscaling/v1",
metadata=ObjectMeta(name="example", namespace="na"),
spec=Scale.Spec(replicas=Some(10))
spec=Scale.Spec(replicas=Some(10)),
status = Some(Scale.Status(replicas = 10, selector = Some("env=prod,app=app1")))
)

val readScale = Json.fromJson[Scale](Json.toJson(scale)).get
Expand All @@ -45,15 +46,17 @@ class ScaleSpec extends Specification {
},
"status": {
"replicas": 1,
"targetSelector": "redis-master"
"targetSelector": "redis-master",
"selector": "app=service1,environment=dev"
}
}
"""
val scale = Json.parse(scaleJsonStr).as[Scale]
scale.kind mustEqual "Scale"
scale.name mustEqual "redis-master"
scale.spec.replicas mustEqual Some(1)
scale.status mustEqual Some(Scale.Status(replicas=1, selector=None, targetSelector=Some("redis-master")))
scale.spec.replicas must beSome(1)
scale.status must beSome(Scale.Status(replicas=1, selector=Some("app=service1,environment=dev"), targetSelector=Some("redis-master")))
scale.statusSelectorLabels mustEqual Map("app" -> "service1", "environment" -> "dev")
}

"A scale object can contain NO replicas" >> {
Expand Down Expand Up @@ -81,4 +84,61 @@ class ScaleSpec extends Specification {
scale.name mustEqual "redis-master"
scale.spec.replicas mustEqual None
}

"A scale json with single key->value in status selector" >> {
val scaleJsonStr = """
{
"kind": "Scale",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "redis-master",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/replicationcontrollers/redis-master/scale",
"creationTimestamp": "2015-12-29T11:55:14Z"
},
"spec": {
"replicas": 1
},
"status": {
"replicas": 1,
"targetSelector": "redis-master",
"selector": "app=service1"
}
}
"""
val scale = Json.parse(scaleJsonStr).as[Scale]
scale.kind mustEqual "Scale"
scale.name mustEqual "redis-master"
scale.spec.replicas must beSome(1)
scale.status must beSome(Scale.Status(replicas=1, selector=Some("app=service1"), targetSelector=Some("redis-master")))
scale.statusSelectorLabels mustEqual Map("app" -> "service1")
}

"A scale json with wrong spec status string should not produce errors" >> {
val scaleJsonStr = """
{
"kind": "Scale",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "redis-master",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/replicationcontrollers/redis-master/scale",
"creationTimestamp": "2015-12-29T11:55:14Z"
},
"spec": {
"replicas": 1
},
"status": {
"replicas": 1,
"targetSelector": "redis-master",
"selector": "app==se,,rvice1,==environment=dev,,"
}
}
"""
val scale = Json.parse(scaleJsonStr).as[Scale]
scale.kind mustEqual "Scale"
scale.name mustEqual "redis-master"
scale.spec.replicas must beSome(1)
scale.status must beSome(Scale.Status(replicas=1, selector=Some("app==se,,rvice1,==environment=dev,,"), targetSelector=Some("redis-master")))
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.5
sbt.version=1.6.2
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "2.7.3"
ThisBuild / version := "2.7.4"

0 comments on commit 937bcfb

Please sign in to comment.