Skip to content

Commit 0ad33ef

Browse files
authored
Merge pull request #126 from vaslabs/feature/helmSupport
Helm plugin
2 parents 3436fbb + 7be0324 commit 0ad33ef

File tree

13 files changed

+206
-12
lines changed

13 files changed

+206
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ kubeyml:gen
4848
| envs | Map of environment variables, raw, field path or secret are supported| empty |
4949
| resourceRequests | Resource requests (cpu in the form of m, memory in the form of MiB | `Resource(Cpu(100), Memory(256))` |
5050
| resourceLimits | Resource limits (cpu in the form of m, memory in the form of MiB | `Resource(Cpu(1000), Memory(512))` |
51-
| target | The directory to output the deployment.yml | target of this project |
51+
| target | The directory to output the deployment.yml | <target of this project> / kubeyml |
5252
| deployment | The key to access the whole Deployment definition, exposed for further customisation | Instance with above defaults |
5353

5454
### Recipes

site/docs/akka-cluster/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: docs
33
title: "Akka Cluster"
4-
position: 4
4+
position: 5
55
---
66

77
# Akka cluster support

site/docs/helm/index.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: docs
3+
title: "Helm Support"
4+
position: 4
5+
---
6+
# Helm support
7+
8+
**This is an experimental feature**
9+
10+
It is possible since 0.3.9 to generate a helm compatible structure.
11+
12+
You have to simply enable HelmPlugin
13+
14+
```scala
15+
enablePlugins(KubeDeploymentPlugin, KubeServicePlugin, KubeIngressPlugin, HelmPlugin)
16+
```
17+
18+
This will generate under target/kubeyml a Chart.yml and a templates/ directory
19+
with all the kubernetes manifests already rendered.
20+
21+
The aim for this is that you can have the whole templating done with Scala
22+
in your sbt build configuration.
23+
24+
## Mixing the file
25+
26+
If you want to have a hybrid solution you can mix helm templates and
27+
this plugin.
28+
29+
In order to make the plugin store the files somewhere other than target/kubeyml
30+
you can override the setting.
31+
32+
33+
```scala
34+
(target in kube) := ".deployment/templates"
35+
```
36+
37+
Remember that if you override the target you need to point to a templates directory
38+

site/src/main/resources/microsite/data/menu.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ options:
2424
menu_section: ingress
2525
url: ingress/recipe/
2626

27+
- title: Helm
28+
url: helm/
29+
menu_section: helm
30+
2731
- title: Akka cluster
2832
url: akka-cluster/
2933
menu_section: akka_cluster

src/main/scala/kubeyml/deployment/plugin/Keys.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ trait Keys {
5959
object Keys extends Keys {
6060

6161
lazy val deploymentSettings: Seq[Def.Setting[_]] = Seq(
62+
(target in kube) := (target in ThisProject).value / "kubeyml",
6263
gen in kube :=
6364
Plugin.generate(
6465
(deployment in kube).value,
65-
(target in ThisProject).value
66+
(target in kube).value
6667
),
6768
namespace := (name in ThisProject).value,
6869
application := (name in ThisProject).value,
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2019 Vasilis Nicolaou
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package kubeyml.helm
23+
24+
import kubeyml.deployment.plugin.Keys.application
25+
import kubeyml.deployment.plugin.Keys.{gen, kube}
26+
import sbt.Def
27+
import sbt._
28+
import sbt.Keys._
29+
import kubeyml.protocol.NonEmptyString
30+
31+
object Keys {
32+
33+
lazy val helmSettings: Seq[Def.Setting[_]] = Seq(
34+
(target in kube) := (target in kube).value / "templates",
35+
gen in kube := {
36+
(gen in kube).value
37+
val chartTarget = (target in kube).value
38+
val chart = Chart(
39+
NonEmptyString((version in ThisBuild).value),
40+
NonEmptyString((application in kube).value)
41+
)
42+
Plugin.generate(chart, chartTarget.getParentFile)
43+
}
44+
)
45+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2019 Vasilis Nicolaou
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package kubeyml.helm
23+
24+
import java.io.File
25+
26+
import sbt.AutoPlugin
27+
import kubeyml.deployment.plugin.Keys.kube
28+
29+
import json_support._
30+
31+
object HelmPlugin extends AutoPlugin {
32+
override def trigger = noTrigger
33+
34+
override val projectSettings = sbt.inConfig(kube)(Keys.helmSettings)
35+
}
36+
37+
object Plugin {
38+
39+
def generate(chart: Chart, file: File) =
40+
kubeyml.plugin.writePlan(chart, file, "Chart")
41+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2019 Vasilis Nicolaou
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package kubeyml.helm
23+
24+
import kubeyml.protocol.NonEmptyString
25+
26+
case class Chart(
27+
version: NonEmptyString,
28+
name: NonEmptyString
29+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2019 Vasilis Nicolaou
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package kubeyml.helm
23+
24+
import io.circe.{Encoder, Json}
25+
import io.circe.syntax._
26+
import kubeyml.protocol.json_support._
27+
28+
object json_support {
29+
30+
implicit val chartEncoder: Encoder[Chart] = Encoder.instance(
31+
c =>
32+
Json.obj(
33+
"apiVersion" -> "v2".asJson,
34+
"name" -> c.name.asJson,
35+
"version" -> c.version.asJson
36+
)
37+
)
38+
}

src/main/scala/kubeyml/ingress/plugin/Keys.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Keys extends Keys {
4949
Plugin.generate(
5050
(ServiceKeys.service in kube).value,
5151
(Keys.ingress in kube).value,
52-
(target in ThisProject).value,
52+
(target in kube).value,
5353
(streams.value.log)
5454
)
5555
},

src/main/scala/kubeyml/plugin/package.scala

+4-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import io.circe.yaml.syntax._
3030
package object plugin {
3131

3232
private[kubeyml] def writePlan[A](a: A, buildTarget: File, kind: String)(implicit encoder: Encoder[A]) = {
33-
val genTarget = new File(buildTarget, "kubeyml")
34-
genTarget.mkdirs()
35-
val file = new File(genTarget, s"${kind}.yml")
33+
buildTarget.mkdirs()
34+
val file = new File(buildTarget, s"${kind}.yml")
3635
val printWriter = new PrintWriter(file)
3736
try {
3837
printWriter.println(a.asJson.asYaml.spaces4)
@@ -44,9 +43,8 @@ package object plugin {
4443
private[kubeyml] def writePlansInSingle[A, B](a: A, b: B, buildTarget: File, kind: String)(implicit
4544
encoderA: Encoder[A], encoder: Encoder[B]
4645
) = {
47-
val genTarget = new File(buildTarget, "kubeyml")
48-
genTarget.mkdirs()
49-
val file = new File(genTarget, s"${kind}.yml")
46+
buildTarget.mkdirs()
47+
val file = new File(buildTarget, s"${kind}.yml")
5048
val printWriter = new PrintWriter(file)
5149
try {
5250
printWriter.println(a.asJson.asYaml.spaces4)

src/main/scala/kubeyml/roles/akka/cluster/plugin/Keys.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object Keys extends Keys {
6969
Essential.subjects(namespace),
7070
RoleRef(role)
7171
),
72-
(target in ThisProject).value
72+
(target in kube).value
7373
)
7474
}
7575
)

src/main/scala/kubeyml/service/plugin/Keys.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object Keys extends Keys {
4343
(gen in kube).value
4444
Plugin.generate(
4545
(Keys.service in kube).value,
46-
(target in ThisProject).value
46+
(target in kube).value
4747
)
4848
},
4949
(service in kube) := Service.fromDeployment(

0 commit comments

Comments
 (0)