Skip to content

Commit

Permalink
Adding args and commands variable to k8s service and its cron jobs (#915
Browse files Browse the repository at this point in the history
)

* Adding args and commands variable to k8s service and its cron jobs

#911

* terraform fmt

* schema fixes
  • Loading branch information
juandiegopalomino authored Jul 1, 2022
1 parent 54021f1 commit 94418a5
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 8 deletions.
10 changes: 10 additions & 0 deletions modules/aws_k8s_service/aws-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
},
"default": []
},
"commands": {
"type": "list",
"description": "The commands override to execute in your container (corresponds to EntryPoint in docker)",
"default": []
},
"args": {
"type": "list",
"description": "The args override to pass to your container (corresponds to Cmd in docker)",
"default": []
},
"ports": {
"type": "array",
"description": "Specifies which port(s) your app exposes.",
Expand Down
7 changes: 4 additions & 3 deletions modules/aws_k8s_service/aws-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ For example, here is a service which has a cron job that runs every minute and s
port:
http: 80
cron_jobs:
- commands:
- args: # Args is an optional field
- "-c"
- 'echo "Hello world!"'
commands:
- /bin/sh
- -c
- 'echo "Hello world!"'
schedule: "* * * * *"
```

Expand Down
11 changes: 11 additions & 0 deletions modules/aws_k8s_service/aws-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ inputs:
validator: int(required=False)
description: The max amount of helm revisions to keep track of (0 for infinite)
default: 25
- name: commands
user_facing: true
validator: list(required=False)
description: The commands override to execute in your container (corresponds to EntryPoint in docker)
default: []
- name: args
user_facing: true
validator: list(required=False)
description: The args override to pass to your container (corresponds to Cmd in docker)
default: []
extra_validators:
limits:
memory: any(int(min=1), str(), required=True)
Expand All @@ -243,6 +253,7 @@ extra_validators:
memory: any(int(min=1), str(), required=True)
cron_job:
commands: list(required=True)
args: list(required=False)
schedule: str(required=True)
toleration:
key: str(required=True)
Expand Down
2 changes: 2 additions & 0 deletions modules/aws_k8s_service/tf_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ resource "helm_release" "k8s-service" {
cron_jobs : var.cron_jobs
podAnnotations : var.pod_annotations
podLabels : var.pod_labels
commands : var.commands
args : var.args
})
]
atomic = true
Expand Down
8 changes: 8 additions & 0 deletions modules/aws_k8s_service/tf_module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,12 @@ variable "readiness_probe_command" {
}
variable "pod_labels" {
type = map(string)
}

variable "commands" {
type = list(string)
}

variable "args" {
type = list(string)
}
18 changes: 18 additions & 0 deletions modules/azure_k8s_service/azure-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
"description": "Set to AUTO to create a private repo for your own images. Otherwises attempts to pull image from public dockerhub",
"default": "AUTO"
},
"commands": {
"type": "list",
"description": "The commands override to execute in your container (corresponds to EntryPoint in docker)",
"default": []
},
"args": {
"type": "list",
"description": "The args override to pass to your container (corresponds to Cmd in docker)",
"default": []
},
"cron_jobs": {
"type": "array",
"description": "A list of cronjobs to execute as part of this service",
"items": {
"$ref": "/common-types/cron-job"
},
"default": []
},
"min_containers": {
"type": "integer",
"description": "The minimum number of replicas your app can autoscale to.",
Expand Down
62 changes: 62 additions & 0 deletions modules/azure_k8s_service/azure-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,65 @@ underlying resource kind is being switched.
_NOTE_ because of the nature of these disks, they will not be cleaned up automatically unless during a service
destruction. If you wish to release the StandardSSD disks for whatever reason you will need to manually do so by
deleting the kubernetes persistent volume claims.

### Tolerations

Opta gives you the option of adding [taints](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/)
to the nodes created in this nodepool, and thusly the ability to add _tolerations_ for said taints. The official
documentation gives an excellent detailed summary, but in short one can use taints to stop workloads from running in
said nodes unless they have a matching toleration. Simply provide a list of desired tolerations as inputs like so:
```yaml
- name: app
type: k8s-service
image: AUTO
healthcheck_path: "/get"
port:
http: 80
tolerations:
- key: instancetype
value: memoryoptimized
effect: "NoExecute"
- key: team
value: booking
# Tolerates for default effect of NoSchedule
- key: highpriority
# Tolerates for default value of opta
```

Please refer to the taints specified in your environment Opta manifests to know what matching tolerations are right
for you.

### Cron Jobs

Opta gives you the option of adding a list of cron jobs to run as part of this service. This is done via the `cron_jobs`
field which a user can fill with entries for each con job in mind. Each entry must specify a command in array format
(for most cases simply specify the shell you wish to use, the `-c` flag and the executable to run), as well as a
schedule following the [Cron Syntax](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax).
The cron jobs will use the same resource requests/limits as the servers.

For example, here is a service which has a cron job that runs every minute and simply outputs "Hello world!" to stdout:

```yaml
- name: app
type: k8s-service
image: AUTO
healthcheck_path: "/get"
port:
http: 80
cron_jobs:
- args: # Args is an optional field
- "-c"
- 'echo "Hello world!"'
commands:
- /bin/sh
schedule: "* * * * *"
```

{{% alert title="Pure Cron Jobs" color="info" %}}
If a user wishes to just have a cron job and no service, then they could simply set the min/max containers to
0.
{{% /alert %}}

{{% alert title="Warning" color="warning" %}}
Cron Jobs are currently created outside the default linkerd service mesh.
{{% /alert %}}
19 changes: 19 additions & 0 deletions modules/azure_k8s_service/azure-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,28 @@ inputs: # (what users see)
validator: int(required=False)
description: The max amount of helm revisions to keep track of (0 for infinite)
default: 25
- name: cron_jobs
user_facing: true
validator: list(include('cron_job'), required=False)
description: A list of cronjobs to execute as part of this service
default: []
- name: commands
user_facing: true
validator: list(required=False)
description: The commands override to execute in your container (corresponds to EntryPoint in docker)
default: []
- name: args
user_facing: true
validator: list(required=False)
description: The args override to pass to your container (corresponds to Cmd in docker)
default: []
extra_validators:
limits:
memory: any(int(min=1), str(), required=True)
cron_job:
commands: list(required=True)
args: list(required=False)
schedule: str(required=True)
resources:
cpu: any(int(min=1), str(), required=True)
memory: any(int(min=1), str(), required=True)
Expand Down
3 changes: 3 additions & 0 deletions modules/azure_k8s_service/tf_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ resource "helm_release" "k8s-service" {
ingressExtraAnnotations : var.ingress_extra_annotations
podAnnotations : var.pod_annotations
podLabels : var.pod_labels
cron_jobs : var.cron_jobs
commands : var.commands
args : var.args
})
]
atomic = true
Expand Down
12 changes: 12 additions & 0 deletions modules/azure_k8s_service/tf_module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,16 @@ variable "readiness_probe_command" {
}
variable "pod_labels" {
type = map(string)
}

variable "commands" {
type = list(string)
}

variable "args" {
type = list(string)
}

variable "cron_jobs" {
default = []
}
4 changes: 4 additions & 0 deletions modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def process(self, module_idx: int) -> None:
if isinstance(self.module.data.get("public_uri"), str):
self.module.data["public_uri"] = [self.module.data["public_uri"]]

cron_jobs = self.module.data.get("cron_jobs", [])
for cron_job in cron_jobs:
cron_job["args"] = cron_job.get("args", [])

if "public_uri" in self.module.data:
new_uris: List[str] = []
public_uri: str
Expand Down
10 changes: 10 additions & 0 deletions modules/gcp_k8s_service/gcp-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"description": "Set to AUTO to create a private repo for your own images. Otherwises attempts to pull image from public dockerhub",
"default": "AUTO"
},
"commands": {
"type": "list",
"description": "The commands override to execute in your container (corresponds to EntryPoint in docker)",
"default": []
},
"args": {
"type": "list",
"description": "The args override to pass to your container (corresponds to Cmd in docker)",
"default": []
},
"min_containers": {
"type": "integer",
"description": "The minimum number of replicas your app can autoscale to.",
Expand Down
9 changes: 5 additions & 4 deletions modules/gcp_k8s_service/gcp-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ For example, here is a service which has a cron job that runs every minute and s
port:
http: 80
cron_jobs:
- commands:
- args: # Args is an optional field
- "-c"
- 'echo "Hello world!"'
commands:
- /bin/sh
- -c
- 'echo "Hello world!"'
schedule: "* * * * *"
```

Expand All @@ -209,4 +210,4 @@ If a user wishes to just have a cron job and no service, then they could simply

{{% alert title="Warning" color="warning" %}}
Cron Jobs are currently created outside the default linkerd service mesh.
{{% /alert %}}
{{% /alert %}}
11 changes: 11 additions & 0 deletions modules/gcp_k8s_service/gcp-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ inputs:
validator: int(required=False)
description: The max amount of helm revisions to keep track of (0 for infinite)
default: 25
- name: commands
user_facing: true
validator: list(required=False)
description: The commands override to execute in your container (corresponds to EntryPoint in docker)
default: []
- name: args
user_facing: true
validator: list(required=False)
description: The args override to pass to your container (corresponds to Cmd in docker)
default: []
extra_validators:
limits:
memory: any(int(min=1), str(), required=True)
Expand All @@ -224,6 +234,7 @@ extra_validators:
memory: any(int(min=1), str(), required=True)
cron_job:
commands: list(required=True)
args: list(required=False)
schedule: str(required=True)
toleration:
key: str(required=True)
Expand Down
2 changes: 2 additions & 0 deletions modules/gcp_k8s_service/tf_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ resource "helm_release" "k8s-service" {
cron_jobs : var.cron_jobs
podAnnotations : var.pod_annotations
podLabels : var.pod_labels
commands : var.commands
args : var.args
})
]
atomic = true
Expand Down
8 changes: 8 additions & 0 deletions modules/gcp_k8s_service/tf_module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,12 @@ variable "readiness_probe_command" {
}
variable "pod_labels" {
type = map(string)
}

