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

Feature: Add container create options on create/edit edge module #1359

Closed
Closed
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 @@ -11,11 +11,11 @@
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.10" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.9" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.20" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ public void CreateGatewayModuleShouldReturnValue()
// Arrange
var config = new Configuration("config_test");

var expectedContainerCreateOptions = /*lang=json,strict*/ "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}";

var jPropModule = new Dictionary<string, object>()
{
{ "status", "running" },
{ "version", "1.0" },
{ "settings", new Dictionary<string, object>()
{
{ "image", "image_test" }
{ "image", "image_test" },
{ "createOptions", expectedContainerCreateOptions }
}
},
{ "env", new Dictionary<string, object>()
Expand All @@ -118,6 +121,7 @@ public void CreateGatewayModuleShouldReturnValue()
Assert.IsNotNull(result);
Assert.AreEqual("running", result.Status);
Assert.AreEqual("image_test", result.ImageURI);
Assert.AreEqual(expectedContainerCreateOptions, result.ContainerCreateOptions);
Assert.AreEqual(1, result.EnvironmentVariables.Count);
}

Expand Down Expand Up @@ -151,21 +155,26 @@ public void CreateGatewayModuleWithNullModuleShouldThrowException()
public void GenerateModulesContentShouldReturnValue()
{
// Arrange
var expectedModuleName = "ModuleTest";
var expectedContainerCreateOptions = /*lang=json,strict*/
"{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}";

var edgeModel = new IoTEdgeModel()
{
ModelId = Guid.NewGuid().ToString(),
Name = "Model test",
Description = "Description Test",
EdgeModules = new List<IoTEdgeModule>()
{
new IoTEdgeModule()
new()
{
ModuleName = "ModuleTest",
ModuleName = expectedModuleName,
Status = "running",
ImageURI = "image",
ContainerCreateOptions = expectedContainerCreateOptions,
EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>()
{
new IoTEdgeModuleEnvironmentVariable(){ Name = "envTest01", Value = "test" }
new() { Name = "envTest01", Value = "test" }
},
ModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>()
}
Expand All @@ -179,6 +188,9 @@ public void GenerateModulesContentShouldReturnValue()
Assert.IsNotNull(result);
Assert.IsAssignableFrom<Dictionary<string, IDictionary<string, object>>>(result);
Assert.AreEqual(2, result.Count);
var edgeHubPropertiesDesired = (EdgeAgentPropertiesDesired)result["$edgeAgent"]["properties.desired"];
_ = edgeHubPropertiesDesired.Modules[expectedModuleName].Settings.CreateOptions.Should()
.Be(expectedContainerCreateOptions);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<PackageReference Include="FluentValidation" Version="11.2.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web.Extensions" Version="5.0.0-preview9.20513.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.10" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@using AzureIoTHub.Portal.Models.v10
@using AzureIoTHub.Portal.Shared.Models.v10
@inject HttpClient Http
@inject IJSRuntime JS
@inject ISnackbar Snackbar

<MudDialog ContentStyle="overflow:auto;max-height:600px;">
<DialogContent >
Expand All @@ -23,6 +20,16 @@
For="@(()=> Module.ImageURI)"
Required="true" />
</MudItem>
<MudItem xs="12">
<MudTextField @bind-Value="@currentContainerCreateOptions"
id=@nameof(IoTEdgeModule.ContainerCreateOptions)
Label="Container Create Options"
Variant="Variant.Outlined"
For="@(()=> Module.ContainerCreateOptions)" />
</MudItem>
<MudItem xs="12">
<MudAlert Severity="Severity.Info"><MudLink Href="https://learn.microsoft.com/en-us/azure/iot-edge/how-to-use-create-options" Target="_blank ">How to configure container create options for IoT Edge modules</MudLink></MudAlert>
</MudItem>
</MudGrid>

<MudTabs Elevation="1" Class="mt-10" Rounded="true" PanelClass="mt-6 scrollable-tab-content">
Expand Down Expand Up @@ -55,6 +62,7 @@

private string currentModuleName;
private string currentImageUri;
private string currentContainerCreateOptions;

private List<IoTEdgeModuleEnvironmentVariable> currentEnvironmentVariables = new();
private List<IoTEdgeModuleTwinSetting> currentModuleIdentityTwinSettings = new();
Expand All @@ -69,6 +77,7 @@

currentModuleName = Module.ModuleName;
currentImageUri = Module.ImageURI;
currentContainerCreateOptions = Module.ContainerCreateOptions;
currentEnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(Module.EnvironmentVariables.ToArray());
currentModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>(Module.ModuleIdentityTwinSettings.ToArray());
currentCommands = new List<IoTEdgeModuleCommand>(Module.Commands.ToArray());
Expand All @@ -80,6 +89,7 @@
{
Module.ModuleName = currentModuleName;
Module.ImageURI = currentImageUri;
Module.ContainerCreateOptions = currentContainerCreateOptions;
Module.EnvironmentVariables = new List<IoTEdgeModuleEnvironmentVariable>(currentEnvironmentVariables.ToArray());
Module.ModuleIdentityTwinSettings = new List<IoTEdgeModuleTwinSetting>(currentModuleIdentityTwinSettings.ToArray());
Module.Commands = new List<IoTEdgeModuleCommand>(currentCommands.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Azure.Devices.Shared" Version="1.30.2" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.10" />
<PackageReference Include="Microsoft.Graph" Version="4.44.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.4.3" />
Expand Down
4 changes: 3 additions & 1 deletion src/AzureIoTHub.Portal/Server/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static IoTEdgeModule CreateGatewayModule(Configuration config, JProperty
{
ModuleName = module.Name,
ImageURI = module.Value["settings"]["image"]?.Value<string>(),
ContainerCreateOptions = module.Value["settings"]["createOptions"]?.Value<string>(),
Status = module.Value["status"]?.Value<string>(),
};

Expand Down Expand Up @@ -248,7 +249,8 @@ public static Dictionary<string, IDictionary<string, object>> GenerateModulesCon
Status = "running",
Settings = new ModuleSettings()
{
Image = module.ImageURI
Image = module.ImageURI,
CreateOptions = module.ContainerCreateOptions
},
RestartPolicy = "always",
EnvironmentVariables = new Dictionary<string, EnvironmentVariable>()
Expand Down
2 changes: 2 additions & 0 deletions src/AzureIoTHub.Portal/Shared/Models/v1.0/IoTEdgeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class IoTEdgeModule
[Required(ErrorMessage = "The device image uri is required.")]
public string ImageURI { get; set; }

public string ContainerCreateOptions { get; set; }

/// <summary>
/// The module status.
/// </summary>
Expand Down