-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Peefy/feat-default-settings-file
feat: support default settings file kcl.yaml loading
- Loading branch information
Showing
14 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
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,5 @@ | ||
run: | ||
cd app && kcl run && cd .. | ||
|
||
test: | ||
make run |
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,7 @@ | ||
kcl_cli_configs: | ||
file: | ||
- main.k | ||
- ../pkg/render/render.k | ||
kcl_options: | ||
- key: env | ||
value: prod |
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,19 @@ | ||
import pkg.app as app_pkg | ||
|
||
app: app_pkg.App { | ||
name: "app" | ||
domainType = "Standard" | ||
containerPort = 80 | ||
if option("env") == "prod": | ||
volumes = [ | ||
{ | ||
mountPath = "/tmp" | ||
} | ||
] | ||
services = [ | ||
{ | ||
clusterIP = "None" | ||
$type = "ClusterIP" | ||
} | ||
] | ||
} |
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,3 @@ | ||
[package] | ||
name = "konfig" | ||
|
Empty file.
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,23 @@ | ||
schema App: | ||
name: str | ||
domainType: "Standard" | "Customized" | "Global" | ||
containerPort: int | ||
volumes?: [Volume] | ||
services: [Service] | ||
|
||
check: | ||
1 <= containerPort <= 65535 | ||
|
||
schema Service: | ||
clusterIP: str | ||
$type: str | ||
|
||
check: | ||
clusterIP == "None" if $type == "ClusterIP" | ||
|
||
schema Volume: | ||
container: str = "*" # The default value of `container` is "*" | ||
mountPath: str | ||
|
||
check: | ||
mountPath not in ["/", "/boot", "/home", "dev", "/etc", "/root"] |
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,26 @@ | ||
import pkg.app as app_pkg | ||
import manifests | ||
|
||
app: app_pkg.App { | ||
domainType = "Standard" | ||
containerPort = 80 | ||
volumes = [ | ||
{ | ||
mountPath = "/tmp" | ||
} | ||
] | ||
services = [ | ||
{ | ||
clusterIP = "None" | ||
$type = "ClusterIP" | ||
} | ||
] | ||
} | ||
render = lambda app: app_pkg.App { | ||
{ | ||
apiVersion = "v1" | ||
metadata.name = app.name | ||
} | ||
} | ||
|
||
manifests.yaml_stream([render(a) for a in app_pkg.App.instances()]) |
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,5 @@ | ||
run: | ||
kcl server.k | ||
|
||
test: | ||
make run |
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,7 @@ | ||
[package] | ||
name = "server" | ||
edition = "0.0.1" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
k8s = "1.28" |
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,9 @@ | ||
[dependencies] | ||
[dependencies.k8s] | ||
name = "k8s" | ||
full_name = "k8s_1.28" | ||
version = "1.28" | ||
sum = "aTxPUVZyr9MdiB3YdiY/8pCh9sC55yURnZdGlJsKG6Q=" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/k8s" | ||
oci_tag = "1.28" |
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,108 @@ | ||
import k8s.api.core.v1 | ||
import regex | ||
|
||
protocol PVCProtocol: | ||
pvc?: {str:} | ||
|
||
mixin PersistenVolumeClaimMixin for PVCProtocol: | ||
""" | ||
PersistentVolumeClaim (PVC) sample: | ||
Link: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims | ||
""" | ||
|
||
# Mix in a new attribute `kubernetesPVC` | ||
kubernetesPVC: v1.PersistentVolumeClaim | ||
|
||
if pvc: | ||
kubernetesPVC = v1.PersistentVolumeClaim { | ||
metadata.name = pvc.name | ||
metadata.labels = pvc.labels | ||
spec = { | ||
accessModes = pvc.accessModes | ||
resources = pvc.resources | ||
storageClassName = pvc.storageClassName | ||
} | ||
} | ||
|
||
schema Server(Deployment): | ||
mixin [PersistenVolumeClaimMixin] | ||
pvc?: {str:} | ||
""" pvc user interface data defined by PersistentVolumeClaimMixin """ | ||
|
||
schema Deployment[priority: int]: | ||
name: str | ||
cpu: int = _cpu | ||
memory: int = _cpu * 2 | ||
volumes?: [Volume] | ||
image: str | ||
service?: Service | ||
replica: int = 1 | ||
command: [str] | ||
labels?: {str: str} | ||
|
||
if priority == 1: | ||
_cpu = 256 | ||
elif priority == 2: | ||
_cpu = 512 | ||
elif priority == 3: | ||
_cpu = 1024 | ||
else: | ||
_cpu = 2048 | ||
|
||
check: | ||
multiplyof(cpu, 256), "CPU must be a multiple of 256" | ||
regex.match(image, "^[a-zA-Z]+:\d+\.\d+\.\d+$"), "image name should be like 'nginx:1.14.2'" | ||
1 <= replica <= 100, "replica must be between 1 and 100" | ||
len(labels) >= 2, "The length of labels should be greater than or equal to 2" | ||
"env" in labels, "'env' must be in labels" | ||
len(command) > 0, "command-list should be non-empty" | ||
|
||
schema Port: | ||
name: str | ||
protocol: str | ||
port: int | ||
targetPort: int | ||
|
||
check: | ||
port in [80, 443], "port must be 80 or 443" | ||
protocol in ["TCP", "HTTP"], "protocol must be TCP or HTTP" | ||
1024 < targetPort, "targetPort must be greater than 1024" | ||
|
||
schema Service: | ||
name: "my-service" = "my-service" | ||
ports: [Port] | ||
|
||
check: | ||
len(ports) > 0, "ports-list should be non-empty" | ||
|
||
schema Volume: | ||
name: str | ||
mountPath: str | ||
hostPath: str | ||
|
||
server = Server { | ||
name = "my-nginx" | ||
image = "nginx:1.14.2" | ||
volumes = [Volume { | ||
name = "mydir" | ||
mountPath = "/test-pd" | ||
hostPath = "/data" | ||
}] | ||
command = ["nginx"] | ||
labels = { | ||
run = "my-nginx" | ||
env = "pre-prod" | ||
} | ||
service.ports = [Port { | ||
name = "http" | ||
protocol = "TCP" | ||
port = 80 | ||
targetPort = 9376 | ||
}] | ||
pvc = { | ||
name = "my_pvc" | ||
acccessModes = ["ReadWriteOnce"] | ||
resources.requests.storage = "8Gi" | ||
storageClassName = "slow" | ||
} | ||
} |
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
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
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