Plumb context to providers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -90,7 +91,7 @@ func TestNewClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateContainerGroupFails(t *testing.T) {
|
||||
_, err := client.CreateContainerGroup(resourceGroup, containerGroup, ContainerGroup{
|
||||
_, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroup, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -121,7 +122,7 @@ func TestCreateContainerGroupFails(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateContainerGroupWithoutResourceLimit(t *testing.T) {
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, containerGroup, ContainerGroup{
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroup, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -155,13 +156,13 @@ func TestCreateContainerGroupWithoutResourceLimit(t *testing.T) {
|
||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroup)
|
||||
}
|
||||
|
||||
if err := client.DeleteContainerGroup(resourceGroup, containerGroup); err != nil {
|
||||
if err := client.DeleteContainerGroup(context.Background(), resourceGroup, containerGroup); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateContainerGroup(t *testing.T) {
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, containerGroup, ContainerGroup{
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroup, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -201,7 +202,7 @@ func TestCreateContainerGroup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateContainerGroupWithBadVNetFails(t *testing.T) {
|
||||
_, err := client.CreateContainerGroup(resourceGroup, containerGroup, ContainerGroup{
|
||||
_, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroup, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -250,7 +251,7 @@ func TestCreateContainerGroupWithBadVNetFails(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContainerGroup(t *testing.T) {
|
||||
cg, err, _ := client.GetContainerGroup(resourceGroup, containerGroup)
|
||||
cg, err, _ := client.GetContainerGroup(context.Background(), resourceGroup, containerGroup)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -260,7 +261,7 @@ func TestGetContainerGroup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListContainerGroup(t *testing.T) {
|
||||
list, err := client.ListContainerGroups(resourceGroup)
|
||||
list, err := client.ListContainerGroups(context.Background(), resourceGroup)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -274,7 +275,7 @@ func TestListContainerGroup(t *testing.T) {
|
||||
func TestCreateContainerGroupWithLivenessProbe(t *testing.T) {
|
||||
uid := uuid.New()
|
||||
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroupName, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -321,7 +322,7 @@ func TestCreateContainerGroupWithLivenessProbe(t *testing.T) {
|
||||
func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) {
|
||||
uid := uuid.New()
|
||||
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||
_, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||
_, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroupName, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -365,7 +366,7 @@ func TestCreateContainerGroupFailsWithLivenessProbeMissingPort(t *testing.T) {
|
||||
func TestCreateContainerGroupWithReadinessProbe(t *testing.T) {
|
||||
uid := uuid.New()
|
||||
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, ContainerGroup{
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroupName, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -420,7 +421,7 @@ func TestCreateContainerGroupWithLogAnalytics(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cgname := "cgla"
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, cgname, ContainerGroup{
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, cgname, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -458,14 +459,14 @@ func TestCreateContainerGroupWithLogAnalytics(t *testing.T) {
|
||||
if cg.Name != cgname {
|
||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, cgname)
|
||||
}
|
||||
if err := client.DeleteContainerGroup(resourceGroup, cgname); err != nil {
|
||||
if err := client.DeleteContainerGroup(context.Background(), resourceGroup, cgname); err != nil {
|
||||
t.Fatalf("Delete Container Group failed: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateContainerGroupWithInvalidLogAnalytics(t *testing.T) {
|
||||
law := &LogAnalyticsWorkspace{}
|
||||
_, err := client.CreateContainerGroup(resourceGroup, containerGroup, ContainerGroup{
|
||||
_, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroup, ContainerGroup{
|
||||
Location: location,
|
||||
ContainerGroupProperties: ContainerGroupProperties{
|
||||
OsType: Linux,
|
||||
@@ -506,52 +507,52 @@ func TestCreateContainerGroupWithInvalidLogAnalytics(t *testing.T) {
|
||||
|
||||
func TestCreateContainerGroupWithVNet(t *testing.T) {
|
||||
uid := uuid.New()
|
||||
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||
containerGroupName := containerGroup + "-" + uid.String()[0:6]
|
||||
fakeKubeConfig := base64.StdEncoding.EncodeToString([]byte(uid.String()))
|
||||
networkProfileId := "/subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/aci-connector/providers/Microsoft.Network/networkprofiles/aci-connector-network-profile-westus"
|
||||
diagnostics, err := NewContainerGroupDiagnosticsFromFile("../../../../loganalytics.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
diagnostics, err := NewContainerGroupDiagnosticsFromFile("../../../../loganalytics.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
diagnostics.LogAnalytics.LogType = LogAnlyticsLogTypeContainerInsights
|
||||
|
||||
cg, err := client.CreateContainerGroup(resourceGroup, containerGroupName, 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
NetworkProfile: &NetworkProfileDefinition{
|
||||
ID: networkProfileId,
|
||||
},
|
||||
cg, err := client.CreateContainerGroup(context.Background(), resourceGroup, containerGroupName, 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
NetworkProfile: &NetworkProfileDefinition{
|
||||
ID: networkProfileId,
|
||||
},
|
||||
Extensions: []*Extension{
|
||||
&Extension{
|
||||
Name: "kube-proxy",
|
||||
Properties: &ExtensionProperties{
|
||||
Properties: &ExtensionProperties{
|
||||
Type: ExtensionTypeKubeProxy,
|
||||
Version: ExtensionVersion1_0,
|
||||
Settings: map[string]string{
|
||||
@@ -567,23 +568,23 @@ func TestCreateContainerGroupWithVNet(t *testing.T) {
|
||||
DNSConfig: &DNSConfig{
|
||||
NameServers: []string{"1.1.1.1"},
|
||||
},
|
||||
Diagnostics: diagnostics,
|
||||
},
|
||||
})
|
||||
Diagnostics: diagnostics,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cg.Name != containerGroupName {
|
||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroupName)
|
||||
}
|
||||
if err := client.DeleteContainerGroup(resourceGroup, containerGroupName); err != nil {
|
||||
t.Fatalf("Delete Container Group failed: %s", err.Error())
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cg.Name != containerGroupName {
|
||||
t.Fatalf("resource group name is %s, expected %s", cg.Name, containerGroupName)
|
||||
}
|
||||
if err := client.DeleteContainerGroup(context.Background(), resourceGroup, containerGroupName); err != nil {
|
||||
t.Fatalf("Delete Container Group failed: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteContainerGroup(t *testing.T) {
|
||||
err := client.DeleteContainerGroup(resourceGroup, containerGroup)
|
||||
err := client.DeleteContainerGroup(context.Background(), resourceGroup, containerGroup)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package aci
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
// CreateContainerGroup creates a new Azure Container Instance with the
|
||||
// provided properties.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate
|
||||
func (c *Client) CreateContainerGroup(resourceGroup, containerGroupName string, containerGroup ContainerGroup) (*ContainerGroup, error) {
|
||||
func (c *Client) CreateContainerGroup(ctx context.Context, resourceGroup, containerGroupName string, containerGroup ContainerGroup) (*ContainerGroup, error) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -34,6 +35,7 @@ func (c *Client) CreateContainerGroup(resourceGroup, containerGroupName string,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Creating create/update container group uri request failed: %v", err)
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
// Add the parameters to the url.
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
// DeleteContainerGroup deletes an Azure Container Instance in the provided
|
||||
// resource group with the given container group name.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/delete
|
||||
func (c *Client) DeleteContainerGroup(resourceGroup, containerGroupName string) error {
|
||||
func (c *Client) DeleteContainerGroup(ctx context.Context, resourceGroup, containerGroupName string) error {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -25,6 +26,7 @@ func (c *Client) DeleteContainerGroup(resourceGroup, containerGroupName string)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Creating delete container group uri request failed: %v", err)
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
// Add the parameters to the url.
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
// GetContainerGroup gets an Azure Container Instance in the provided
|
||||
// resource group with the given container group name.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/get
|
||||
func (c *Client) GetContainerGroup(resourceGroup, containerGroupName string) (*ContainerGroup, error, *int) {
|
||||
func (c *Client) GetContainerGroup(ctx context.Context, resourceGroup, containerGroupName string) (*ContainerGroup, error, *int) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -27,6 +28,7 @@ func (c *Client) GetContainerGroup(resourceGroup, containerGroupName string) (*C
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Creating get container group uri request failed: %v", err), nil
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
// Add the parameters to the url.
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
// if it is not empty.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/list
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/listbyresourcegroup
|
||||
func (c *Client) ListContainerGroups(resourceGroup string) (*ContainerGroupListResult, error) {
|
||||
func (c *Client) ListContainerGroups(ctx context.Context, resourceGroup string) (*ContainerGroupListResult, error) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
}
|
||||
@@ -35,6 +36,7 @@ func (c *Client) ListContainerGroups(resourceGroup string) (*ContainerGroupListR
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Creating get container group list uri request failed: %v", err)
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
// Add the parameters to the url.
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
// GetContainerLogs returns the logs from an Azure Container Instance
|
||||
// in the provided resource group with the given container group name.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/ContainerLogs/List
|
||||
func (c *Client) GetContainerLogs(resourceGroup, containerGroupName, containerName string, tail int) (*Logs, error) {
|
||||
func (c *Client) GetContainerLogs(ctx context.Context, resourceGroup, containerGroupName, containerName string, tail int) (*Logs, error) {
|
||||
urlParams := url.Values{
|
||||
"api-version": []string{apiVersion},
|
||||
"tail": []string{fmt.Sprintf("%d", tail)},
|
||||
@@ -28,6 +29,7 @@ func (c *Client) GetContainerLogs(resourceGroup, containerGroupName, containerNa
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Creating get container logs uri request failed: %v", err)
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
// Add the parameters to the url.
|
||||
if err := api.ExpandURL(req.URL, map[string]string{
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package aci
|
||||
|
||||
import "context"
|
||||
|
||||
// UpdateContainerGroup updates an Azure Container Instance with the
|
||||
// provided properties.
|
||||
// From: https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate
|
||||
func (c *Client) UpdateContainerGroup(resourceGroup, containerGroupName string, containerGroup ContainerGroup) (*ContainerGroup, error) {
|
||||
return c.CreateContainerGroup(resourceGroup, containerGroupName, containerGroup)
|
||||
func (c *Client) UpdateContainerGroup(ctx context.Context, resourceGroup, containerGroupName string, containerGroup ContainerGroup) (*ContainerGroup, error) {
|
||||
return c.CreateContainerGroup(ctx, resourceGroup, containerGroupName, containerGroup)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user