in src/ccf/virtual-ccf-provider/aci/AciNginxLoadBalancerProvider.cs [265:371]
private async Task<ContainerGroupData> CreateContainerGroup(
string networkName,
string lbName,
string containerGroupName,
JsonObject providerConfig,
string tgzConfigData,
string dnsNameLabel)
{
var client = new ArmClient(new DefaultAzureCredential());
string location = providerConfig["location"]!.ToString();
string subscriptionId = providerConfig["subscriptionId"]!.ToString();
string resourceGroupName = providerConfig["resourceGroupName"]!.ToString();
ResourceIdentifier resourceGroupResourceId =
ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource =
client.GetResourceGroupResource(resourceGroupResourceId);
ContainerGroupCollection collection = resourceGroupResource.GetContainerGroups();
ContainerGroupData data = CreateContainerGroupData(
location,
networkName,
lbName,
dnsNameLabel,
tgzConfigData);
this.logger.LogInformation(
$"Starting container group creation for load balancer: {containerGroupName}");
ArmOperation<ContainerGroupResource> lro = await collection.CreateOrUpdateAsync(
WaitUntil.Completed,
containerGroupName,
data);
ContainerGroupResource result = lro.Value;
// The variable result is a resource, you could call other operations on this instance as
// well.
ContainerGroupData resourceData = result.Data;
this.logger.LogInformation(
$"container group creation succeeded. " +
$"id: {resourceData.Id}, IP address: {resourceData.IPAddress.IP}, " +
$"fqdn: {resourceData.IPAddress.Fqdn}");
return resourceData;
static ContainerGroupData CreateContainerGroupData(
string location,
string networkName,
string lbName,
string dnsNameLabel,
string tgzConfigData)
{
return new ContainerGroupData(
new AzureLocation(location),
new ContainerInstanceContainer[]
{
new(
$"ccf-nginx",
$"{ImageUtils.CcfNginxImage()}:{ImageUtils.CcfNginxTag()}",
new ContainerResourceRequirements(new ContainerResourceRequestsContent(1.5, 1)))
{
Ports =
{
new ContainerPort(Ports.NginxPort)
},
EnvironmentVariables =
{
new ContainerEnvironmentVariable("CONFIG_DATA_TGZ")
{
Value = tgzConfigData
}
}
}
},
ContainerInstanceOperatingSystemType.Linux)
{
Tags =
{
{
AciConstants.CcfNetworkNameTag,
networkName
},
{
AciConstants.CcfNetworkTypeTag,
"load-balancer"
},
{
AciConstants.CcfNetworkResourceNameTag,
lbName
}
},
IPAddress = new ContainerGroupIPAddress(
new ContainerGroupPort[]
{
new(Ports.NginxPort)
{
Protocol = ContainerGroupNetworkProtocol.Tcp,
}
},
ContainerGroupIPAddressType.Public)
{
DnsNameLabel = dnsNameLabel,
AutoGeneratedDomainNameLabelScope = DnsNameLabelReusePolicy.Unsecure
},
};
}
}