diff --git a/CodeCoverage.runsettings b/CodeCoverage.runsettings
index 460286f146c..e54f290b9d5 100644
--- a/CodeCoverage.runsettings
+++ b/CodeCoverage.runsettings
@@ -38,7 +38,6 @@ Included items must then not match any entries in the exclude list to remain inc
.*moq\..*
.*app.metrics.*\..*
.*autofac.*
- .*bouncycastle\..*
.*fluentassertions.*
.*microsoft.codeanalysis\..*
.*microsoft.identitymodel\..*
diff --git a/Microsoft.Azure.Devices.Edge.sln b/Microsoft.Azure.Devices.Edge.sln
index d9ea6409349..4adc4968624 100644
--- a/Microsoft.Azure.Devices.Edge.sln
+++ b/Microsoft.Azure.Devices.Edge.sln
@@ -44,9 +44,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{A9F6AF55-719
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Service", "edge-agent\src\Microsoft.Azure.Devices.Edge.Agent.Service\Microsoft.Azure.Devices.Edge.Agent.Service.csproj", "{37129265-046F-4A46-A1BD-C067E6C06264}"
- ProjectSection(ProjectDependencies) = postProject
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E} = {B63C506E-5CB5-4DE8-8275-F7BA8354799E}
- EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Hub.CloudProxy", "edge-hub\src\Microsoft.Azure.Devices.Edge.Hub.CloudProxy\Microsoft.Azure.Devices.Edge.Hub.CloudProxy.csproj", "{F3F1EFBD-CCD0-4579-99EE-C91A1B6D5C5D}"
EndProject
@@ -164,23 +161,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2300ED4C-1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Test.Common", "test\Microsoft.Azure.Devices.Edge.Test.Common\Microsoft.Azure.Devices.Edge.Test.Common.csproj", "{950DACB0-B011-41AF-B0FB-245F749B01AB}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Kubernetes", "edge-agent\src\Microsoft.Azure.Devices.Edge.Agent.Kubernetes\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.csproj", "{B63C506E-5CB5-4DE8-8275-F7BA8354799E}"
- ProjectSection(ProjectDependencies) = postProject
- {B0F37919-0D16-490F-B7A1-665BB93B9A62} = {B0F37919-0D16-490F-B7A1-665BB93B9A62}
- {3B5A4C63-7B33-4E37-9602-29FC8FC7C9C5} = {3B5A4C63-7B33-4E37-9602-29FC8FC7C9C5}
- {84B77973-0092-4DC9-87E3-F16FC2F4E9AE} = {84B77973-0092-4DC9-87E3-F16FC2F4E9AE}
- EndProjectSection
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test", "edge-agent\test\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test.csproj", "{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Test", "test\Microsoft.Azure.Devices.Edge.Test\Microsoft.Azure.Devices.Edge.Test.csproj", "{08986FED-9283-47F1-B938-86D9C6E753E1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Diagnostics", "edge-agent\src\Microsoft.Azure.Devices.Edge.Agent.Diagnostics\Microsoft.Azure.Devices.Edge.Agent.Diagnostics.csproj", "{47AA5965-5826-489D-B74B-314A61629121}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Diagnostics.Test", "edge-agent\test\Microsoft.Azure.Devices.Edge.Agent.Diagnostics.Test\Microsoft.Azure.Devices.Edge.Agent.Diagnostics.Test.csproj", "{B736B03C-1185-4AE5-87B7-665C6790F50F}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Kubernetes.IntegrationTest", "edge-agent\test\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.IntegrationTest\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.IntegrationTest.csproj", "{79540E35-45EA-4568-9AB7-C1CC0BFF73EE}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{F921339B-32F9-4BF3-B364-2DB01FA2F1A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestResultCoordinator", "test\modules\TestResultCoordinator\TestResultCoordinator.csproj", "{8181EB49-62CE-495B-8078-08DCF8C30541}"
@@ -484,18 +470,6 @@ Global
{950DACB0-B011-41AF-B0FB-245F749B01AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{950DACB0-B011-41AF-B0FB-245F749B01AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{950DACB0-B011-41AF-B0FB-245F749B01AB}.Release|Any CPU.Build.0 = Release|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E}.Release|Any CPU.Build.0 = Release|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Release|Any CPU.Build.0 = Release|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -518,14 +492,6 @@ Global
{B736B03C-1185-4AE5-87B7-665C6790F50F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B736B03C-1185-4AE5-87B7-665C6790F50F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B736B03C-1185-4AE5-87B7-665C6790F50F}.Release|Any CPU.Build.0 = Release|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.CodeCoverage|Any CPU.ActiveCfg = Debug|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.CodeCoverage|Any CPU.Build.0 = Debug|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE}.Release|Any CPU.Build.0 = Release|Any CPU
{8181EB49-62CE-495B-8078-08DCF8C30541}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
{8181EB49-62CE-495B-8078-08DCF8C30541}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
{8181EB49-62CE-495B-8078-08DCF8C30541}.CodeCoverage|Any CPU.ActiveCfg = Debug|Any CPU
@@ -758,12 +724,9 @@ Global
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF} = {C3BDC9FA-B7D8-44F3-970F-D24281335F46}
{9BED8F14-63E9-4B4B-88F7-659D5E522CBD} = {63969606-14B2-4D9D-AB72-A5D60D22037C}
{950DACB0-B011-41AF-B0FB-245F749B01AB} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
- {B63C506E-5CB5-4DE8-8275-F7BA8354799E} = {54351E51-19CB-4DE3-8302-99846AB216CF}
- {A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE} = {F5E37327-3AA9-4CC2-9FE3-B28271ADB5E3}
{08986FED-9283-47F1-B938-86D9C6E753E1} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
{47AA5965-5826-489D-B74B-314A61629121} = {54351E51-19CB-4DE3-8302-99846AB216CF}
{B736B03C-1185-4AE5-87B7-665C6790F50F} = {F5E37327-3AA9-4CC2-9FE3-B28271ADB5E3}
- {79540E35-45EA-4568-9AB7-C1CC0BFF73EE} = {F5E37327-3AA9-4CC2-9FE3-B28271ADB5E3}
{F921339B-32F9-4BF3-B364-2DB01FA2F1A1} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
{8181EB49-62CE-495B-8078-08DCF8C30541} = {F921339B-32F9-4BF3-B364-2DB01FA2F1A1}
{F3B989E5-E7F5-4A07-AEA1-84B63040A190} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
diff --git a/THIRDPARTYNOTICES b/THIRDPARTYNOTICES
index bca649f6cf2..05ae34d280d 100644
--- a/THIRDPARTYNOTICES
+++ b/THIRDPARTYNOTICES
@@ -2395,50 +2395,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***
-
-Portable.BouncyCastle
-
-
-
-
- License
-
-
-The Bouncy Castle Cryptographic C#® API
-License:
-The Bouncy Castle License
-Copyright (c) 2000-2011 The Legion Of The Bouncy Castle
-(http://www.bouncycastle.org)
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"), to deal in the
-Software without restriction, including without limitation the rights to use, copy, modify, merge,
-publish, distribute, sub license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS",
-WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-INCLUDING BUT NOT LIMITED TO THE
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-PURPOSE AND NONINFRINGEMENT. IN NO
-EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-
-
-
-
-***
-
paholg/typenum
The MIT License (MIT)
Copyright (c) 2014 Paho Lurie-Gregg
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AssemblyInfo.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AssemblyInfo.cs
deleted file mode 100644
index 6283060f118..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AssemblyInfo.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-using System.Runtime.CompilerServices;
-
-[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test")]
-[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Agent.Kubernetes.IntegrationTest")]
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AuthConfig.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AuthConfig.cs
deleted file mode 100644
index a6be53ddcd5..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/AuthConfig.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using Microsoft.Azure.Devices.Edge.Util;
-
- public class AuthConfig
- {
- public AuthConfig(string name)
- {
- this.Name = Preconditions.CheckNonWhiteSpace(name, nameof(name));
- }
-
- public string Name { get; }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfig.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfig.cs
deleted file mode 100644
index ce0d3e7864a..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfig.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment;
- using Microsoft.Azure.Devices.Edge.Util;
-
- public class CombinedKubernetesConfig
- {
- public CombinedKubernetesConfig(string image, CreatePodParameters createOptions, Option imagePullSecret)
- {
- this.Image = Preconditions.CheckNonWhiteSpace(image, nameof(image)).Trim();
- this.CreateOptions = Preconditions.CheckNotNull(createOptions, nameof(createOptions));
- this.ImagePullSecret = imagePullSecret;
- }
-
- public string Image { get; }
-
- public CreatePodParameters CreateOptions { get; }
-
- public Option ImagePullSecret { get; }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfigProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfigProvider.cs
deleted file mode 100644
index a8365867a3c..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CombinedKubernetesConfigProvider.cs
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.InteropServices;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Agent.Docker;
- using Microsoft.Azure.Devices.Edge.Agent.Docker.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment;
- using Microsoft.Azure.Devices.Edge.Util;
- using Newtonsoft.Json.Linq;
-
- public class CombinedKubernetesConfigProvider : ICombinedConfigProvider
- {
- const string CmdKey = "Cmd";
- const string EntrypointKey = "Entrypoint";
- const string WorkingDirKey = "WorkingDir";
-
- readonly CombinedDockerConfigProvider dockerConfigProvider;
- readonly Uri workloadUri;
- readonly Uri managementUri;
- readonly bool enableKubernetesExtensions;
-
- public CombinedKubernetesConfigProvider(
- IEnumerable authConfigs,
- Uri workloadUri,
- Uri managementUri,
- bool enableKubernetesExtensions)
- {
- this.dockerConfigProvider = new CombinedDockerConfigProvider(authConfigs);
- this.workloadUri = Preconditions.CheckNotNull(workloadUri, nameof(workloadUri));
- this.managementUri = Preconditions.CheckNotNull(managementUri, nameof(managementUri));
- this.enableKubernetesExtensions = enableKubernetesExtensions;
- }
-
- public CombinedKubernetesConfig GetCombinedConfig(IModule module, IRuntimeInfo runtimeInfo)
- {
- CombinedDockerConfig dockerConfig = this.dockerConfigProvider.GetCombinedConfig(module, runtimeInfo);
-
- // if the workload URI is a Unix domain socket then volume mount it into the container
- HostConfig hostConfig = this.AddSocketBinds(module, Option.Maybe(dockerConfig.CreateOptions.HostConfig));
-
- var otherProperties = Option.Maybe(dockerConfig.CreateOptions.OtherProperties)
- .Map(op => new Dictionary(op, StringComparer.OrdinalIgnoreCase));
-
- CreatePodParameters createOptions = new CreatePodParameters(
- dockerConfig.CreateOptions.Env,
- dockerConfig.CreateOptions.ExposedPorts,
- hostConfig,
- dockerConfig.CreateOptions.Image,
- dockerConfig.CreateOptions.Labels,
- GetPropertiesStringArray(CmdKey, otherProperties),
- GetPropertiesStringArray(EntrypointKey, otherProperties),
- GetPropertiesString(WorkingDirKey, otherProperties));
-
- if (this.enableKubernetesExtensions)
- {
- Option experimentalOptions = KubernetesExperimentalCreatePodParameters.Parse(dockerConfig.CreateOptions.OtherProperties);
- experimentalOptions.ForEach(parameters => createOptions.Volumes = parameters.Volumes);
- experimentalOptions.ForEach(parameters => createOptions.NodeSelector = parameters.NodeSelector);
- experimentalOptions.ForEach(parameters => createOptions.Resources = parameters.Resources);
- experimentalOptions.ForEach(parameters => createOptions.SecurityContext = parameters.SecurityContext);
- experimentalOptions.ForEach(parameters => createOptions.ServiceOptions = parameters.ServiceOptions);
- experimentalOptions.ForEach(parameters => createOptions.DeploymentStrategy = parameters.DeploymentStrategy);
- }
-
- Option imagePullSecret = dockerConfig.AuthConfig
- .Map(auth => new ImagePullSecret(auth));
-
- return new CombinedKubernetesConfig(dockerConfig.Image, createOptions, imagePullSecret);
- }
-
- HostConfig AddSocketBinds(IModule module, Option dockerHostConfig)
- {
- Option hostConfig = dockerHostConfig;
-
- // If Workload URI is Unix domain socket, and the module is the EdgeAgent, then mount it ino the container.
- if (string.Equals(this.workloadUri.Scheme, "unix", StringComparison.OrdinalIgnoreCase))
- {
- string path = BindPath(this.workloadUri);
- hostConfig = hostConfig.Else(() => Option.Some(new HostConfig { Binds = new List() }));
- hostConfig.ForEach(config => config.Binds.Add($"{path}:{path}"));
- }
-
- // If Management URI is Unix domain socket, and the module is the EdgeAgent, then mount it ino the container.
- if (string.Equals(this.managementUri.Scheme, "unix", StringComparison.OrdinalIgnoreCase)
- && module.Name.Equals(Core.Constants.EdgeAgentModuleName, StringComparison.OrdinalIgnoreCase))
- {
- string path = BindPath(this.managementUri);
- hostConfig = hostConfig.Else(() => Option.Some(new HostConfig { Binds = new List() }));
- hostConfig.ForEach(config => config.Binds.Add($"{path}:{path}"));
- }
-
- return hostConfig.OrDefault();
- }
-
- static string BindPath(Uri uri)
- {
- // On Windows we need to bind to the parent folder. We can't bind
- // directly to the socket file.
- return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
- ? Path.GetDirectoryName(uri.LocalPath)
- : uri.AbsolutePath;
- }
-
- static IReadOnlyList GetPropertiesStringArray(string key, Option> other) =>
- other.FlatMap(options => options.Get(key).FlatMap(option => Option.Maybe(option.ToObject>()))).OrDefault();
-
- static string GetPropertiesString(string key, Option> other) =>
- other.FlatMap(options => options.Get(key).FlatMap(option => Option.Maybe(option.ToObject()))).OrDefault();
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/Constants.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/Constants.cs
deleted file mode 100644
index bd1c8a390c0..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/Constants.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment.Service;
-
- public static class Constants
- {
- public static class EdgeDeployment
- {
- public const string ApiVersion = Api + "/" + Version;
-
- public const string Api = "microsoft.azure.devices.edge";
-
- public const string Version = "v1";
-
- public const string Kind = "EdgeDeployment";
-
- public const string Group = "microsoft.azure.devices.edge";
-
- public const string Plural = "edgedeployments";
- }
-
- public const string CreationString = "net.azure-devices.edge.creationstring";
-
- public const string DefaultDeletePropagationPolicy = "Background";
-
- public const PortMapServiceType DefaultPortMapServiceType = PortMapServiceType.ClusterIP;
-
- public const string K8sEdgeModuleLabel = "net.azure-devices.edge.module";
-
- public const string K8sEdgeOriginalModuleId = "net.azure-devices.edge.original-moduleid";
-
- public const string K8sEdgeDeviceLabel = "net.azure-devices.edge.deviceid";
-
- public const string K8sNameDivider = "-";
-
- public const string K8sPullSecretType = "kubernetes.io/dockerconfigjson";
-
- public const string K8sPullSecretData = ".dockerconfigjson";
-
- public const string K8sBackupSecretType = "Opaque";
-
- public const string EdgeAgentBackupName = "edgeagent-backup-config";
-
- public const string PortMappingServiceType = "PortMappingServiceType";
-
- public const string EnableK8sServiceCallTracingName = "EnableK8sServiceCallTracing";
-
- public const string K8sNamespaceKey = "K8sNamespace";
-
- public const string ProxyImageEnvKey = "ProxyImage";
-
- public const string ProxyImagePullSecretNameEnvKey = "ProxyImagePullSecretName";
-
- public const string ProxyConfigPathEnvKey = "ProxyConfigPath";
-
- public const string ProxyConfigVolumeEnvKey = "ProxyConfigVolume";
-
- public const string ProxyConfigMapNameEnvKey = "ProxyConfigMapName";
-
- public const string ProxyTrustBundlePathEnvKey = "ProxyTrustBundlePath";
-
- public const string ProxyTrustBundleVolumeEnvKey = "ProxyTrustBundleVolume";
-
- public const string ProxyTrustBundleConfigMapEnvKey = "ProxyTrustBundleConfigMapName";
-
- public const string UseMountSourceForVolumeNameKey = "UseMountSourceForVolumeName";
-
- public const string StorageClassNameKey = "StorageClassName";
-
- public const string PersistentVolumeClaimDefaultSizeInMbKey = "PersistentVolumeClaimDefaultSizeInMb";
-
- public const string EdgeK8sObjectOwnerApiVersionKey = "EdgeK8sObjectOwnerApiVersion";
-
- public const string EdgeK8sObjectOwnerKindKey = "EdgeK8sObjectOwnerKind";
-
- public const string EdgeK8sObjectOwnerNameKey = "EdgeK8sObjectOwnerName";
-
- public const string EdgeK8sObjectOwnerUidKey = "EdgeK8sObjectOwnerUid";
-
- public const string RunAsNonRootKey = "RunAsNonRoot";
-
- public const string UnknownImage = "unknown";
-
- public const string HostIPC = "host";
- public const string HostNetwork = "host";
- public const string HostNetworkDnsPolicy = "ClusterFirstWithHostNet";
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CreatePodParameters.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CreatePodParameters.cs
deleted file mode 100644
index b1e104b8603..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/CreatePodParameters.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System.Collections.Generic;
- using System.Linq;
- using k8s.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Docker.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment.Service;
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Azure.Devices.Edge.Util.Json;
- using Newtonsoft.Json;
- using EmptyStruct = global::Docker.DotNet.Models.EmptyStruct;
-
- public class CreatePodParameters
- {
- public CreatePodParameters(
- IEnumerable env,
- IDictionary exposedPorts,
- HostConfig hostConfig,
- string image,
- IDictionary labels,
- IEnumerable cmd,
- IEnumerable entrypoint,
- string workingDir)
- : this(env?.ToList(), exposedPorts, hostConfig, image, labels, cmd?.ToList(), entrypoint?.ToList(), workingDir, null, null, null, null, null, null)
- {
- }
-
- [JsonConstructor]
- CreatePodParameters(
- IReadOnlyList env,
- IDictionary exposedPorts,
- HostConfig hostConfig,
- string image,
- IDictionary labels,
- IReadOnlyList cmd,
- IReadOnlyList entrypoint,
- string workingDir,
- IDictionary nodeSelector,
- V1ResourceRequirements resources,
- IReadOnlyList volumes,
- V1PodSecurityContext securityContext,
- KubernetesServiceOptions serviceOptions,
- V1DeploymentStrategy strategy)
- {
- this.Env = Option.Maybe(env);
- this.ExposedPorts = Option.Maybe(exposedPorts);
- this.HostConfig = Option.Maybe(hostConfig);
- this.Image = Option.Maybe(image);
- this.Labels = Option.Maybe(labels);
- this.Cmd = Option.Maybe(cmd);
- this.Entrypoint = Option.Maybe(entrypoint);
- this.WorkingDir = Option.Maybe(workingDir);
- this.NodeSelector = Option.Maybe(nodeSelector);
- this.Resources = Option.Maybe(resources);
- this.Volumes = Option.Maybe(volumes);
- this.SecurityContext = Option.Maybe(securityContext);
- this.ServiceOptions = Option.Maybe(serviceOptions);
- this.DeploymentStrategy = Option.Maybe(strategy);
- }
-
- internal static CreatePodParameters Create(
- IReadOnlyList env = null,
- IDictionary exposedPorts = null,
- HostConfig hostConfig = null,
- string image = null,
- IDictionary labels = null,
- IReadOnlyList cmd = null,
- IReadOnlyList entrypoint = null,
- string workingDir = null,
- IDictionary nodeSelector = null,
- V1ResourceRequirements resources = null,
- IReadOnlyList volumes = null,
- V1PodSecurityContext securityContext = null,
- KubernetesServiceOptions serviceOptions = null,
- V1DeploymentStrategy deploymentStrategy = null)
- => new CreatePodParameters(env, exposedPorts, hostConfig, image, labels, cmd, entrypoint, workingDir, nodeSelector, resources, volumes, securityContext, serviceOptions, deploymentStrategy);
-
- [JsonProperty("env", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> Env { get; }
-
- [JsonProperty("exposedPorts", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> ExposedPorts { get; }
-
- [JsonProperty("hostConfig", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option HostConfig { get; }
-
- [JsonProperty("image", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option Image { get; }
-
- [JsonProperty("labels", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> Labels { get; }
-
- [JsonProperty("nodeSelector", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> NodeSelector { get; set; }
-
- [JsonProperty("resources", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option Resources { get; set; }
-
- [JsonProperty("volumes", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> Volumes { get; set; }
-
- [JsonProperty("securityContext", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option SecurityContext { get; set; }
-
- [JsonProperty("serviceOptions", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option ServiceOptions { get; set; }
-
- [JsonProperty("strategy", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option DeploymentStrategy { get; set; }
-
- [JsonProperty("cmd", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> Cmd { get; }
-
- [JsonProperty("entrypoint", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter>))]
- public Option> Entrypoint { get; }
-
- [JsonProperty("workingDir", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
- [JsonConverter(typeof(OptionConverter))]
- public Option WorkingDir { get; }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/DeploymentSecretBackup.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/DeploymentSecretBackup.cs
deleted file mode 100644
index 6f7abe232eb..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/DeploymentSecretBackup.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Threading.Tasks;
- using k8s;
- using k8s.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Agent.Core.Serde;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment;
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Azure.Devices.Edge.Util.Concurrency;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- using Microsoft.Rest;
-
- public class DeploymentSecretBackup : IDeploymentBackupSource
- {
- const string BackupData = "backup.json";
- readonly string deviceNamespace;
- readonly KubernetesModuleOwner moduleOwner;
- readonly ISerde serde;
- readonly IKubernetes client;
-
- public DeploymentSecretBackup(string secretName, string deviceNamespace, KubernetesModuleOwner moduleOwner, ISerde serde, IKubernetes client)
- {
- this.Name = Preconditions.CheckNonWhiteSpace(secretName, nameof(secretName));
- this.deviceNamespace = Preconditions.CheckNonWhiteSpace(deviceNamespace, nameof(deviceNamespace));
- this.moduleOwner = Preconditions.CheckNotNull(moduleOwner, nameof(moduleOwner));
- this.serde = Preconditions.CheckNotNull(serde, nameof(serde));
- this.client = Preconditions.CheckNotNull(client, nameof(client));
- }
-
- public string Name { get; }
-
- public async Task ReadFromBackupAsync()
- {
- Option config = Option.None();
-
- try
- {
- V1Secret backupSecret = await this.client.ReadNamespacedSecretAsync(this.Name, this.deviceNamespace);
- config = Option.Maybe(backupSecret)
- .FlatMap(
- s =>
- {
- if (s.Data != null && s.Data.TryGetValue(BackupData, out byte[] backupconfig))
- {
- string backupJson = System.Text.Encoding.UTF8.GetString(s.Data[BackupData]);
- DeploymentConfigInfo deploymentConfigInfo = this.serde.Deserialize(backupJson);
- Events.ObtainedDeploymentFromBackup(this.Name);
- return Option.Maybe(deploymentConfigInfo);
- }
-
- return Option.None();
- });
- }
- catch (Exception e)
- {
- Events.GetBackupFailed(e, this.Name);
- }
-
- return config.GetOrElse(DeploymentConfigInfo.Empty);
- }
-
- public async Task BackupDeploymentConfigAsync(DeploymentConfigInfo deploymentConfigInfo)
- {
- try
- {
- // backup the config info only if there isn't an error in it
- if (!deploymentConfigInfo.Exception.HasValue)
- {
- byte[] json = System.Text.Encoding.UTF8.GetBytes(this.serde.Serialize(deploymentConfigInfo));
-
- var secretMeta = new V1ObjectMeta(
- name: this.Name,
- namespaceProperty: this.deviceNamespace,
- ownerReferences: this.moduleOwner.ToOwnerReferences());
- var secretData = new Dictionary { [BackupData] = json };
- var newSecret = new V1Secret("v1", secretData, type: Constants.K8sBackupSecretType, kind: "Secret", metadata: secretMeta);
-
- Option currentSecret;
- try
- {
- currentSecret = Option.Maybe(await this.client.ReadNamespacedSecretAsync(this.Name, this.deviceNamespace));
- }
- catch (HttpOperationException ex) when (!ex.IsFatal())
- {
- currentSecret = Option.None();
- }
-
- var v1Secret = await currentSecret.Match(
- async s =>
- {
- if (s.Data != null && s.Data.TryGetValue(BackupData, out byte[] backupSecretData) &&
- backupSecretData.SequenceEqual(json))
- {
- return s;
- }
-
- return await this.client.ReplaceNamespacedSecretAsync(
- newSecret,
- this.Name,
- this.deviceNamespace);
- },
- async () => await this.client.CreateNamespacedSecretAsync(newSecret, this.deviceNamespace));
- if (v1Secret == null)
- {
- throw new InvalidBackupException("backup secret was not properly created");
- }
- }
- }
- catch (Exception e)
- {
- Events.SetBackupFailed(e, this.Name);
- }
- }
-
- static class Events
- {
- const int IdStart = KubernetesEventIds.SecretBackup;
- static readonly ILogger Log = Logger.Factory.CreateLogger();
-
- enum EventIds
- {
- Created = IdStart,
- SetBackupFailed,
- GetBackupFailed
- }
-
- public static void SetBackupFailed(Exception exception, string secretName)
- {
- Log.LogError((int)EventIds.SetBackupFailed, exception, $"Error backing up edge agent config to secret {secretName}");
- }
-
- public static void GetBackupFailed(Exception exception, string secretName)
- {
- Log.LogError((int)EventIds.GetBackupFailed, exception, $"Failed to read edge agent config from backup secret {secretName}");
- }
-
- public static void ObtainedDeploymentFromBackup(string secretName)
- {
- Log.LogInformation((int)EventIds.Created, $"Obtained edge agent config from backup config secret - {secretName}");
- }
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesEnvironmentOperator.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesEnvironmentOperator.cs
deleted file mode 100644
index 0ffafd45fa3..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesEnvironmentOperator.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- public interface IKubernetesEnvironmentOperator : IKubernetesOperator
- {
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesOperator.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesOperator.cs
deleted file mode 100644
index 366da20b8dc..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IKubernetesOperator.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
-
- public interface IKubernetesOperator : IDisposable
- {
- void Start();
-
- void Stop();
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IRuntimeInfoSource.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IRuntimeInfoSource.cs
deleted file mode 100644
index a5ad6518104..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/IRuntimeInfoSource.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using k8s.Models;
-
- public interface IRuntimeInfoSource
- {
- void CreateOrUpdateAddPodInfo(V1Pod pod);
-
- bool RemovePodInfo(V1Pod pod);
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidBackupException.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidBackupException.cs
deleted file mode 100644
index d133cd28f1c..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidBackupException.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
-
- [Serializable]
- public class InvalidBackupException : Exception
- {
- public InvalidBackupException(string message)
- : base(message)
- {
- }
-
- public InvalidBackupException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidIdentityException.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidIdentityException.cs
deleted file mode 100644
index 3a0a823fe6f..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidIdentityException.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
-
- [Serializable]
- public class InvalidIdentityException : Exception
- {
- public InvalidIdentityException(string message)
- : base(message)
- {
- }
-
- public InvalidIdentityException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidKubernetesName.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidKubernetesName.cs
deleted file mode 100644
index 343a0592502..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidKubernetesName.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
-
- [Serializable]
- public class InvalidKubernetesNameException : Exception
- {
- public InvalidKubernetesNameException(string message)
- : base(message)
- {
- }
-
- public InvalidKubernetesNameException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidModuleException.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidModuleException.cs
deleted file mode 100644
index 26bc23b2faf..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/InvalidModuleException.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
-
- [Serializable]
- public class InvalidModuleException : Exception
- {
- public InvalidModuleException(string message)
- : base(message)
- {
- }
-
- public InvalidModuleException(string message, Exception inner)
- : base(message, inner)
- {
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubeUtils.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubeUtils.cs
deleted file mode 100644
index e1420e59070..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubeUtils.cs
+++ /dev/null
@@ -1,249 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CoreConstants = Microsoft.Azure.Devices.Edge.Agent.Core.Constants;
-
- public static class KubeUtils
- {
- const string Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- const string Numeric = "0123456789";
- const string AllowedCharsLabelValues = "-._";
- const string AllowedCharsDns = "-";
- const string AllowedCharsGeneric = "-.";
- const int MaxK8SValueLength = 253;
- const int MaxDnsNameLength = 63;
- const int MaxLabelValueLength = 63;
- static readonly HashSet AlphaHashSet = new HashSet(Alphabet.ToCharArray());
- static readonly HashSet AlphaNumericHashSet = new HashSet((Alphabet + Numeric).ToCharArray());
- static readonly HashSet AllowedLabelsHashSet = new HashSet((Alphabet + Numeric + AllowedCharsLabelValues).ToCharArray());
- static readonly HashSet AllowedDnsHashSet = new HashSet((Alphabet + Numeric + AllowedCharsDns).ToCharArray());
- static readonly HashSet AllowedGenericHashSet = new HashSet((Alphabet + Numeric + AllowedCharsGeneric).ToCharArray());
-
- static bool IsAlpha(char ch) => AlphaHashSet.Contains(ch);
-
- static bool IsAlphaNumeric(char ch) => AlphaNumericHashSet.Contains(ch);
-
- // Valid annotation keys have two segments: an optional prefix and name, separated by a slash (/).
- // The name segment is required and must be 63 characters or less, beginning and ending with an
- // alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between.
- // The prefix is optional. If specified, the prefix must be a DNS subdomain
- public static string SanitizeAnnotationKey(string key)
- {
- if (string.IsNullOrEmpty(key))
- {
- throw new InvalidKubernetesNameException($"Key '{key}' is null or empty");
- }
-
- char[] annotationSplit = { '/' };
- string[] keySegments = key.Split(annotationSplit, 2);
- string output;
- if (keySegments.Count() == 2)
- {
- output = SanitizeDNSDomain(keySegments[0]) + "/" + SanitizeNameValue(keySegments[1]);
- }
- else
- {
- output = SanitizeNameValue(key);
- }
-
- if (string.IsNullOrEmpty(output))
- {
- throw new InvalidKubernetesNameException($"Key '{key}' as sanitized is empty");
- }
-
- return output;
- }
-
- // Alphanumeric, '-' and '.' up to 253 characters.
- public static string SanitizeK8sValue(string name)
- {
- if (name == null)
- {
- // Values sometimes may be null, and that's OK.
- return name;
- }
-
- name = name.ToLower();
-
- var output = new StringBuilder();
- for (int i = 0; i < name.Length; i++)
- {
- if (AllowedGenericHashSet.Contains(name[i]))
- {
- output.Append(name[i]);
- }
- }
-
- if (output.Length > MaxK8SValueLength)
- {
- throw new InvalidKubernetesNameException($"Value '{name}' as sanitized exceeded maximum length {MaxK8SValueLength}");
- }
-
- return output.ToString();
- }
-
- // DNS label (as per RFC 1035)
- public static string SanitizeDNSValue(string name)
- {
- // The name returned from here must conform to following rules (as per RFC 1035):
- // - length must be <= 63 characters
- // - must be all lower case alphanumeric characters or '-'
- // - must start with an alphabet
- // - must end with an alphanumeric character
- if (string.IsNullOrEmpty(name))
- {
- throw new InvalidKubernetesNameException($"DNS Name '{name}' is null or empty");
- }
-
- name = name.ToLower();
-
- // get index of first character from the left that is an alphabet
- int start = 0;
- while (start < name.Length && !IsAlpha(name[start]))
- {
- start++;
- }
-
- if (start == name.Length)
- {
- throw new InvalidKubernetesNameException($"DNS name '{name}' does not start with a valid character");
- }
-
- // get index of last character from right that's an alphanumeric
- int end = Math.Max(start, name.Length - 1);
- while (end > start && !IsAlphaNumeric(name[end]))
- {
- end--;
- }
-
- // build a new string from start-end (inclusive) excluding characters
- // that aren't alphanumeric or the symbol '-'
- var output = new StringBuilder();
- for (int i = start; i <= end; i++)
- {
- if (AllowedDnsHashSet.Contains(name[i]))
- {
- output.Append(name[i]);
- }
- }
-
- if (output.Length > MaxDnsNameLength)
- {
- throw new InvalidKubernetesNameException($"DNS name '{name}' exceeded maximum length of {MaxDnsNameLength}");
- }
-
- if (output.Length == 0)
- {
- throw new InvalidKubernetesNameException($"DNS name '{name}' as sanitized is empty");
- }
-
- return output.ToString();
- }
-
- // DNS subdomains are DNS labels separated by '.', max 253 characters.
- public static string SanitizeDNSDomain(string name)
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new InvalidKubernetesNameException($"DNS subdomain '{name}' is null or empty");
- }
-
- char[] nameSplit = { '.' };
- string[] dnsSegments = name.Split(nameSplit);
- var output = new StringBuilder();
- bool firstSegment = true;
- foreach (var segment in dnsSegments)
- {
- string sanitized = SanitizeDNSValue(segment);
-
- if (firstSegment)
- {
- output.Append(sanitized);
- firstSegment = false;
- }
- else
- {
- output.Append(".");
- output.Append(sanitized);
- }
- }
-
- if (output.Length > MaxK8SValueLength)
- {
- throw new InvalidKubernetesNameException($"DNS subdomain '{name}' as sanitized exceeded maximum length of {MaxK8SValueLength}");
- }
-
- return output.ToString();
- }
-
- private static string SanitizeNameValue(string name)
- {
- // The name returned from here must conform to following rules:
- // - length must be <= 63 characters
- // - must be all alphanumeric characters or ['-','.','_']
- // - must start with an alphabet
- // - must end with an alphanumeric character
-
- // get index of first character from the left that is an alphabet
- int start = 0;
- while (start < name.Length && !IsAlphaNumeric(name[start]))
- {
- start++;
- }
-
- if (start == name.Length)
- {
- throw new InvalidKubernetesNameException($"Name '{name}' does not start with a valid character");
- }
-
- // get index of last character from right that's an alphanumeric
- int end = Math.Max(start, name.Length - 1);
- while (end > start && !IsAlphaNumeric(name[end]))
- {
- end--;
- }
-
- // build a new string from start-end (inclusive) excluding characters
- // that aren't alphanumeric or the symbol '-'
- var output = new StringBuilder();
- for (int i = start; i <= end; i++)
- {
- if (AllowedLabelsHashSet.Contains(name[i]))
- {
- output.Append(name[i]);
- }
- }
-
- if (output.Length > MaxLabelValueLength)
- {
- throw new InvalidKubernetesNameException($"Name '{name}' exceeded maximum length of {MaxLabelValueLength}");
- }
-
- if (output.Length == 0)
- {
- throw new InvalidKubernetesNameException($"Name '{name}' as sanitized is empty");
- }
-
- return output.ToString();
- }
-
- public static string SanitizeLabelValue(string name)
- {
- // The name returned from here must conform to following rules:
- // - length must be <= 63 characters
- // - must be all lower case alphanumeric characters or ['-','.','_']
- // - must start with an alphabet
- // - must end with an alphanumeric character
- if (string.IsNullOrEmpty(name))
- {
- throw new InvalidKubernetesNameException($"Name '{name}' is null or empty");
- }
-
- return SanitizeNameValue(name.ToLower());
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesApplicationSettings.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesApplicationSettings.cs
deleted file mode 100644
index e3da433f8a4..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesApplicationSettings.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System.Collections.Generic;
- using System.Linq;
- using k8s.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment.Service;
- using Microsoft.Azure.Devices.Edge.Util;
-
- ///
- /// Application settings, derived from "appsetting_k8s.json" and environment
- /// variables, loaded from autofac. These setting are used to allow edgeAgent
- /// to properly construct proxy container settings and for agent to build itself.
- ///
- public class KubernetesApplicationSettings
- {
- // Location of "appsetting_k8s.json" in container
- public string AgentConfigPath { get; set; }
- // Name of configmap containing "appsetting_k8s.json"
- public string AgentConfigMapName { get; set; }
- // Name of volume to use when mounting configmap, used in PodSpec
- public string AgentConfigVolume { get; set; }
- // Proxy Image
- public string ProxyImage { get; set; }
- // Name of volume to use when mounting proxy's configmap
- public string ProxyConfigVolume { get; set; }
- // Name of configmap containing "config.yaml"
- public string ProxyConfigMapName { get; set; }
- // Location of "config.yaml" in proxy container
- public string ProxyConfigPath { get; set; }
- // Location of trustbundle in proxy container
- public string ProxyTrustBundlePath { get; set; }
- // Name of volume to use when mounting trustbundle
- public string ProxyTrustBundleVolume { get; set; }
- // Map of configmap containing trustbundle
- public string ProxyTrustBundleConfigMapName { get; set; }
- // Resource requirements for proxy.
- public ResourceSettings ProxyResourceRequests { get; set; }
- // Resource requirements for agent.
- public ResourceSettings AgentResourceRequests { get; set; }
-
- public Option GetProxyResourceRequirements() =>
- Option.Maybe(this.ProxyResourceRequests).Map(rr => rr.ToResourceRequirements());
- public Option GetAgentResourceRequirements() =>
- Option.Maybe(this.AgentResourceRequests).Map(rr => rr.ToResourceRequirements());
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesCommandFactory.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesCommandFactory.cs
deleted file mode 100644
index 7581309737a..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesCommandFactory.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System.Threading.Tasks;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Agent.Core.Commands;
-
- public class KubernetesCommandFactory : ICommandFactory
- {
- public KubernetesCommandFactory()
- {
- }
-
- public Task UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) => Task.FromResult(NullCommand.Instance as ICommand);
-
- public Task CreateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task RemoveAsync(IModule module) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task StartAsync(IModule module) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task StopAsync(IModule module) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task RestartAsync(IModule module) =>
- Task.FromResult((ICommand)NullCommand.Instance);
-
- public Task WrapAsync(ICommand command) => Task.FromResult(command);
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesConfig.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesConfig.cs
deleted file mode 100644
index 6b17b1970f6..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesConfig.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Azure.Devices.Edge.Util.Json;
- using Newtonsoft.Json;
-
- public class KubernetesConfig
- {
- public KubernetesConfig(string image, CreatePodParameters createOptions, Option authConfig)
- {
- this.Image = Preconditions.CheckNonWhiteSpace(image, nameof(image)).Trim();
- this.CreateOptions = Preconditions.CheckNotNull(createOptions, nameof(createOptions));
- this.AuthConfig = authConfig;
- }
-
- [JsonConstructor]
- KubernetesConfig(string image, CreatePodParameters createOptions, AuthConfig auth)
- : this(image, createOptions, Option.Maybe(auth))
- {
- }
-
- [JsonProperty(Required = Required.Always, PropertyName = "image")]
- public string Image { get; }
-
- [JsonProperty(Required = Required.AllowNull, PropertyName = "createOptions")]
- public CreatePodParameters CreateOptions { get; }
-
- [JsonProperty(Required = Required.AllowNull, PropertyName = "auth")]
- [JsonConverter(typeof(OptionConverter))]
- public Option AuthConfig { get; }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironment.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironment.cs
deleted file mode 100644
index 5fdd9119d47..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironment.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Agent.Docker;
- using Microsoft.Azure.Devices.Edge.Agent.Docker.Models;
- using Microsoft.Azure.Devices.Edge.Storage;
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Extensions.Logging;
-
- ///
- /// This implementation gets the module runtime information from KubernetesRuntimeInfoProvider and
- /// the configuration information from the deploymentConfig.
- /// TODO: This could be made generic (not docker specific) and moved to Core.
- ///
- public class KubernetesEnvironment : IEnvironment
- {
- readonly IRuntimeInfoProvider moduleStatusProvider;
- readonly IEntityStore moduleStateStore;
- readonly string operatingSystemType;
- readonly string architecture;
- readonly string version;
- readonly DeploymentConfig deploymentConfig;
-
- public KubernetesEnvironment(
- IRuntimeInfoProvider moduleStatusProvider,
- DeploymentConfig deploymentConfig,
- IEntityStore moduleStateStore,
- string operatingSystemType,
- string architecture,
- string version)
- {
- this.moduleStatusProvider = moduleStatusProvider;
- this.deploymentConfig = deploymentConfig;
- this.moduleStateStore = moduleStateStore;
- this.operatingSystemType = operatingSystemType;
- this.architecture = architecture;
- this.version = version;
- }
-
- public async Task GetModulesAsync(CancellationToken token)
- {
- IEnumerable moduleStatuses = await this.moduleStatusProvider.GetModules(token);
- var modules = new List();
- ModuleSet moduleSet = this.deploymentConfig.GetModuleSet();
-
- foreach (ModuleRuntimeInfo moduleRuntimeInfo in moduleStatuses)
- {
- if (moduleRuntimeInfo.Type != "docker" || !(moduleRuntimeInfo is ModuleRuntimeInfo dockerRuntimeInfo))
- {
- Events.InvalidModuleType(moduleRuntimeInfo);
- continue;
- }
-
- if (!moduleSet.Modules.TryGetValue(dockerRuntimeInfo.Name, out IModule configModule) || !(configModule is DockerModule dockerModule))
- {
- dockerModule = new DockerModule(dockerRuntimeInfo.Name, string.Empty, ModuleStatus.Unknown, Core.RestartPolicy.Unknown, new DockerConfig(Constants.UnknownImage, new CreateContainerParameters(), Option.None()), ImagePullPolicy.OnCreate, Core.Constants.HighestPriority, new ConfigurationInfo(), null);
- }
-
- Option moduleStateOption = await this.moduleStateStore.Get(moduleRuntimeInfo.Name);
- ModuleState moduleState = moduleStateOption.GetOrElse(new ModuleState(0, moduleRuntimeInfo.ExitTime.GetOrElse(DateTime.MinValue)));
-
- string image = !string.IsNullOrWhiteSpace(dockerRuntimeInfo.Config.Image) ? dockerRuntimeInfo.Config.Image : dockerModule.Config.Image;
- var dockerReportedConfig = new DockerReportedConfig(image, dockerModule.Config.CreateOptions, dockerRuntimeInfo.Config.ImageHash, dockerModule.Config.NotaryContentTrust);
- IModule module;
- switch (moduleRuntimeInfo.Name)
- {
- case Core.Constants.EdgeHubModuleName:
- module = new EdgeHubDockerRuntimeModule(
- dockerModule.DesiredStatus,
- dockerModule.RestartPolicy,
- dockerReportedConfig,
- (int)dockerRuntimeInfo.ExitCode,
- moduleRuntimeInfo.Description,
- moduleRuntimeInfo.StartTime.GetOrElse(DateTime.MinValue),
- moduleRuntimeInfo.ExitTime.GetOrElse(DateTime.MinValue),
- moduleState.RestartCount,
- moduleState.LastRestartTimeUtc,
- moduleRuntimeInfo.ModuleStatus,
- dockerModule.ImagePullPolicy,
- dockerModule.StartupOrder,
- dockerModule.ConfigurationInfo,
- dockerModule.Env);
- break;
-
- case Core.Constants.EdgeAgentModuleName:
- module = new EdgeAgentDockerRuntimeModule(
- dockerReportedConfig,
- moduleRuntimeInfo.ModuleStatus,
- (int)dockerRuntimeInfo.ExitCode,
- moduleRuntimeInfo.Description,
- moduleRuntimeInfo.StartTime.GetOrElse(DateTime.MinValue),
- moduleRuntimeInfo.ExitTime.GetOrElse(DateTime.MinValue),
- dockerModule.ImagePullPolicy,
- dockerModule.ConfigurationInfo,
- dockerModule.Env);
- break;
-
- default:
- module = new DockerRuntimeModule(
- moduleRuntimeInfo.Name,
- dockerModule.Version,
- dockerModule.DesiredStatus,
- dockerModule.RestartPolicy,
- dockerReportedConfig,
- (int)dockerRuntimeInfo.ExitCode,
- moduleRuntimeInfo.Description,
- moduleRuntimeInfo.StartTime.GetOrElse(DateTime.MinValue),
- moduleRuntimeInfo.ExitTime.GetOrElse(DateTime.MinValue),
- moduleState.RestartCount,
- moduleState.LastRestartTimeUtc,
- moduleRuntimeInfo.ModuleStatus,
- dockerModule.ImagePullPolicy,
- dockerModule.StartupOrder,
- dockerModule.ConfigurationInfo,
- dockerModule.Env);
- break;
- }
-
- modules.Add(module);
- }
-
- return ModuleSet.Create(modules.ToArray());
- }
-
- public Task GetRuntimeInfoAsync()
- {
- IRuntimeInfo runtimeInfo = this.deploymentConfig.Runtime;
- if (runtimeInfo?.Type == "docker")
- {
- var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture, this.version);
- DockerRuntimeConfig config = (runtimeInfo as DockerRuntimeInfo)?.Config;
- runtimeInfo = new DockerReportedRuntimeInfo(runtimeInfo.Type, config, platform);
- }
- else if (runtimeInfo == null || runtimeInfo is UnknownRuntimeInfo)
- {
- var platform = new DockerPlatformInfo(this.operatingSystemType, this.architecture, this.version);
- runtimeInfo = new DockerReportedUnknownRuntimeInfo(platform);
- }
-
- return Task.FromResult(runtimeInfo);
- }
-
- static class Events
- {
- const int IdStart = AgentEventIds.DockerEnvironment;
- static readonly ILogger Log = Logger.Factory.CreateLogger();
-
- enum EventIds
- {
- InvalidModuleType = IdStart
- }
-
- public static void InvalidModuleType(ModuleRuntimeInfo moduleRuntimeInfo)
- {
- Log.LogWarning((int)EventIds.InvalidModuleType, $"Module {moduleRuntimeInfo.Name} has an invalid module type '{moduleRuntimeInfo.Type}'. Expected type 'docker'");
- }
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentOperator.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentOperator.cs
deleted file mode 100644
index 5be86affc35..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentOperator.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Threading.Tasks;
- using k8s;
- using k8s.Models;
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Extensions.Logging;
- using Microsoft.Rest;
-
- public class KubernetesEnvironmentOperator : IKubernetesEnvironmentOperator
- {
- readonly IRuntimeInfoSource moduleStatusSource;
- readonly IKubernetes client;
- readonly string deviceNamespace;
- Option> podWatch;
-
- public KubernetesEnvironmentOperator(
- string deviceNamespace,
- IRuntimeInfoSource moduleStatusSource,
- IKubernetes client)
- {
- this.deviceNamespace = deviceNamespace;
- this.moduleStatusSource = moduleStatusSource;
- this.client = Preconditions.CheckNotNull(client, nameof(client));
- this.podWatch = Option.None>();
- }
-
- public void Start() => this.StartListPods();
-
- public void Stop()
- {
- // TODO do we need lock here?
- this.podWatch.ForEach(watch => watch.Dispose());
- }
-
- public void Dispose() => this.Stop();
-
- void StartListPods() =>
- this.client.ListNamespacedPodWithHttpMessagesAsync(this.deviceNamespace, watch: true)
- .ContinueWith(this.OnListPodsCompleted);
-
- async Task OnListPodsCompleted(Task> task)
- {
- HttpOperationResponse podListResp = await task;
-
- this.podWatch = Option.Some(
- podListResp.Watch(
- onEvent: (type, item) =>
- {
- try
- {
- this.HandlePodChangedAsync(type, item);
- }
- catch (Exception ex) when (!ex.IsFatal())
- {
- Events.PodWatchFailed(ex);
- }
- },
- onClosed: () =>
- {
- Events.PodWatchClosed();
-
- // get rid of the current pod watch object since we got closed
- this.podWatch.ForEach(watch => watch.Dispose());
- this.podWatch = Option.None>();
-
- // kick off a new watch
- this.StartListPods();
- },
- onError: (ex) =>
- {
- Events.PodWatchFailed(ex);
- throw ex;
- }));
- }
-
- void HandlePodChangedAsync(WatchEventType type, V1Pod pod)
- {
- // if the pod doesn't have the module label set then we are not interested in it
- if (!pod.Metadata.Labels.ContainsKey(Constants.K8sEdgeModuleLabel))
- {
- return;
- }
-
- Events.PodStatus(type, pod);
- switch (type)
- {
- case WatchEventType.Added:
- case WatchEventType.Modified:
- case WatchEventType.Error:
- this.moduleStatusSource.CreateOrUpdateAddPodInfo(pod);
- break;
-
- case WatchEventType.Deleted:
- if (!this.moduleStatusSource.RemovePodInfo(pod))
- {
- Events.PodStatusRemoveError(pod);
- }
-
- break;
-
- default:
- throw new ArgumentOutOfRangeException(nameof(type), type, null);
- }
- }
- }
-
- static class Events
- {
- const int IdStart = KubernetesEventIds.KubernetesEnvironmentOperator;
- static readonly ILogger Log = Logger.Factory.CreateLogger();
-
- enum EventIds
- {
- WatchFailed = IdStart,
- PodStatus,
- PodStatusRemoveError,
- WatchClosed
- }
-
- public static void PodWatchFailed(Exception ex)
- {
- Log.LogError((int)EventIds.WatchFailed, ex, "Exception caught in Pod Watch task.");
- }
-
- public static void PodStatus(WatchEventType type, V1Pod pod)
- {
- Log.LogDebug((int)EventIds.PodStatus, $"Pod '{pod.Metadata.Name}', status'{type}'");
- }
-
- public static void PodStatusRemoveError(V1Pod pod)
- {
- Log.LogWarning((int)EventIds.PodStatusRemoveError, $"Notified of pod {pod.Metadata.Name} deleted, but not removed from our pod list");
- }
-
- public static void PodWatchClosed()
- {
- Log.LogInformation((int)EventIds.WatchClosed, $"K8s closed the pod watch. Attempting to reopen watch.");
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentProvider.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentProvider.cs
deleted file mode 100644
index 2baa2cddbb0..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEnvironmentProvider.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Storage;
- using Microsoft.Azure.Devices.Edge.Util;
-
- public class KubernetesEnvironmentProvider : IEnvironmentProvider
- {
- readonly IRuntimeInfoProvider moduleStatusProvider;
- readonly IEntityStore store;
- readonly string operatingSystemType;
- readonly string architecture;
- readonly string version;
-
- KubernetesEnvironmentProvider(
- IRuntimeInfoProvider runtimeInfoProvider,
- IEntityStore store,
- string operatingSystemType,
- string architecture,
- string version)
- {
- this.moduleStatusProvider = runtimeInfoProvider;
- this.store = Preconditions.CheckNotNull(store, nameof(store));
- this.operatingSystemType = operatingSystemType;
- this.architecture = architecture;
- this.version = version;
- }
-
- public static async Task CreateAsync(
- IRuntimeInfoProvider runtimeInfoProvider,
- IEntityStore store,
- CancellationToken token)
- {
- SystemInfo systemInfo = await Preconditions.CheckNotNull(runtimeInfoProvider, nameof(runtimeInfoProvider)).GetSystemInfo(token);
- return new KubernetesEnvironmentProvider(
- runtimeInfoProvider,
- store,
- systemInfo.OperatingSystemType,
- systemInfo.Architecture,
- systemInfo.Version);
- }
-
- public IEnvironment Create(DeploymentConfig deploymentConfig) =>
- new KubernetesEnvironment(
- this.moduleStatusProvider,
- deploymentConfig,
- this.store,
- this.operatingSystemType,
- this.architecture,
- this.version);
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEventIds.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEventIds.cs
deleted file mode 100644
index 19fe22fc68a..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesEventIds.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- public struct KubernetesEventIds
- {
- public const int KubernetesPlanner = EventIdStart + 100;
- public const int KubernetesCommand = EventIdStart + 200;
- public const int EdgeDeploymentOperator = EventIdStart + 300;
- public const int EdgeDeploymentController = EventIdStart + 400;
- public const int KubernetesEnvironmentOperator = EventIdStart + 500;
- public const int KubernetesExperimentalCreateOptions = EventIdStart + 600;
- public const int KubernetesModelValidation = EventIdStart + 700;
- public const int KubernetesProxyHealthProbe = EventIdStart + 800;
- public const int SecretBackup = EventIdStart + 900;
- const int EventIdStart = 200000;
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesExperimentalCreatePodParameters.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesExperimentalCreatePodParameters.cs
deleted file mode 100644
index c0b0655db61..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesExperimentalCreatePodParameters.cs
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System;
- using System.Collections.Generic;
- using k8s.Models;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment;
- using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.EdgeDeployment.Service;
- using Microsoft.Azure.Devices.Edge.Util;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json.Linq;
-
- public class KubernetesExperimentalCreatePodParameters
- {
- public Option> NodeSelector { get; }
-
- public Option Resources { get; }
-
- public Option> Volumes { get; }
-
- public Option SecurityContext { get; }
-
- public Option ServiceOptions { get; }
-
- public Option DeploymentStrategy { get; }
-
- KubernetesExperimentalCreatePodParameters(
- Option> nodeSelector,
- Option resources,
- Option> volumes,
- Option securityContext,
- Option serviceOptions,
- Option deploymentStrategy)
- {
- this.NodeSelector = nodeSelector;
- this.Resources = resources;
- this.Volumes = volumes;
- this.SecurityContext = securityContext;
- this.ServiceOptions = serviceOptions;
- this.DeploymentStrategy = deploymentStrategy;
- }
-
- static class ExperimentalParameterNames
- {
- public const string Section = "k8s-experimental";
- public const string NodeSelector = "NodeSelector";
- public const string Resources = "Resources";
- public const string Volumes = "Volumes";
- public const string SecurityContext = "SecurityContext";
- public const string ServiceOptions = "ServiceOptions";
- public const string DeploymentStrategy = "Strategy";
- }
-
- public static Option Parse(IDictionary other)
- => Option.Maybe(other).FlatMap(options => options.Get(ExperimentalParameterNames.Section).FlatMap(ParseParameters));
-
- static Option ParseParameters(JToken experimental)
- => Option.Maybe(experimental as JObject)
- .Map(ParseParameters)
- .Else(
- () =>
- {
- Events.UnableToParseExperimentalOptions(experimental);
- return Option.None();
- });
-
- static KubernetesExperimentalCreatePodParameters ParseParameters(JObject experimental)
- {
- Dictionary options = PrepareSupportedOptionsStore(experimental);
-
- Option> nodeSelector = options.Get(ExperimentalParameterNames.NodeSelector)
- .FlatMap(option => Option.Maybe(option.ToObject>()));
-
- var resources = options.Get(ExperimentalParameterNames.Resources)
- .FlatMap(option => Option.Maybe(option.ToObject()));
-
- var volumes = options.Get(ExperimentalParameterNames.Volumes)
- .FlatMap(option => Option.Maybe(option.ToObject>()));
-
- var securityContext = options.Get(ExperimentalParameterNames.SecurityContext)
- .FlatMap(option => Option.Maybe(option.ToObject()));
-
- var serviceOptions = options.Get(ExperimentalParameterNames.ServiceOptions)
- .FlatMap(option => Option.Maybe(option.ToObject()));
-
- var deploymentStrategy = options.Get(ExperimentalParameterNames.DeploymentStrategy)
- .FlatMap(option => Option.Maybe(option.ToObject()));
-
- return new KubernetesExperimentalCreatePodParameters(nodeSelector, resources, volumes, securityContext, serviceOptions, deploymentStrategy);
- }
-
- static Dictionary PrepareSupportedOptionsStore(JObject experimental)
- {
- var options = new Dictionary(StringComparer.OrdinalIgnoreCase);
- foreach (var property in experimental.Properties())
- {
- if (!KnownExperimentalOptions.Contains(property.Name))
- {
- Events.UnknownExperimentalOption(property.Name);
- continue;
- }
-
- options[property.Name] = property.Value;
- }
-
- return options;
- }
-
- static readonly HashSet KnownExperimentalOptions = new HashSet(StringComparer.OrdinalIgnoreCase)
- {
- ExperimentalParameterNames.NodeSelector,
- ExperimentalParameterNames.Resources,
- ExperimentalParameterNames.Volumes,
- ExperimentalParameterNames.SecurityContext,
- ExperimentalParameterNames.ServiceOptions,
- ExperimentalParameterNames.DeploymentStrategy
- };
-
- static class Events
- {
- const int IdStart = KubernetesEventIds.KubernetesExperimentalCreateOptions;
- static readonly ILogger Log = Logger.Factory.CreateLogger();
-
- enum EventIds
- {
- UnknownExperimentalOption = IdStart
- }
-
- public static void UnknownExperimentalOption(string name)
- {
- Log.LogWarning((int)EventIds.UnknownExperimentalOption, $"Unknown Kubernetes CreateOption {name}.");
- }
-
- public static void UnableToParseExperimentalOptions(JToken experimental)
- {
- Log.LogWarning((int)EventIds.UnknownExperimentalOption, $"Unable to parse Kubernetes CreateOptions. Expected JObject but: {experimental.Type} found: {experimental}");
- }
- }
- }
-}
diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesModule.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesModule.cs
deleted file mode 100644
index 24dd45b010c..00000000000
--- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Kubernetes/KubernetesModule.cs
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes
-{
- using System.Collections.Generic;
- using System.Collections.Immutable;
- using Microsoft.Azure.Devices.Edge.Agent.Core;
- using Microsoft.Azure.Devices.Edge.Agent.Docker.Models;
- using Microsoft.Azure.Devices.Edge.Util;
- using Newtonsoft.Json;
-
- public class KubernetesModule : IModule
- {
- static readonly DictionaryComparer EnvDictionaryComparer = new DictionaryComparer();
-
- static readonly CombinedKubernetesConfigEqualityComparer ConfigComparer = new CombinedKubernetesConfigEqualityComparer();
-
- public KubernetesModule(IModule module, KubernetesConfig config, KubernetesModuleOwner owner)
- {
- this.Name = module.Name;
- this.Version = module.Version;
- this.Type = module.Type;
- this.DesiredStatus = module.DesiredStatus;
- this.RestartPolicy = module.RestartPolicy;
- this.ConfigurationInfo = module.ConfigurationInfo ?? new ConfigurationInfo(string.Empty);
- this.Env = module.Env?.ToImmutableDictionary() ?? ImmutableDictionary.Empty;
- this.ImagePullPolicy = module.ImagePullPolicy;
- this.StartupOrder = Core.Constants.DefaultStartupOrder;
- this.Config = config;
- this.Owner = owner;
- }
-
- [JsonConstructor]
- public KubernetesModule(
- string name,
- string version,
- string type,
- ModuleStatus status,
- Core.RestartPolicy restartPolicy,
- ConfigurationInfo configurationInfo,
- IDictionary env,
- KubernetesConfig settings,
- ImagePullPolicy imagePullPolicy,
- KubernetesModuleOwner owner)
- {
- this.Name = name;
- this.Version = version;
- this.Type = type;
- this.DesiredStatus = status;
- this.RestartPolicy = restartPolicy;
- this.ConfigurationInfo = configurationInfo ?? new ConfigurationInfo(string.Empty);
- this.Env = env?.ToImmutableDictionary() ?? ImmutableDictionary.Empty;
- this.Config = settings;
- this.ImagePullPolicy = imagePullPolicy;
- this.StartupOrder = Core.Constants.DefaultStartupOrder;
- this.Owner = owner;
- }
-
- [JsonProperty(PropertyName = "name")]
- public string Name { get; set; }
-
- [JsonProperty(PropertyName = "version")]
- public string Version { get; }
-
- [JsonProperty(PropertyName = "type")]
- public string Type { get; }
-
- [JsonProperty(PropertyName = "status")]
- public ModuleStatus DesiredStatus { get; }
-
- [JsonProperty(PropertyName = "restartPolicy")]
- public Core.RestartPolicy RestartPolicy { get; }
-
- [JsonProperty(PropertyName = "imagePullPolicy")]
- public ImagePullPolicy ImagePullPolicy { get; }
-
- [JsonIgnore]
- public uint StartupOrder { get; }
-
- [JsonIgnore]
- public ConfigurationInfo ConfigurationInfo { get; }
-
- [JsonProperty(PropertyName = "env")]
- public IDictionary Env { get; }
-
- [JsonProperty(PropertyName = "settings")]
- [JsonConverter(typeof(ObjectToStringConverter))]
- public KubernetesConfig Config { get; }
-
- [JsonProperty(PropertyName = "owner")]
- public KubernetesModuleOwner Owner { get; }
-
- public virtual bool Equals(IModule other) => this.Equals(other as KubernetesModule);
-
- public bool Equals(IModule other) => this.Equals(other as KubernetesModule);
-
- public static string PvcName(KubernetesModule module, Mount mount)
- {
- return KubeUtils.SanitizeK8sValue($"{module.Name}-{mount.Source}");
- }
-
- public bool Equals(KubernetesModule other)
- {
- if (ReferenceEquals(null, other))
- {
- return false;
- }
-
- if (ReferenceEquals(this, other))
- {
- return true;
- }
-
- return string.Equals(this.Name, other.Name) &&
- string.Equals(this.Version, other.Version) &&
- string.Equals(this.Type, other.Type) &&
- this.DesiredStatus == other.DesiredStatus &&
- ConfigComparer.Equals(this.Config, other.Config) &&
- this.RestartPolicy == other.RestartPolicy &&
- this.ImagePullPolicy == other.ImagePullPolicy &&
- this.StartupOrder == other.StartupOrder &&
- EnvDictionaryComparer.Equals(this.Env, other.Env);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- // We are ignoring this here because, we only change the name of the module on Creation. This
- // is needed because the name is not part of the body of Json equivalent to IModule, it is on the key of the json.
- // ReSharper disable NonReadonlyMemberInGetHashCode
- int hashCode = this.Name != null ? this.Name.GetHashCode() : 0;
- // ReSharper restore NonReadonlyMemberInGetHashCode
- hashCode = (hashCode * 397) ^ (this.Version != null ? this.Version.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ (this.Type != null ? this.Type.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ (int)this.DesiredStatus;
- hashCode = (hashCode * 397) ^ (this.Config != null ? this.Config.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ this.RestartPolicy.GetHashCode();
- hashCode = (hashCode * 397) ^ this.ImagePullPolicy.GetHashCode();
- hashCode = (hashCode * 397) ^ this.StartupOrder.GetHashCode();
- hashCode = (hashCode * 397) ^ EnvDictionaryComparer.GetHashCode(this.Env);
- return hashCode;
- }
- }
-
- public bool IsOnlyModuleStatusChanged(IModule other)
- {
- return other is KubernetesModule &&
- string.Equals(this.Name, other.Name) &&
- string.Equals(this.Version, other.Version) &&
- string.Equals(this.Type, other.Type) &&
- this.DesiredStatus != other.DesiredStatus &&
- ConfigComparer.Equals(this.Config, (other as KubernetesModule).Config) &&
- this.RestartPolicy == other.RestartPolicy &&
- this.ImagePullPolicy == other.ImagePullPolicy &&
- this.StartupOrder == other.StartupOrder &&
- EnvDictionaryComparer.Equals(this.Env, other.Env);
- }
-
- internal class CombinedKubernetesConfigEqualityComparer : IEqualityComparer
- {
- static readonly AuthConfigEqualityComparer AuthConfigComparer = new AuthConfigEqualityComparer();
-
- public bool Equals(KubernetesConfig a, KubernetesConfig b)
- {
- if ((ReferenceEquals(null, a) && !ReferenceEquals(null, b)) ||
- (!ReferenceEquals(null, a) && ReferenceEquals(null, b)))
- {
- return false;
- }
-
- if (ReferenceEquals(a, b))
- {
- return true;
- }
-
- string thisOptions = JsonConvert.SerializeObject(a.CreateOptions);
- string otherOptions = JsonConvert.SerializeObject(b.CreateOptions);
-
- return string.Equals(a.Image, b.Image)
- && AuthConfigComparer.Equals(a.AuthConfig, b.AuthConfig)
- && string.Equals(thisOptions, otherOptions);
- }
-
- public int GetHashCode(KubernetesConfig obj) => obj.GetHashCode();
-
- internal class AuthConfigEqualityComparer : IEqualityComparer