From 9b06d180239d714a4edc3f774301bb0a19ae3ca0 Mon Sep 17 00:00:00 2001 From: Jeremy Rickard Date: Tue, 24 Jul 2018 15:08:25 -0700 Subject: [PATCH] ACI Provider: Adding Liveness/Readiness probes to ACI sdk (#267) * Adding Liveness/Readiness probes to ACI sdk * Rename Secure to SecureValue * Slightly modify failure test. * Remove errant t.Fatal line --- providers/azure/client/aci/client_test.go | 143 ++++++++++++++++++++++ providers/azure/client/aci/types.go | 31 ++++- 2 files changed, 172 insertions(+), 2 deletions(-) diff --git a/providers/azure/client/aci/client_test.go b/providers/azure/client/aci/client_test.go index aa8c9d5e6..bae449f4e 100644 --- a/providers/azure/client/aci/client_test.go +++ b/providers/azure/client/aci/client_test.go @@ -217,6 +217,149 @@ func TestListContainerGroup(t *testing.T) { } } +func TestCreateContainerGroupWithLivenessProbe(t *testing.T) { + uid := uuid.New() + congainerGroupName := containerGroup + "-" + uid.String()[0:6] + cg, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{ + Location: location, + ContainerGroupProperties: ContainerGroupProperties{ + OsType: Linux, + Containers: []Container{ + { + Name: "nginx", + ContainerProperties: ContainerProperties{ + Image: "nginx", + Command: []string{"nginx", "-g", "daemon off;"}, + Ports: []ContainerPort{ + { + Protocol: ContainerNetworkProtocolTCP, + Port: 80, + }, + }, + Resources: ResourceRequirements{ + Requests: &ResourceRequests{ + CPU: 1, + MemoryInGB: 1, + }, + Limits: &ResourceLimits{ + CPU: 1, + MemoryInGB: 1, + }, + }, + LivenessProbe: &ContainerProbe{ + HTTPGet: &ContainerHTTPGetProbe{ + Port: 80, + }, + }, + }, + }, + }, + }, + }) + if err != nil { + t.Fatal(err) + } + if cg.Name != congainerGroupName { + t.Fatalf("resource group name is %s, expected %s", cg.Name, congainerGroupName) + } +} + +func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) { + uid := uuid.New() + congainerGroupName := containerGroup + "-" + uid.String()[0:6] + _, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{ + Location: location, + ContainerGroupProperties: ContainerGroupProperties{ + OsType: Linux, + Containers: []Container{ + { + Name: "nginx", + ContainerProperties: ContainerProperties{ + Image: "nginx", + Command: []string{"nginx", "-g", "daemon off;"}, + Ports: []ContainerPort{ + { + Protocol: ContainerNetworkProtocolTCP, + Port: 80, + }, + }, + Resources: ResourceRequirements{ + Requests: &ResourceRequests{ + CPU: 1, + MemoryInGB: 1, + }, + Limits: &ResourceLimits{ + CPU: 1, + MemoryInGB: 1, + }, + }, + LivenessProbe: &ContainerProbe{ + HTTPGet: &ContainerHTTPGetProbe{ + Path: "/", + }, + }, + }, + }, + }, + }, + }) + if err == nil { + t.Fatal("expected failure") + } +} + +func TestCreateContainerGroupWithReadinessProbe(t *testing.T) { + uid := uuid.New() + congainerGroupName := containerGroup + "-" + uid.String()[0:6] + cg, err := client.CreateContainerGroup(resourceGroup, congainerGroupName, ContainerGroup{ + Location: location, + ContainerGroupProperties: ContainerGroupProperties{ + OsType: Linux, + Containers: []Container{ + { + Name: "nginx", + ContainerProperties: ContainerProperties{ + Image: "nginx", + Command: []string{"nginx", "-g", "daemon off;"}, + Ports: []ContainerPort{ + { + Protocol: ContainerNetworkProtocolTCP, + Port: 80, + }, + }, + Resources: ResourceRequirements{ + Requests: &ResourceRequests{ + CPU: 1, + MemoryInGB: 1, + }, + Limits: &ResourceLimits{ + CPU: 1, + MemoryInGB: 1, + }, + }, + ReadinessProbe: &ContainerProbe{ + HTTPGet: &ContainerHTTPGetProbe{ + Port: 80, + Path: "/", + }, + InitialDelaySeconds: 5, + SuccessThreshold: 3, + FailureThreshold: 5, + TimeoutSeconds: 120, + }, + }, + }, + }, + }, + }) + if err != nil { + t.Fatal(err) + } + if cg.Name != congainerGroupName { + t.Fatalf("resource group name is %s, expected %s", cg.Name, congainerGroupName) + } +} + func TestDeleteContainerGroup(t *testing.T) { err := client.DeleteContainerGroup(resourceGroup, containerGroup) if err != nil { diff --git a/providers/azure/client/aci/types.go b/providers/azure/client/aci/types.go index 1e8b06383..126bce8b5 100644 --- a/providers/azure/client/aci/types.go +++ b/providers/azure/client/aci/types.go @@ -121,6 +121,8 @@ type ContainerProperties struct { InstanceView ContainerPropertiesInstanceView `json:"instanceView,omitempty"` Resources ResourceRequirements `json:"resources,omitempty"` VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"` + LivenessProbe *ContainerProbe `json:"livenessProbe,omitempty"` + ReadinessProbe *ContainerProbe `json:"readinessProbe,omitempty"` } // ContainerPropertiesInstanceView is the instance view of the container instance. Only valid in response. @@ -142,8 +144,9 @@ type ContainerState struct { // EnvironmentVariable is the environment variable to set within the container instance. type EnvironmentVariable struct { - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` + SecureValue string `json:"secureValue,omitempty"` } // Event is a container group or container instance event. @@ -293,3 +296,27 @@ type ExecResponse struct { WebSocketUri string `json:"webSocketUri,omitempty"` Password string `json:"password,omitempty"` } + +// ContainerProbe is a probe definition that can be used for Liveness +// or Readiness checks. +type ContainerProbe struct { + Exec *ContainerExecProbe `json:"exec,omitempty"` + HTTPGet *ContainerHTTPGetProbe `json:"httpGet,omitempty"` + InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"` + Period int32 `json:"periodSeconds,omitempty"` + FailureThreshold int32 `json:"failureThreshold,omitempty"` + SuccessThreshold int32 `json:"successThreshold,omitempty"` + TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"` +} + +// ContainerExecProbe defines a command based probe +type ContainerExecProbe struct { + Command []string `json:"command,omitempty"` +} + +// ContainerHTTPGetProbe defines an HTTP probe +type ContainerHTTPGetProbe struct { + Port int `json:"port"` + Path string `json:"path,omitempty"` + Scheme string `json:"scheme,omitempty"` +}