-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate the k8s deployment file generation to PKL
- Loading branch information
1 parent
1826e9a
commit cfc2917
Showing
7 changed files
with
462 additions
and
219 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/K8sResource.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/apps/v1/Deployment.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/Service.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/networking/v1/Ingress.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/PodSpec.pkl" | ||
import "./modules/ingress.pkl" as ingress | ||
|
||
hidden appNamespace = "development" | ||
hidden podPort = 3000 | ||
|
||
hidden IngressOptions = new { | ||
rules = new {} | ||
} | ||
hidden ServiceOptions = new { | ||
spec = new Service.ServiceSpec { | ||
type = "NodePort" | ||
selector { | ||
["app"] = "aletheia" | ||
} | ||
ports { | ||
new { | ||
name = "aletheia" | ||
targetPort = trace(podPort) | ||
port = 80 | ||
} | ||
} | ||
} | ||
} | ||
hidden DeploymentOptions = new { | ||
replicas = 1 | ||
containers = new Listing<PodSpec.Container> {} | ||
} | ||
|
||
|
||
resources: Listing<K8sResource> = new { | ||
new Ingress { | ||
metadata { | ||
name = "ingress-aletheia" | ||
namespace = appNamespace | ||
annotations { | ||
["kubernetes.io/ingress.class"] = "traefik" | ||
} | ||
} | ||
spec { | ||
rules = new { | ||
for (_rule in IngressOptions.rules) { | ||
_rule | ||
} | ||
} | ||
} | ||
} | ||
|
||
new Service { | ||
metadata { | ||
name = "aletheia" | ||
namespace = appNamespace | ||
} | ||
spec = ServiceOptions.spec | ||
} | ||
|
||
new Deployment { | ||
metadata { | ||
name = "aletheia" | ||
namespace = appNamespace | ||
} | ||
spec { | ||
replicas = DeploymentOptions.replicas | ||
selector { | ||
matchLabels { | ||
["app"] = "aletheia" | ||
} | ||
} | ||
template { | ||
metadata { | ||
labels { | ||
["app"] = "aletheia" | ||
} | ||
} | ||
spec { | ||
containers = DeploymentOptions.containers | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
output { | ||
value = resources | ||
renderer = (K8sResource.output.renderer as YamlRenderer) { | ||
isStream = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
amends "./app.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/K8sResource.pkl" | ||
import "./modules/ingress.pkl" as ingress | ||
import "./modules/aletheia.pkl" | ||
|
||
appNamespace = "development" | ||
podPort = 3000 | ||
|
||
local newAletheia = new (aletheia) { | ||
ns = appNamespace | ||
p = podPort | ||
} | ||
|
||
IngressOptions { | ||
rules { | ||
(ingress.rule) { | ||
host = "test.aletheiafact.org" | ||
} | ||
} | ||
} | ||
|
||
DeploymentOptions { | ||
containers { | ||
(newAletheia.pod.container) { | ||
name = "aletheia" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import "./container.pkl" as containerConfig | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/PodSpec.pkl" | ||
|
||
hidden ns = "" | ||
hidden p = 3000 | ||
|
||
pod = (containerConfig) { | ||
namespace = ns | ||
imagePath = "134187360702.dkr.ecr.us-east-1.amazonaws.com/aletheiafact-production" + ":" + read("env:TAG") | ||
podPort = p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/EnvVar.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/ResourceRequirements.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/PodSpec.pkl" | ||
|
||
hidden namespace = "" | ||
hidden imagePath = "" | ||
hidden podPort = "" | ||
|
||
container: PodSpec.Container = new { | ||
name = "" | ||
image = imagePath | ||
imagePullPolicy = "Always" | ||
env = new { | ||
new { | ||
name = "NEXT_PUBLIC_UMAMI_SITE_ID" | ||
value = read("env:UMAMI_SITE_ID") | ||
} | ||
new { | ||
name = "NEXT_PUBLIC_RECAPTCHA_SITEKEY" | ||
value = read("env:RECAPTCHA_SITEKEY") | ||
} | ||
new { | ||
name = "ORY_SDK_URL" | ||
value = read("env:ORY_SDK_URL") | ||
} | ||
new { | ||
name = "ORY_ACCESS_TOKEN" | ||
value = read("env:ORY_ACCESS_TOKEN") | ||
} | ||
new { | ||
name = "NEW_RELIC_LICENSE_KEY" | ||
value = read("env:NEW_RELIC_LICENSE_KEY") | ||
} | ||
new { | ||
name = "NEW_RELIC_APP_NAME" | ||
value = "aletheia-" + namespace | ||
} | ||
new { | ||
name = "NEXT_PUBLIC_ORY_SDK_URL" | ||
value = read("env:NEXT_PUBLIC_ORYSDKURL") | ||
} | ||
new { | ||
name = "OPENAI_API_KEY" | ||
value = read("env:OPENAI_API_KEY") | ||
} | ||
new { | ||
name = "ENV_NAME" | ||
value = namespace | ||
} | ||
} | ||
|
||
readinessProbe { | ||
httpGet { | ||
path = "/api/health" | ||
port = podPort | ||
} | ||
initialDelaySeconds = 50 | ||
timeoutSeconds = 5 | ||
} | ||
livenessProbe { | ||
httpGet { | ||
path = "/api/health" | ||
port = podPort | ||
} | ||
initialDelaySeconds = 50 | ||
timeoutSeconds = 10 | ||
failureThreshold = 10 | ||
} | ||
resources { | ||
requests { | ||
["cpu"] = "300m" | ||
["memory"] = 512.mib | ||
} | ||
limits { | ||
["cpu"] = "400m" | ||
["memory"] = 1024.mib | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/networking/v1/Ingress.pkl" as Ingress | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/apps/v1/Deployment.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/Service.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/K8sResource.pkl" | ||
|
||
rule: Ingress.IngressRule = new { | ||
host = "www.test.aletheiafact.org" | ||
http { | ||
paths { | ||
new { | ||
path = "/" | ||
pathType = "Prefix" | ||
backend { | ||
service { | ||
name = "aletheia" | ||
port { | ||
name = "aletheia" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
amends "./app.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/K8sResource.pkl" | ||
import "./modules/ingress.pkl" as ingress | ||
import "./modules/aletheia.pkl" | ||
|
||
appNamespace = "production" | ||
podPort = 3000 | ||
|
||
local newAletheia = new (aletheia) { | ||
ns = appNamespace | ||
p = podPort | ||
} | ||
|
||
IngressOptions { | ||
rules { | ||
(ingress.rule) { | ||
host = "aletheiafact.org" | ||
} | ||
|
||
(ingress.rule) { | ||
host = "www.aletheiafact.org" | ||
} | ||
} | ||
} | ||
|
||
DeploymentOptions { | ||
containers { | ||
(newAletheia.pod.container) { | ||
name = "aletheia" | ||
} | ||
} | ||
} |