-
Notifications
You must be signed in to change notification settings - Fork 13
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 #43 from zong-zhe/support-import-path
feat: support import in krm-function
- Loading branch information
Showing
6 changed files
with
168 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,46 @@ | ||
import schemas as s | ||
|
||
# Convert the `App` model into Kubernetes Deployment and Service Manifests | ||
kubernetesRender = lambda a: s.App { | ||
# Construct the deployment manifest. | ||
deployment = { | ||
apiVersion = "apps/v1" | ||
kind = "Deployment" | ||
metadata.name = a.name | ||
metadata.labels = a.labels | ||
spec = { | ||
replicas = a.replicas | ||
selector.matchLabels = a.labels | ||
template.metadata.labels = a.labels | ||
template.spec.containers = [ | ||
{ | ||
name = name | ||
image = c.image | ||
command = c.command | ||
args = c.args | ||
env = c.env | ||
volumeMounts = c.volumes | ||
resources: c.resources | ||
ports = c.ports | ||
} for name, c in a.containers | ||
] | ||
} | ||
} | ||
# Construct the service manifest. | ||
service = { | ||
apiVersion = "v1" | ||
kind = "Service" | ||
metadata.name = a.name | ||
metadata.labels = a.labels | ||
spec = { | ||
type = a.service?.$type | ||
selector = a.labels | ||
ports = a.service?.ports | ||
} | ||
} | ||
# Returns Kubernetes manifests | ||
[deployment, if a.service: service] | ||
} | ||
|
||
params: s.App = option("params") | ||
items = kubernetesRender(params) |
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,51 @@ | ||
schema App: | ||
"""The application model.""" | ||
name: str | ||
replicas: int = 1 | ||
labels?: {str:str} = {app = name} | ||
service?: Service | ||
containers?: {str: Container} | ||
|
||
schema Service: | ||
"""The service model.""" | ||
$type?: str | ||
ports: [Port] | ||
|
||
schema Port: | ||
"""The port model.""" | ||
port: int | ||
protocol: "TCP" | "UDP" | "SCTP" = "TCP" | ||
targetPort?: int | str | ||
|
||
schema Container: | ||
"""The container model.""" | ||
image: str | ||
command?: [str] | ||
args?: [str] | ||
env?: [Env] | ||
volumes?: [Volume] | ||
resources?: Resource | ||
ports: [ContainerPort] | ||
|
||
schema ContainerPort: | ||
"""The container port model.""" | ||
name?: str | ||
protocol: "TCP" | "UDP" | "SCTP" = "TCP" | ||
containerPort: int | ||
|
||
check: | ||
1 <= containerPort <= 65535, "containerPort must be between 1 and 65535, inclusive" | ||
|
||
schema Env: | ||
name: str | ||
value: str | ||
|
||
schema Volume: | ||
source: str | ||
path: str | ||
target: str | ||
readOnly?: bool = False | ||
|
||
schema Resource: | ||
limits?: {str:} | ||
requests?: {str:} |
20 changes: 20 additions & 0 deletions
20
examples/abstraction/web-service-with-import/suite/config.yaml
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,20 @@ | ||
apiVersion: config.kubernetes.io/v1 | ||
kind: ResourceList | ||
items: | ||
functionConfig: | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLRun | ||
spec: | ||
params: | ||
name: app | ||
containers: | ||
nginx: | ||
image: nginx | ||
ports: | ||
- containerPort: 80 | ||
service: | ||
ports: | ||
- port: 80 | ||
labels: | ||
name: app | ||
source: oci://ghcr.io/kcl-lang/web-service |
23 changes: 23 additions & 0 deletions
23
examples/abstraction/web-service-with-import/suite/good.yaml
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 @@ | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLRun | ||
metadata: | ||
name: web-service | ||
annotations: | ||
krm.kcl.dev/version: 0.0.1 | ||
krm.kcl.dev/type: abstraction | ||
documentation: >- | ||
Web service application abstraction | ||
spec: | ||
params: | ||
name: app | ||
containers: | ||
nginx: | ||
image: nginx | ||
ports: | ||
- containerPort: 80 | ||
service: | ||
ports: | ||
- port: 80 | ||
labels: | ||
name: app | ||
source: ./examples/abstraction/web-service-with-import/main.k |
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