Skip to content

Commit 8967a31

Browse files
authored
mgmt containerinstance, support liveness readiness probe (Azure#32615)
* interface * implementation * changelog.md * add failureThreshold overload for exec and httpGet * add verification for failureThreshold
1 parent 44500b8 commit 8967a31

File tree

6 files changed

+558
-5
lines changed

6 files changed

+558
-5
lines changed

sdk/resourcemanager/azure-resourcemanager-containerinstance/CHANGELOG.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- Supported configuring liveness probes and readiness probes for container instances.
128

139
## 2.21.0 (2022-11-24)
1410

sdk/resourcemanager/azure-resourcemanager-containerinstance/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
--add-opens com.azure.resourcemanager.containerinstance/com.azure.resourcemanager.containerinstance=ALL-UNNAMED
4242
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
4343
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm=ALL-UNNAMED
44+
45+
--add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
4446
</javaModulesSurefireArgLine>
4547
</properties>
4648

sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/implementation/ContainerImpl.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
package com.azure.resourcemanager.containerinstance.implementation;
55

66
import com.azure.resourcemanager.containerinstance.models.Container;
7+
import com.azure.resourcemanager.containerinstance.models.ContainerExec;
78
import com.azure.resourcemanager.containerinstance.models.ContainerGroup;
89
import com.azure.resourcemanager.containerinstance.models.ContainerGroupIpAddressType;
910
import com.azure.resourcemanager.containerinstance.models.ContainerGroupNetworkProtocol;
11+
import com.azure.resourcemanager.containerinstance.models.ContainerHttpGet;
1012
import com.azure.resourcemanager.containerinstance.models.ContainerNetworkProtocol;
1113
import com.azure.resourcemanager.containerinstance.models.ContainerPort;
14+
import com.azure.resourcemanager.containerinstance.models.ContainerProbe;
1215
import com.azure.resourcemanager.containerinstance.models.EnvironmentVariable;
1316
import com.azure.resourcemanager.containerinstance.models.GpuResource;
1417
import com.azure.resourcemanager.containerinstance.models.GpuSku;
@@ -18,6 +21,7 @@
1821
import com.azure.resourcemanager.containerinstance.models.ResourceRequirements;
1922
import com.azure.resourcemanager.containerinstance.models.VolumeMount;
2023
import java.util.ArrayList;
24+
import java.util.List;
2125
import java.util.Map;
2226

2327
/** Implementation for container group's container instance definition stages interface. */
@@ -271,4 +275,108 @@ public ContainerImpl withReadOnlyVolumeMountSetting(Map<String, String> volumeMo
271275

272276
return this;
273277
}
278+
279+
@Override
280+
public ContainerImpl withLivenessProbeExecutionCommand(List<String> command, int probePeriodSeconds) {
281+
return this.withLivenessProbe(
282+
new ContainerProbe()
283+
.withExec(
284+
new ContainerExec()
285+
.withCommand(command))
286+
.withPeriodSeconds(probePeriodSeconds));
287+
}
288+
289+
@Override
290+
public ContainerImpl withLivenessProbeExecutionCommand(List<String> command, int probePeriodSeconds, int failureThreshold) {
291+
return this.withLivenessProbe(
292+
new ContainerProbe()
293+
.withExec(
294+
new ContainerExec()
295+
.withCommand(command))
296+
.withPeriodSeconds(probePeriodSeconds)
297+
.withFailureThreshold(failureThreshold));
298+
}
299+
300+
@Override
301+
public ContainerImpl withLivenessProbeHttpGet(String path, int port, int probePeriodSeconds) {
302+
return this.withLivenessProbe(
303+
new ContainerProbe()
304+
.withHttpGet(
305+
new ContainerHttpGet()
306+
.withPath(path)
307+
.withPort(port))
308+
.withPeriodSeconds(probePeriodSeconds));
309+
}
310+
311+
@Override
312+
public ContainerImpl withLivenessProbeHttpGet(String path, int port, int probePeriodSeconds, int failureThreshold) {
313+
return this.withLivenessProbe(
314+
new ContainerProbe()
315+
.withHttpGet(
316+
new ContainerHttpGet()
317+
.withPath(path)
318+
.withPort(port))
319+
.withPeriodSeconds(probePeriodSeconds)
320+
.withFailureThreshold(failureThreshold));
321+
}
322+
323+
@Override
324+
public ContainerImpl withLivenessProbe(ContainerProbe livenessProbe) {
325+
if (livenessProbe != null) {
326+
this.innerContainer.withLivenessProbe(livenessProbe);
327+
}
328+
return this;
329+
}
330+
331+
@Override
332+
public ContainerImpl withReadinessProbeExecutionCommand(List<String> command, int probePeriodSeconds) {
333+
return this.withReadinessProbe(
334+
new ContainerProbe()
335+
.withExec(
336+
new ContainerExec()
337+
.withCommand(command))
338+
.withPeriodSeconds(probePeriodSeconds));
339+
}
340+
341+
@Override
342+
public ContainerImpl withReadinessProbeExecutionCommand(List<String> command, int probePeriodSeconds, int failureThreshold) {
343+
return this.withReadinessProbe(
344+
new ContainerProbe()
345+
.withExec(
346+
new ContainerExec()
347+
.withCommand(command))
348+
.withPeriodSeconds(probePeriodSeconds)
349+
.withFailureThreshold(failureThreshold));
350+
}
351+
352+
@Override
353+
public ContainerImpl withReadinessProbeHttpGet(String path, int port, int probePeriodSeconds) {
354+
return this.withReadinessProbe(
355+
new ContainerProbe()
356+
.withHttpGet(
357+
new ContainerHttpGet()
358+
.withPath(path)
359+
.withPort(port))
360+
.withPeriodSeconds(probePeriodSeconds));
361+
}
362+
363+
@Override
364+
public ContainerImpl withReadinessProbeHttpGet(String path, int port, int probePeriodSeconds, int failureThreshold) {
365+
return this.withReadinessProbe(
366+
new ContainerProbe()
367+
.withHttpGet(
368+
new ContainerHttpGet()
369+
.withPath(path)
370+
.withPort(port))
371+
.withPeriodSeconds(probePeriodSeconds)
372+
.withFailureThreshold(failureThreshold));
373+
}
374+
375+
@Override
376+
public ContainerImpl withReadinessProbe(ContainerProbe readinessProbe) {
377+
if (readinessProbe != null) {
378+
this.innerContainer.withReadinessProbe(readinessProbe);
379+
}
380+
return this;
381+
}
274382
}

sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/models/ContainerGroup.java

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,145 @@ WithContainerInstanceAttach<ParentT> withReadOnlyVolumeMountSetting(
922922
Map<String, String> volumeMountSetting);
923923
}
924924

925+
/**
926+
* The stage of the container instance definition allowing to specify liveness probe.
927+
* Azure Container Instances supports liveness probes so that you can configure your containers within your
928+
* container group to restart if critical functionality is not working.
929+
*
930+
* @param <ParentT> the stage of the parent definition to return to after attaching this definition
931+
*/
932+
interface WithLivenessProbe<ParentT> {
933+
/**
934+
* Specifies the container's liveness probe to execute a given command at a given interval.
935+
* <p>If the probe command execution fails, the container will restart.</p>
936+
* <p>Only 1 liveness probe can be set for a given container.</p>
937+
*
938+
* @param command the command for the probe to execute
939+
* @param probePeriodSeconds the interval at which the command executes
940+
* @return the next stage of the definition
941+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-command">liveness command</a>
942+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-probes-and-restart-policies">liveness probes and restart policies</a>
943+
*/
944+
WithContainerInstanceAttach<ParentT> withLivenessProbeExecutionCommand(List<String> command, int probePeriodSeconds);
945+
946+
/**
947+
* Specifies the container's liveness probe to execute a given command at a given interval.
948+
* <p>After the probe command execution failure reaches the given threshold, the container will restart.</p>
949+
* <p>Only 1 liveness probe can be set for a given container.</p>
950+
*
951+
* @param command the command for the probe to execute
952+
* @param probePeriodSeconds the interval at which the command executes
953+
* @param failureThreshold the consecutive probe failure count before the container restarts
954+
* @return the next stage of the definition
955+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-command">liveness command</a>
956+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-probes-and-restart-policies">liveness probes and restart policies</a>
957+
*/
958+
WithContainerInstanceAttach<ParentT> withLivenessProbeExecutionCommand(List<String> command, int probePeriodSeconds, int failureThreshold);
959+
960+
/**
961+
* Specifies the container's liveness probe to perform an Http Get at a given interval.
962+
* <p>If the probe HTTP GET operation fails with non-200 response, the container will restart.</p>
963+
* <p>Only 1 liveness probe can be set for a given container.</p>
964+
*
965+
* @param path the path to perform the Http Get, starts with "/"
966+
* @param probePeriodSeconds the interval at which the Http Get performs
967+
* @param port the port number to probe
968+
* @return the next stage of the definition
969+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-probes-and-restart-policies">liveness probes and restart policies</a>
970+
*/
971+
WithContainerInstanceAttach<ParentT> withLivenessProbeHttpGet(String path, int port, int probePeriodSeconds);
972+
973+
/**
974+
* Specifies the container's liveness probe to perform an Http Get at a given interval.
975+
* <p>After the probe HTTP GET failure with non-200 response reaches the given threshold, the container will restart.</p>
976+
* <p>Only 1 liveness probe can be set for a given container.</p>
977+
*
978+
* @param path the path to perform the Http Get, starts with "/"
979+
* @param probePeriodSeconds the interval at which the Http Get performs
980+
* @param port the port number to probe
981+
* @param failureThreshold the consecutive probe failure count before the container restarts
982+
* @return the next stage of the definition
983+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-probes-and-restart-policies">liveness probes and restart policies</a>
984+
*/
985+
WithContainerInstanceAttach<ParentT> withLivenessProbeHttpGet(String path, int port, int probePeriodSeconds, int failureThreshold);
986+
987+
/**
988+
* Specifies the container's liveness probe.
989+
*
990+
* @param livenessProbe the liveness probe
991+
* @return the next stage of the definition
992+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-liveness-probe#liveness-probes-and-restart-policies">liveness probes and restart policies</a>
993+
*/
994+
WithContainerInstanceAttach<ParentT> withLivenessProbe(ContainerProbe livenessProbe);
995+
}
996+
997+
/**
998+
* The stage of the container instance definition allowing to specify readiness probe.
999+
* Azure Container Instances supports readiness probes to include configurations so that your container
1000+
* can't be accessed under certain conditions.
1001+
*
1002+
* @param <ParentT> the stage of the parent definition to return to after attaching this definition
1003+
*/
1004+
interface WithReadinessProbe<ParentT> {
1005+
/**
1006+
* Specifies the container's readiness probe to execute a given command at a given interval.
1007+
* <p>If the probe command execution fails, the container will continue to run but can't be accessed.</p>
1008+
* <p>Only 1 readiness probe can be set for a given container.</p>
1009+
*
1010+
* @param command the command for the probe to execute
1011+
* @param probePeriodSeconds the interval at which the command executes
1012+
* @return the next stage of the definition
1013+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-readiness-probe#readiness-command">readiness command</a>
1014+
*/
1015+
WithContainerInstanceAttach<ParentT> withReadinessProbeExecutionCommand(List<String> command, int probePeriodSeconds);
1016+
1017+
/**
1018+
* Specifies the container's readiness probe to execute a given command at a given interval.
1019+
* <p>After the probe command execution failure reaches the given threshold, the container will continue to run but can't be accessed.</p>
1020+
* <p>Only 1 readiness probe can be set for a given container.</p>
1021+
*
1022+
* @param command the command for the probe to execute
1023+
* @param probePeriodSeconds the interval at which the command executes
1024+
* @param failureThreshold the consecutive probe failure count before the container becomes inaccessible
1025+
* @return the next stage of the definition
1026+
* @see <a href="https://learn.microsoft.com/en-us/azure/container-instances/container-instances-readiness-probe#readiness-command">readiness command</a>
1027+
*/
1028+
WithContainerInstanceAttach<ParentT> withReadinessProbeExecutionCommand(List<String> command, int probePeriodSeconds, int failureThreshold);
1029+
1030+
/**
1031+
* Specifies the container's readiness probe to perform an Http Get at a given interval.
1032+
* <p>If the probe HTTP GET operation fails with non-200 response, the container will continue to run but can't be accessed.</p>
1033+
* <p>Only 1 readiness probe can be set for a given container.</p>
1034+
*
1035+
* @param path the path to perform the Http Get, starts with "/"
1036+
* @param port the port number to probe
1037+
* @param probePeriodSeconds the interval at which the Http Get performs
1038+
* @return the next stage of the definition
1039+
*/
1040+
WithContainerInstanceAttach<ParentT> withReadinessProbeHttpGet(String path, int port, int probePeriodSeconds);
1041+
1042+
/**
1043+
* Specifies the container's readiness probe to perform an Http Get at a given interval.
1044+
* <p>After the probe HTTP GET failure with non-200 response reaches the given threshold, the container will continue to run but can't be accessed.</p>
1045+
* <p>Only 1 readiness probe can be set for a given container.</p>
1046+
*
1047+
* @param path the path to perform the Http Get, starts with "/"
1048+
* @param port the port number to probe
1049+
* @param probePeriodSeconds the interval at which the Http Get performs
1050+
* @param failureThreshold the consecutive probe failure count before the container becomes inaccessible
1051+
* @return the next stage of the definition
1052+
*/
1053+
WithContainerInstanceAttach<ParentT> withReadinessProbeHttpGet(String path, int port, int probePeriodSeconds, int failureThreshold);
1054+
1055+
/**
1056+
* Specifies the container's readiness probe.
1057+
*
1058+
* @param readinessProbe the readiness probe
1059+
* @return the next stage of the definition
1060+
*/
1061+
WithContainerInstanceAttach<ParentT> withReadinessProbe(ContainerProbe readinessProbe);
1062+
}
1063+
9251064
/**
9261065
* The final stage of the container instance definition.
9271066
*
@@ -937,6 +1076,8 @@ interface WithContainerInstanceAttach<ParentT>
9371076
WithStartingCommandLine<ParentT>,
9381077
WithEnvironmentVariables<ParentT>,
9391078
WithVolumeMountSetting<ParentT>,
1079+
WithLivenessProbe<ParentT>,
1080+
WithReadinessProbe<ParentT>,
9401081
Attachable.InDefinition<ParentT> {
9411082
}
9421083

0 commit comments

Comments
 (0)