Skip to content

Commit

Permalink
Adding ability to make a exec command health probes (#885)
Browse files Browse the repository at this point in the history
* Adding ability to make a exec command health probes

At the behest of our beloved users

* lint

* addressing cr
  • Loading branch information
juandiegopalomino authored May 20, 2022
1 parent 99d0155 commit 6311039
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 29 deletions.
21 changes: 18 additions & 3 deletions modules/aws_k8s_service/aws-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
"$ref": "/common-types/port"
}
},
"healthcheck_command": {
"type": "array",
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `[]` (i.e., no user-specified healthchecks)",
"default": []
},
"liveness_probe_command": {
"type": "array",
"description": "Use if using shell command liveness checks and liveness probe != readiness probe",
"default": []
},
"readiness_probe_command": {
"type": "array",
"description": "Use if using shell command readiness checks and liveness probe != readiness probe",
"default": []
},
"max_history": {
"type": "number",
"description": "The max amount of helm revisions to keep track of (0 for infinite)",
Expand Down Expand Up @@ -94,15 +109,15 @@
},
"healthcheck_path": {
"type": "string",
"description": "See the See the [liveness/readiness](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
},
"liveness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping liveness checks and liveness probe != readiness probe"
},
"readiness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping readiness checks and liveness probe != readiness probe"
},
"initial_liveness_delay": {
"type": "integer",
Expand Down
17 changes: 17 additions & 0 deletions modules/aws_k8s_service/aws-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ tl;dr An (optional) liveness probe determines whether your server should be rest
be sent to a replica or be temporarily rerouted to other replicas. Essentially smart healthchecks. For websockets Opta
just checks the tcp connection on the given port.

Opta supports 2 types of possible health checks (please be advised that while they're not required, they're highly
recommended):

#### Option 1: Health Check HTTP Ping
Quite straightforward, K8s does regular http get requests to your server under a specific given path.
[Any code greater than or equal to 200 and less than 400 indicates success](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
Any other code indicates failure. You can specify this by setting the `healthcheck_path` input, or alternatively the
`liveness_probe_path` and/or the `readiness_probe_path` if you want different behavior for the liveness and readiness
checks.

#### Option 2: Health Check Command
Also simple to understand, K8s regularly execute a shell command of your choosing and considers the
server healthy if it has and exit code of 0. Commands should be passed in as a list of the different
parts (e.g. ["echo", "hello"]). You can specify this by setting the `healthcheck_command` input, or alternatively the
`liveness_probe_command` and/or the `readiness_probe_command` if you want different behavior for the liveness and
readiness checks.

### Autoscaling

As mentioned, autoscaling is available out of the box. We currently only support autoscaling
Expand Down
21 changes: 18 additions & 3 deletions modules/aws_k8s_service/aws-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,32 @@ inputs:
- name: healthcheck_path
user_facing: true
validator: str(required=False)
description: See the See the [liveness/readiness](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)
description: See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)
default: null
- name: healthcheck_command
user_facing: true
validator: list(str(), required=False)
description: See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `[]` (i.e., no user-specified healthchecks)
default: []
- name: liveness_probe_command
user_facing: true
validator: list(str(), required=False)
description: Use if using shell command liveness checks and liveness probe != readiness probe
default: []
- name: readiness_probe_command
user_facing: true
validator: list(str(), required=False)
description: Use if using shell command readiness checks and liveness probe != readiness probe
default: []
- name: liveness_probe_path
user_facing: true
validator: str(required=False)
description: Use if liveness probe != readiness probe
description: Use if using http ping liveness checks and liveness probe != readiness probe
default: null
- name: readiness_probe_path
user_facing: true
validator: str(required=False)
description: Use if liveness probe != readiness probe
description: Use if using http ping readiness checks and liveness probe != readiness probe
default: null
- name: initial_liveness_delay
user_facing: 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 @@ -34,8 +34,10 @@ resource "helm_release" "k8s-service" {
image : local.image
version : var.tag == null ? "latest" : var.tag
livenessProbePath : var.healthcheck_path == null || var.liveness_probe_path != null ? var.liveness_probe_path : var.healthcheck_path,
livenessProbeCommand : length(var.healthcheck_command) == 0 || length(var.liveness_probe_command) != 0 ? var.liveness_probe_command : var.healthcheck_command,
initialLivenessDelay : var.initial_liveness_delay
readinessProbePath : var.healthcheck_path == null || var.readiness_probe_path != null ? var.readiness_probe_path : var.healthcheck_path,
readinessProbeCommand : length(var.healthcheck_command) == 0 || length(var.readiness_probe_command) != 0 ? var.readiness_probe_command : var.healthcheck_command,
initialReadinessDelay : var.initial_readiness_delay
healthcheck_path : var.healthcheck_path,
envVars : var.env_vars,
Expand Down
12 changes: 12 additions & 0 deletions modules/aws_k8s_service/tf_module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ variable "timeout" {
variable "max_history" {
type = number
}

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

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

variable "readiness_probe_command" {
type = list(string)
}
21 changes: 18 additions & 3 deletions modules/azure_k8s_service/azure-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
"default": 3,
"minimum": 0
},
"healthcheck_command": {
"type": "array",
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `[]` (i.e., no user-specified healthchecks)",
"default": []
},
"liveness_probe_command": {
"type": "array",
"description": "Use if using shell command liveness checks and liveness probe != readiness probe",
"default": []
},
"readiness_probe_command": {
"type": "array",
"description": "Use if using shell command readiness checks and liveness probe != readiness probe",
"default": []
},
"max_history": {
"type": "number",
"description": "The max amount of helm revisions to keep track of (0 for infinite)",
Expand Down Expand Up @@ -62,11 +77,11 @@
},
"healthcheck_path": {
"type": "string",
"description": "See the See the [liveness/readiness](https://docs.opta.dev/reference/azurerm/modules/azure-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
},
"liveness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping liveness checks and liveness probe != readiness probe"
},
"initial_liveness_delay": {
"type": "integer",
Expand All @@ -80,7 +95,7 @@
},
"readiness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping readiness checks and liveness probe != readiness probe"
},
"consistent_hash": {
"description": "Use [consistent hashing](https://www.nginx.com/resources/wiki/modules/consistent_hash/)",
Expand Down
17 changes: 17 additions & 0 deletions modules/azure_k8s_service/azure-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ tl;dr An (optional) liveness probe determines whether your server should be rest
be sent to a replica or be temporarily rerouted to other replicas. Essentially smart healthchecks. For websockets Opta
just checks the tcp connection on the given port.

Opta supports 2 types of possible health checks (please be advised that while they're not required, they're highly
recommended):

#### Option 1: Health Check HTTP Ping
Quite straightforward, K8s does regular http get requests to your server under a specific given path.
[Any code greater than or equal to 200 and less than 400 indicates success](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
Any other code indicates failure. You can specify this by setting the `healthcheck_path` input, or alternatively the
`liveness_probe_path` and/or the `readiness_probe_path` if you want different behavior for the liveness and readiness
checks.

#### Option 2: Health Check Command
Also simple to understand, K8s regularly execute a shell command of your choosing and considers the
server healthy if it has and exit code of 0. Commands should be passed in as a list of the different
parts (e.g. ["echo", "hello"]). You can specify this by setting the `healthcheck_command` input, or alternatively the
`liveness_probe_command` and/or the `readiness_probe_command` if you want different behavior for the liveness and
readiness checks.

### Autoscaling

As mentioned, autoscaling is available out of the box. We currently only support autoscaling
Expand Down
21 changes: 18 additions & 3 deletions modules/azure_k8s_service/azure-k8s-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,32 @@ inputs: # (what users see)
- name: healthcheck_path
user_facing: true
validator: str(required=False)
description: See the See the [liveness/readiness](https://docs.opta.dev/reference/azurerm/modules/azure-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)
description: See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)
default: null
- name: healthcheck_command
user_facing: true
validator: list(str(), required=False)
description: See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `[]` (i.e., no user-specified healthchecks)
default: []
- name: liveness_probe_command
user_facing: true
validator: list(str(), required=False)
description: Use if using shell command liveness checks and liveness probe != readiness probe
default: []
- name: readiness_probe_command
user_facing: true
validator: list(str(), required=False)
description: Use if using shell command readiness checks and liveness probe != readiness probe
default: []
- name: liveness_probe_path
user_facing: true
validator: str(required=False)
description: Use if liveness probe != readiness probe
description: Use if using http ping liveness checks and liveness probe != readiness probe
default: null
- name: readiness_probe_path
user_facing: true
validator: str(required=False)
description: Use if liveness probe != readiness probe
description: Use if using http ping readiness checks and liveness probe != readiness probe
default: null
- name: initial_liveness_delay
user_facing: true
Expand Down
2 changes: 2 additions & 0 deletions modules/azure_k8s_service/tf_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ resource "helm_release" "k8s-service" {
image : local.image
version : var.tag == null ? "latest" : var.tag
livenessProbePath : var.healthcheck_path == null || var.liveness_probe_path != null ? var.liveness_probe_path : var.healthcheck_path,
livenessProbeCommand : length(var.healthcheck_command) == 0 || length(var.liveness_probe_command) != 0 ? var.liveness_probe_command : var.healthcheck_command,
initialLivenessDelay : var.initial_liveness_delay
readinessProbePath : var.healthcheck_path == null || var.readiness_probe_path != null ? var.readiness_probe_path : var.healthcheck_path,
readinessProbeCommand : length(var.healthcheck_command) == 0 || length(var.readiness_probe_command) != 0 ? var.readiness_probe_command : var.healthcheck_command,
initialReadinessDelay : var.initial_readiness_delay
healthcheck_path : var.healthcheck_path,
envVars : var.env_vars,
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 @@ -208,3 +208,15 @@ variable "timeout" {
variable "max_history" {
type = number
}

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

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

variable "readiness_probe_command" {
type = list(string)
}
22 changes: 22 additions & 0 deletions modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ def process(self, module_idx: int) -> None:
new_uris.append(public_uri)
self.module.data["public_uri"] = new_uris

liveness_probe_command = self.module.data.get(
"healthcheck_command"
) or self.module.data.get("liveness_probe_command")
liveness_probe_path = self.module.data.get(
"healthcheck_path"
) or self.module.data.get("liveness_probe_path")
if liveness_probe_path is not None and liveness_probe_command is not None:
raise UserErrors(
"Invalid liveness probes: you can only specify a path for an http get request or a shell command to run, not both."
)

readiness_probe_command = self.module.data.get(
"healthcheck_command"
) or self.module.data.get("readiness_probe_command")
readiness_probe_path = self.module.data.get(
"healthcheck_path"
) or self.module.data.get("readiness_probe_path")
if readiness_probe_path is not None and readiness_probe_command is not None:
raise UserErrors(
"Invalid readiness probes: you can only specify a path for an http get request or a shell command to run, not both."
)

super(K8sServiceModuleProcessor, self).process(module_idx)

def get_event_properties(self) -> Dict[str, int]:
Expand Down
21 changes: 18 additions & 3 deletions modules/gcp_k8s_service/gcp-k8s-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
"description": "The max amount of helm revisions to keep track of (0 for infinite)",
"default": 25
},
"healthcheck_command": {
"type": "array",
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `[]` (i.e., no user-specified healthchecks)",
"default": []
},
"liveness_probe_command": {
"type": "array",
"description": "Use if using shell command liveness checks and liveness probe != readiness probe",
"default": []
},
"readiness_probe_command": {
"type": "array",
"description": "Use if using shell command readiness checks and liveness probe != readiness probe",
"default": []
},
"timeout": {
"type": "number",
"description": "Time in seconds to wait for deployment.",
Expand Down Expand Up @@ -79,15 +94,15 @@
},
"healthcheck_path": {
"type": "string",
"description": "See the See the [liveness/readiness](https://docs.opta.dev/reference/google/modules/gcp-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
"description": "See the See the [healthcheck probe](https://docs.opta.dev/reference/aws/modules/aws-k8s-service/#healthcheck-probe) section. Default `null` (i.e., no user-specified healthchecks)"
},
"liveness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping liveness checks and liveness probe != readiness probe"
},
"readiness_probe_path": {
"type": "string",
"description": "Use if liveness probe != readiness probe"
"description": "Use if using http ping readiness checks and liveness probe != readiness probe"
},
"initial_liveness_delay": {
"type": "integer",
Expand Down
17 changes: 17 additions & 0 deletions modules/gcp_k8s_service/gcp-k8s-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ tl;dr An (optional) liveness probe determines whether your server should be rest
be sent to a replica or be temporarily rerouted to other replicas. Essentially smart healthchecks. For websockets Opta
just checks the tcp connection on the given port.

Opta supports 2 types of possible health checks (please be advised that while they're not required, they're highly
recommended):

#### Option 1: Health Check HTTP Ping
Quite straightforward, K8s does regular http get requests to your server under a specific given path.
[Any code greater than or equal to 200 and less than 400 indicates success](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
Any other code indicates failure. You can specify this by setting the `healthcheck_path` input, or alternatively the
`liveness_probe_path` and/or the `readiness_probe_path` if you want different behavior for the liveness and readiness
checks.

#### Option 2: Health Check Command
Also simple to understand, K8s regularly execute a shell command of your choosing and considers the
server healthy if it has and exit code of 0. Commands should be passed in as a list of the different
parts (e.g. ["echo", "hello"]). You can specify this by setting the `healthcheck_command` input, or alternatively the
`liveness_probe_command` and/or the `readiness_probe_command` if you want different behavior for the liveness and
readiness checks.

### Autoscaling

As mentioned, autoscaling is available out of the box. We currently only support autoscaling
Expand Down
Loading

0 comments on commit 6311039

Please sign in to comment.