variable "commands" {
type = list(string)
}

variable "args" {
type = list(string)
}
10 changes: 10 additions & 0 deletions modules/local_k8s_service/local-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"$ref": "/common-types/port-deprecated",
"description": "Specifies what port your app was made to be listened to. Currently it must be a map of the form\n`http: [PORT_NUMBER_HERE]` or `tcp: [PORT_NUMBER_HERE]`. Use http if you just have a vanilla http server and tcp for\nwebsockets.\n"
},
"commands": {
"type": "list",
"description": "The commands override to execute in your container (corresponds to EntryPoint in docker)",
"default": []
},
"args": {
"type": "list",
"description": "The args override to pass to your container (corresponds to Cmd in docker)",
"default": []
},
"cron_jobs": {
"type": "array",
"description": "A list of cronjobs to execute as part of this service",
Expand Down
11 changes: 11 additions & 0 deletions modules/local_k8s_service/local-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ inputs:
validator: int(required=False)
description: The max amount of helm revisions to keep track of (0 for infinite)
default: 25
- name: commands
user_facing: true
validator: list(required=False)
description: The commands override to execute in your container (corresponds to EntryPoint in docker)
default: []
- name: args
user_facing: true
validator: list(required=False)
description: The args override to pass to your container (corresponds to Cmd in docker)
default: []
extra_validators:
limits:
memory: any(int(min=1), str(), required=True)
Expand All @@ -182,6 +192,7 @@ extra_validators:
memory: any(int(min=1), str(), required=True)
cron_job:
commands: list(required=True)
args: list(required=False)
schedule: str(required=True)
toleration:
key: str(required=True)
Expand Down
2 changes: 2 additions & 0 deletions modules/local_k8s_service/tf_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ resource "helm_release" "k8s-service" {
ingressExtraAnnotations : var.ingress_extra_annotations
tolerations : var.tolerations
cron_jobs : var.cron_jobs
commands : var.commands
args : var.args
})
]
atomic = true
Expand Down
8 changes: 8 additions & 0 deletions modules/local_k8s_service/tf_module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,11 @@ variable "cron_jobs" {
variable "max_history" {
type = number
}

variable "commands" {
type = list(string)
}

variable "args" {
type = list(string)
}
2 changes: 1 addition & 1 deletion modules/opta-k8s-service-helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.1
version: 0.1.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
Loading

0 comments on commit 94418a5

Please sign in to comment.