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

container apps - support for additional settings in container apps probes #27551

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
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,7 @@ resource "azurerm_container_app" "test" {
transport = "HTTP"
port = 5000
path = "/uptime"
initial_delay = 5
timeout = 2
failure_count_threshold = 1
success_count_threshold = 1
Expand Down Expand Up @@ -2227,6 +2228,7 @@ resource "azurerm_container_app" "test" {
startup_probe {
transport = "TCP"
port = 5000
initial_delay = 5
timeout = 5
failure_count_threshold = 1
}
Expand Down
76 changes: 55 additions & 21 deletions internal/services/containerapps/helpers/container_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ type ContainerAppReadinessProbe struct {
Port int64 `tfschema:"port"`
Path string `tfschema:"path"`
Headers []HttpHeader `tfschema:"header"`
InitialDelay int64 `tfschema:"initial_delay"`
Interval int64 `tfschema:"interval_seconds"`
Timeout int64 `tfschema:"timeout"`
FailureThreshold int64 `tfschema:"failure_count_threshold"`
Expand Down Expand Up @@ -1799,6 +1800,14 @@ func ContainerAppReadinessProbeSchema() *pluginsdk.Schema {
},
},

"initial_delay": {
stephybun marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 60),
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.",
},

"interval_seconds": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand All @@ -1819,8 +1828,8 @@ func ContainerAppReadinessProbeSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 3,
ValidateFunc: validation.IntBetween(1, 10),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
ValidateFunc: validation.IntBetween(1, 30),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"success_count_threshold": {
Expand Down Expand Up @@ -1885,6 +1894,12 @@ func ContainerAppReadinessProbeSchemaComputed() *pluginsdk.Schema {
},
},

"initial_delay": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.",
},

