Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deprecate Component base model and rename LongRunningServic… #12

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 33 additions & 37 deletions models/samples/helloworld/base/base.k
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
import models.schema.v1 as ac
import models.schema.v1.component as cmp
import models.schema.v1.component.container as c
import models.schema.v1.component.workload as wl
import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c

# base.k declares reuseable configurations for all stacks.

appConfiguration: ac.AppConfiguration {
components: {
"proxy": cmp.Component {
longRunningService: wl.LongRunningService {
containers: {
"nginx": c.Container {
image: "nginx:v1"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hi"]
# Extra arguments append to command defined above
args: ["/bin/sh", "-c", "echo hi"]
env: {
# An environment variable of name "env1" and value "VALUE" will be set
"env1": "VALUE"
# An environment variable of name "env2" and value of the key "key" in the
# secret named "sec-name" will be set.
"env2": "secret://sec-name/key"
}
# Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp"
workingDir: "/tmp"
}
helloworld: ac.AppConfiguration {
workload: wl.Service {
containers: {
"nginx": c.Container {
image: "nginx:v1"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hi"]
# Extra arguments append to command defined above
args: ["/bin/sh", "-c", "echo hi"]
env: {
# An environment variable of name "env1" and value "VALUE" will be set
"env1": "VALUE"
# An environment variable of name "env2" and value of the key "key" in the
# secret named "sec-name" will be set.
"env2": "secret://sec-name/key"
}
replicas: 2
# Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp"
workingDir: "/tmp"
}
}
"echo-hello": {
job: wl.Job {
containers: {
"busybox": {
image: "busybox:1.28"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hello"]
}
}
# The scheduling strategy in Cron format.
schedule: "0 0 13 * 5"
replicas: 2
}
}

samplejob: ac.AppConfiguration {
workload: wl.Job {
containers: {
"busybox": c.Container {
image: "busybox:1.28"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hello"]
}
}
# Run every hour.
schedule: "0 * * * *"
}
}
}
4 changes: 2 additions & 2 deletions models/samples/helloworld/dev/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import models.schema.v1 as ac

# main.k declares customized configurations for dev stack.

appConfiguration: ac.AppConfiguration {
components.proxy.longRunningService.containers.nginx: {
helloworld: ac.AppConfiguration {
workload.containers.nginx: {
# dev stack has different image
image = "nginx:v2"
}
Expand Down
33 changes: 20 additions & 13 deletions models/schema/v1/app_configuration.k
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import models.schema.v1.component as cmp
import models.schema.v1.workload as wl

schema AppConfiguration:
""" AppConfiguration is a developer-centric definition that describes how to run an Application.
Expand All @@ -7,21 +7,23 @@ schema AppConfiguration:

Attributes
----------
components: {str:c.Component}, default is Undefined, required.
Component defines the delivery artifact of one application. Each application can be
composed by multiple components.
workload: wl.Service | wl.Job, default is Undefined, required.
Workload defines how to run your application code. Currently supported workload profile
includes Service and Job.

Examples
--------
Instantiate an App with a long-running service and its image is "nginx:v1"

import models.schema.v1 as ac
import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c

appConfiguration = ac.AppConfiguration {
components: {
"proxy": cmp.Component {
containers: {
"nginx": c.Container {
image: "nginx:v1"
}
workload: wl.Service {
containers: {
"nginx": c.Container {
image: "nginx:v1"
}
}
}
Expand All @@ -30,6 +32,11 @@ schema AppConfiguration:

__settings__: {str:str} = {"output_type" = "STANDALONE"}

# Component defines the delivery artifact of one application.
# Each application can be composed by multiple components.
components?: {str:cmp.Component}
# Workload defines how to run your application code.
workload: wl.Service | wl.Job

###### Other metadata info

# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
labels?: {str:str}
annotations?: {str:str}
52 changes: 0 additions & 52 deletions models/schema/v1/component/component.k

This file was deleted.

34 changes: 0 additions & 34 deletions models/schema/v1/component/workload/job.k

This file was deleted.

41 changes: 0 additions & 41 deletions models/schema/v1/component/workload/long_running_service.k

This file was deleted.

31 changes: 31 additions & 0 deletions models/schema/v1/workload/common.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import models.schema.v1.workload.container as c

schema WorkloadBase:
""" WorkloadBase defines set of attributes shared by different workload profile, e.g Service
and Job. You can inherit this Schema to reuse these common attributes.

Attributes
----------
containers: {str:c.Container}, default is Undefined, required.
Containers defines the templates of containers to be ran.
More info: https://kubernetes.io/docs/concepts/containers
replicas: int, default is 2, required.
Number of container replicas based on this configuration that should be ran.
labels: {str:str}, default is Undefined, optional.
Labels are key/value pairs that are attached to the workload.
annotations: {str:str}, default is Undefined, optional.
Annotations are key/value pairs that attach arbitrary non-identifying metadata to the workload.
"""

# The templates of containers to be ran.
containers: {str:c.Container}

# The number of containers that should be ran.
# Default is 2 to meet high availability requirements.
replicas: int = 2

###### Other metadata info

# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
labels?: {str:str}
annotations?: {str:str}
25 changes: 25 additions & 0 deletions models/schema/v1/workload/job.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
schema Job(WorkloadBase):
""" Job is a kind of workload profile that describes how to run your application code. This
is typically used for tasks that take from a few senconds to a few days to complete.

Examples
--------
Instantiate a job with busybox image and runs every hour

import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c

job: wl.Job {
containers: {
"busybox": c.Container{
image: "busybox:1.28"
command: ["/bin/sh", "-c", "echo hello"]
}
}
schedule: "0 * * * *"
}
"""

# The scheduling strategy in Cron format.
# More info: https://en.wikipedia.org/wiki/Cron.
schedule: str
25 changes: 25 additions & 0 deletions models/schema/v1/workload/service.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
schema Service(WorkloadBase):
""" Service is a kind of workload profile that describes how to run your application code. This
is typically used for long-running web applications that should "never" go down, and handle
short-lived latency-sensitive web requests, or events.

Attributes
----------

Examples
--------
Instantiate a long-running service and its image is "nginx:v1"

import models.schema.v1.workload as wl
import models.schema.v1.workload.container as c

svc = wl.Service {
containers: {
"nginx": c.Container {
image: "nginx:v1"
}
}
}
"""

# More service workload attributes here
Loading