diff --git a/models/samples/helloworld/base/base.k b/models/samples/helloworld/base/base.k index db118b9..46de3be 100644 --- a/models/samples/helloworld/base/base.k +++ b/models/samples/helloworld/base/base.k @@ -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 * * * *" } -} +} \ No newline at end of file diff --git a/models/samples/helloworld/dev/main.k b/models/samples/helloworld/dev/main.k index 625dd4d..d1903a4 100644 --- a/models/samples/helloworld/dev/main.k +++ b/models/samples/helloworld/dev/main.k @@ -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" } diff --git a/models/schema/v1/app_configuration.k b/models/schema/v1/app_configuration.k index 2b18357..c7e6a69 100644 --- a/models/schema/v1/app_configuration.k +++ b/models/schema/v1/app_configuration.k @@ -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. @@ -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" } } } @@ -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} \ No newline at end of file diff --git a/models/schema/v1/component/component.k b/models/schema/v1/component/component.k deleted file mode 100644 index 14a7c59..0000000 --- a/models/schema/v1/component/component.k +++ /dev/null @@ -1,52 +0,0 @@ -import models.schema.v1.component.workload as wl - -schema Component: - """ Component defines the delivery artifact of one application. Each component - can be composed of a Workload and its supporting Accessories. - - Attributes - ---------- - job: wl.Job, default is Undefined, optional. - job describes how the Application's tasks are expected to be run. - A job will contiune to run until it succeeds. - longRunningService: ws.LongRunningService, default is Undefined, optional. - longRunningService defines long-running, scalable workload types that should "never" go down, - and handle short-lived latency-sensitive requests. - labels: {str:str}, default is Undefined, optional. - Labels are key/value pairs that are attached to the component. - annotations: {str:str}, default is Undefined, optional. - Annotations are key/value pairs that attach arbitrary non-identifying metadata to the component. - - Examples - -------- - Instantiate a long-running service Component with "nginx:v1" image and customized labels. - - component = cmp.Component { - longRunningService: wl.LongRunningService{ - containers: { - "nginx": c.Container { - image: "nginx:v1" - } - } - } - labels: { - "key": "value" - } - } - """ - - # Job describes how the Application's tasks are expected to be run. - # A job will contiune to run until it succeeds. - job?: wl.Job - # longRunningService defines long-running, scalable workload types that should "never" go down, - # and handle short-lived latency-sensitive requests. - longRunningService?: wl.LongRunningService - - ###### 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} - - check: - not longRunningService if job, "longRunningService and job cannot exist simultaneously." - not job if longRunningService, "longRunningService and job cannot exist simultaneously." diff --git a/models/schema/v1/component/workload/job.k b/models/schema/v1/component/workload/job.k deleted file mode 100644 index 36e27da..0000000 --- a/models/schema/v1/component/workload/job.k +++ /dev/null @@ -1,34 +0,0 @@ -import models.schema.v1.component.container as c - -schema Job: - """ Job describes how the Application's tasks are expected to be run. A job will contiune to run until it succeeds. - - 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 - schedule: str, default is Undefined, optional. - The scheduling strategy in Cron format, see https://en.wikipedia.org/wiki/Cron. - - Examples - -------- - import models.schema.v1.component.workload as wl - import models.schema.v1.component.container as c - - job: wl.Job { - containers: { - "busybox": c.Container{ - image: "busybox:1.28" - command: ["/bin/sh", "-c", "echo hello"] - } - schedule: "0 0 13 * 5" - } - } - """ - - # The template of container to be ran. - containers: {str:c.Container} - - # The scheduling strategy in Cron format. - schedule?: str diff --git a/models/schema/v1/component/workload/long_running_service.k b/models/schema/v1/component/workload/long_running_service.k deleted file mode 100644 index 40840a8..0000000 --- a/models/schema/v1/component/workload/long_running_service.k +++ /dev/null @@ -1,41 +0,0 @@ -import models.schema.v1.component.container as c - -schema LongRunningService: - """ LongRunningService defines long-running, scalable workload types that should "never" - go down, and handle short-lived latency-sensitive requests. Such services are commonly - used for web applications and services that expose APIs. - - 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 Undefined, optional. - Replicas is the number of desired replicas. - - Examples - -------- - import models.schema.v1.component.workload as wl - import models.schema.v1.component.container as c - - webservice: wl.LongRunningService { - containers: { - "web": c.Container { - image: "nginx:latest" - command: ["/bin/sh", "-c", "echo hi"] - env: { - "name": "value" - } - } - } - replicas: 2 - } - """ - - # 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. - # Not supported when type is Job. - replicas: int = 2 diff --git a/models/schema/v1/workload/common.k b/models/schema/v1/workload/common.k new file mode 100644 index 0000000..dff74ff --- /dev/null +++ b/models/schema/v1/workload/common.k @@ -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} diff --git a/models/schema/v1/component/container/container.k b/models/schema/v1/workload/container/container.k similarity index 100% rename from models/schema/v1/component/container/container.k rename to models/schema/v1/workload/container/container.k diff --git a/models/schema/v1/workload/job.k b/models/schema/v1/workload/job.k new file mode 100644 index 0000000..5730d17 --- /dev/null +++ b/models/schema/v1/workload/job.k @@ -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 diff --git a/models/schema/v1/workload/service.k b/models/schema/v1/workload/service.k new file mode 100644 index 0000000..7ad8d62 --- /dev/null +++ b/models/schema/v1/workload/service.k @@ -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 \ No newline at end of file