"interval_seconds": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand All @@ -1900,7 +1915,7 @@ func ContainerAppReadinessProbeSchemaComputed() *pluginsdk.Schema {
"failure_count_threshold": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"success_count_threshold": {
Expand All @@ -1916,11 +1931,12 @@ func ContainerAppReadinessProbeSchemaComputed() *pluginsdk.Schema {
func expandContainerAppReadinessProbe(input ContainerAppReadinessProbe) containerapps.ContainerAppProbe {
probeType := containerapps.TypeReadiness
result := containerapps.ContainerAppProbe{
Type: &probeType,
PeriodSeconds: pointer.To(input.Interval),
TimeoutSeconds: pointer.To(input.Timeout),
FailureThreshold: pointer.To(input.FailureThreshold),
SuccessThreshold: pointer.To(input.SuccessThreshold),
Type: &probeType,
InitialDelaySeconds: pointer.To(input.InitialDelay),
PeriodSeconds: pointer.To(input.Interval),
TimeoutSeconds: pointer.To(input.Timeout),
FailureThreshold: pointer.To(input.FailureThreshold),
SuccessThreshold: pointer.To(input.SuccessThreshold),
}

switch p := strings.ToUpper(input.Transport); p {
Expand Down Expand Up @@ -1957,6 +1973,7 @@ func expandContainerAppReadinessProbe(input ContainerAppReadinessProbe) containe
func flattenContainerAppReadinessProbe(input containerapps.ContainerAppProbe) []ContainerAppReadinessProbe {
result := make([]ContainerAppReadinessProbe, 0)
probe := ContainerAppReadinessProbe{
InitialDelay: pointer.From(input.InitialDelaySeconds),
Interval: pointer.From(input.PeriodSeconds),
Timeout: pointer.From(input.TimeoutSeconds),
FailureThreshold: pointer.From(input.FailureThreshold),
Expand Down Expand Up @@ -2070,8 +2087,8 @@ func ContainerAppLivenessProbeSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: validation.IntBetween(1, 60),
Description: "The time in seconds to wait after the container has started before the probe is started.",
ValidateFunc: validation.IntBetween(0, 60),
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `1` seconds.",
},

"interval_seconds": {
Expand All @@ -2094,8 +2111,8 @@ func ContainerAppLivenessProbeSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 3,
ValidateFunc: validation.IntBetween(1, 10),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
ValidateFunc: validation.IntBetween(1, 30),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"termination_grace_period_seconds": {
Expand Down Expand Up @@ -2161,7 +2178,7 @@ func ContainerAppLivenessProbeSchemaComputed() *pluginsdk.Schema {
"initial_delay": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The time in seconds to wait after the container has started before the probe is started.",
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `1` seconds.",
},

"interval_seconds": {
Expand All @@ -2179,7 +2196,7 @@ func ContainerAppLivenessProbeSchemaComputed() *pluginsdk.Schema {
"failure_count_threshold": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"termination_grace_period_seconds": {
Expand Down Expand Up @@ -2279,6 +2296,7 @@ type ContainerAppStartupProbe struct {
Port int64 `tfschema:"port"`
Path string `tfschema:"path"`
Headers []HttpHeader `tfschema:"header"`
InitialDelay int64 `tfschema:"initial_delay"`
Interval int64 `tfschema:"interval_seconds"`
Timeout int64 `tfschema:"timeout"`
FailureThreshold int64 `tfschema:"failure_count_threshold"`
Expand Down Expand Up @@ -2344,6 +2362,14 @@ func ContainerAppStartupProbeSchema() *pluginsdk.Schema {
},
},

"initial_delay": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 60),
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.",
},

"interval_seconds": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand All @@ -2364,8 +2390,8 @@ func ContainerAppStartupProbeSchema() *pluginsdk.Schema {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 3,
ValidateFunc: validation.IntBetween(1, 10),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
ValidateFunc: validation.IntBetween(1, 30),
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"termination_grace_period_seconds": {
Expand Down Expand Up @@ -2424,6 +2450,12 @@ func ContainerAppStartupProbeSchemaComputed() *pluginsdk.Schema {
},
},

"initial_delay": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.",
},

"interval_seconds": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand All @@ -2439,7 +2471,7 @@ func ContainerAppStartupProbeSchemaComputed() *pluginsdk.Schema {
"failure_count_threshold": {
Type: pluginsdk.TypeInt,
Computed: true,
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.",
Description: "The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.",
},

"termination_grace_period_seconds": {
Expand All @@ -2455,10 +2487,11 @@ func ContainerAppStartupProbeSchemaComputed() *pluginsdk.Schema {
func expandContainerAppStartupProbe(input ContainerAppStartupProbe) containerapps.ContainerAppProbe {
probeType := containerapps.TypeStartup
result := containerapps.ContainerAppProbe{
Type: &probeType,
PeriodSeconds: pointer.To(input.Interval),
TimeoutSeconds: pointer.To(input.Timeout),
FailureThreshold: pointer.To(input.FailureThreshold),
Type: &probeType,
InitialDelaySeconds: pointer.To(input.InitialDelay),
PeriodSeconds: pointer.To(input.Interval),
TimeoutSeconds: pointer.To(input.Timeout),
FailureThreshold: pointer.To(input.FailureThreshold),
Copy link

@Dmitriyx Dmitriyx Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come there is no success threshold property here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a container app that is failing because I can not set a success_count_threshold to it, it will assign it an empty value.
Since I have a container app that is a public container that accepts ingress, Azure does a health check of the service using startup probe.
Since I can not configure it via terraform, my container always fails until I manually configure it on the UI to have a success threshold count to be 1, which then works fine

Copy link

@Dmitriyx Dmitriyx Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the issue you are responding too: #25457
startup_probe should also have a success threshold.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added initialy, but removed later in the same PR due to review in c8002c0

It was removed due to the fact that only a single value is accepted and that is 1. You cannot set the value to anything else. I also use this code for our infra and it's working as expected.

The question would be how it worked until now as the option wasn't present there? If it's really needed, I guess you could create a PR with the changes from that commit to add the success threshold property and see if it's merged.

image

Copy link

@Dmitriyx Dmitriyx Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for a quick response, just tested it again and I do not get the same result - somehow success count threshold is not defaulted to 1. Any ideas on what can be done?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create a new PR with changes from c8002c0 and put the screenshot as an explanation. Are you sure it fails due to the value being empty?

Copy link

@Dmitriyx Dmitriyx Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I am sure - because once I edit the container config on the UI, once I add a success threshold, then the container lives, otherwise it just dies and keeps restarting.

Copy link

@Dmitriyx Dmitriyx Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to make a PR however I get denied
remote: Permission to hashicorp/terraform-provider-azurerm.git denied to Dmitriyx

I will check what the rules are for making a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fork the repo and make changes in the forked repository. Afterwards you can create a PR in Github.

}

switch p := strings.ToUpper(input.Transport); p {
Expand Down Expand Up @@ -2495,6 +2528,7 @@ func expandContainerAppStartupProbe(input ContainerAppStartupProbe) containerapp
func flattenContainerAppStartupProbe(input containerapps.ContainerAppProbe) []ContainerAppStartupProbe {
result := make([]ContainerAppStartupProbe, 0)
probe := ContainerAppStartupProbe{
InitialDelay: pointer.From(input.InitialDelaySeconds),
Interval: pointer.From(input.PeriodSeconds),
Timeout: pointer.From(input.TimeoutSeconds),
FailureThreshold: pointer.From(input.FailureThreshold),
Expand Down
10 changes: 7 additions & 3 deletions website/docs/d/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ A `liveness_probe` block supports the following:

* `host` - The probe hostname. Defaults to the pod IP address. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - The time in seconds to wait after the container has started before the probe is started.
* `initial_delay` - The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `1` seconds.

* `interval_seconds` - How often, in seconds, the probe should run. Possible values are in the range `1` - `240`. Defaults to `10`.

Expand Down Expand Up @@ -187,12 +187,14 @@ An `env` block supports the following:

A `readiness_probe` block supports the following:

* `failure_count_threshold` - The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.
* `failure_count_threshold` - The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.

* `header` - A `header` block as detailed below.

* `host` - The probe hostname. Defaults to the pod IP address. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.

* `interval_seconds` - How often, in seconds, the probe should run. Possible values are between `1` and `240`. Defaults to `10`

* `path` - The URI to use for http type probes. Not valid for `TCP` type probes. Defaults to `/`.
Expand All @@ -217,12 +219,14 @@ A `header` block supports the following:

A `startup_probe` block supports the following:

* `failure_count_threshold` - The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.
* `failure_count_threshold` - The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.

* `header` - A `header` block as detailed below.

* `host` - The value for the host header which should be sent with this probe. If unspecified, the IP Address of the Pod is used as the host header. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.

* `interval_seconds` - How often, in seconds, the probe should run. Possible values are between `1` and `240`. Defaults to `10`

* `path` - The URI to use with the `host` for http type probes. Not valid for `TCP` type probes. Defaults to `/`.
Expand Down
10 changes: 7 additions & 3 deletions website/docs/r/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ A `liveness_probe` block supports the following:

* `host` - (Optional) The probe hostname. Defaults to the pod IP address. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - (Optional) The time in seconds to wait after the container has started before the probe is started.
* `initial_delay` - (Optional) The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `1` seconds.

* `interval_seconds` - (Optional) How often, in seconds, the probe should run. Possible values are in the range `1` - `240`. Defaults to `10`.

Expand Down Expand Up @@ -298,12 +298,14 @@ An `env` block supports the following:

A `readiness_probe` block supports the following:

* `failure_count_threshold` - (Optional) The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.
* `failure_count_threshold` - (Optional) The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.

* `header` - (Optional) A `header` block as detailed below.

* `host` - (Optional) The probe hostname. Defaults to the pod IP address. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - (Optional) The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.

* `interval_seconds` - (Optional) How often, in seconds, the probe should run. Possible values are between `1` and `240`. Defaults to `10`

* `path` - (Optional) The URI to use for http type probes. Not valid for `TCP` type probes. Defaults to `/`.
Expand All @@ -328,12 +330,14 @@ A `header` block supports the following:

A `startup_probe` block supports the following:

* `failure_count_threshold` - (Optional) The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `10`. Defaults to `3`.
* `failure_count_threshold` - (Optional) The number of consecutive failures required to consider this probe as failed. Possible values are between `1` and `30`. Defaults to `3`.

* `header` - (Optional) A `header` block as detailed below.

* `host` - (Optional) The value for the host header which should be sent with this probe. If unspecified, the IP Address of the Pod is used as the host header. Setting a value for `Host` in `headers` can be used to override this for `HTTP` and `HTTPS` type probes.

* `initial_delay` - (Optional) The number of seconds elapsed after the container has started before the probe is initiated. Possible values are between `0` and `60`. Defaults to `0` seconds.

* `interval_seconds` - (Optional) How often, in seconds, the probe should run. Possible values are between `1` and `240`. Defaults to `10`

* `path` - (Optional) The URI to use with the `host` for http type probes. Not valid for `TCP` type probes. Defaults to `/`.
Expand Down
Loading