Beispiel #1
0
 public Agent(
     IConfigSource configSource,
     IEnvironmentProvider environmentProvider,
     IPlanner planner,
     IPlanRunner planRunner,
     IReporter reporter,
     IModuleIdentityLifecycleManager moduleIdentityLifecycleManager,
     IEntityStore <string, string> configStore,
     DeploymentConfigInfo initialDeployedConfigInfo,
     ISerde <DeploymentConfigInfo> deploymentConfigInfoSerde,
     IEncryptionProvider encryptionProvider,
     IAvailabilityMetric availabilityMetric)
 {
     this.configSource = Preconditions.CheckNotNull(configSource, nameof(configSource));
     this.planner      = Preconditions.CheckNotNull(planner, nameof(planner));
     this.planRunner   = Preconditions.CheckNotNull(planRunner, nameof(planRunner));
     this.reporter     = Preconditions.CheckNotNull(reporter, nameof(reporter));
     this.moduleIdentityLifecycleManager = Preconditions.CheckNotNull(moduleIdentityLifecycleManager, nameof(moduleIdentityLifecycleManager));
     this.configStore               = Preconditions.CheckNotNull(configStore, nameof(configStore));
     this.environmentProvider       = Preconditions.CheckNotNull(environmentProvider, nameof(environmentProvider));
     this.currentConfig             = Preconditions.CheckNotNull(initialDeployedConfigInfo);
     this.deploymentConfigInfoSerde = Preconditions.CheckNotNull(deploymentConfigInfoSerde, nameof(deploymentConfigInfoSerde));
     this.environment               = this.environmentProvider.Create(this.currentConfig.DeploymentConfig);
     this.encryptionProvider        = Preconditions.CheckNotNull(encryptionProvider, nameof(encryptionProvider));
     this.availabilityMetric        = Preconditions.CheckNotNull(availabilityMetric, nameof(availabilityMetric));
     this.status = DeploymentStatus.Unknown;
     Events.AgentCreated();
 }
Beispiel #2
0
        public static async Task <Agent> Create(IConfigSource configSource, IPlanner planner, IPlanRunner planRunner, IReporter reporter,
                                                IModuleIdentityLifecycleManager moduleIdentityLifecycleManager, IEnvironmentProvider environmentProvider,
                                                IEntityStore <string, string> configStore, ISerde <DeploymentConfigInfo> deploymentConfigInfoSerde, IEncryptionProvider encryptionProvider)
        {
            Preconditions.CheckNotNull(deploymentConfigInfoSerde, nameof(deploymentConfigInfoSerde));
            Preconditions.CheckNotNull(configStore, nameof(configStore));

            Option <DeploymentConfigInfo> deploymentConfigInfo = Option.None <DeploymentConfigInfo>();

            try
            {
                Option <string> deploymentConfigInfoJson = await Preconditions.CheckNotNull(configStore, nameof(configStore)).Get(StoreConfigKey);

                await deploymentConfigInfoJson.ForEachAsync(async json =>
                {
                    string decryptedJson = await encryptionProvider.DecryptAsync(json);
                    deploymentConfigInfo = Option.Some(deploymentConfigInfoSerde.Deserialize(decryptedJson));
                });
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                Events.ErrorDeserializingConfig(ex);
            }
            var agent = new Agent(configSource, environmentProvider, planner, planRunner, reporter, moduleIdentityLifecycleManager,
                                  configStore, deploymentConfigInfo.GetOrElse(DeploymentConfigInfo.Empty), deploymentConfigInfoSerde, encryptionProvider);

            return(agent);
        }
Beispiel #3
0
        public CrdWatchOperator(
            string iotHubHostname,
            string deviceId,
            string edgeHostname,
            string proxyImage,
            string proxyConfigPath,
            string proxyConfigVolumeName,
            string serviceAccountName,
            string k8sNamespace,
            string workloadApiVersion,
            Uri workloadUri,
            Uri managementUri,
            PortMapServiceType defaultMapServiceType,
            IKubernetes client,
            IModuleIdentityLifecycleManager moduleIdentityLifecycleManager)
        {
            this.iotHubHostname        = Preconditions.CheckNonWhiteSpace(iotHubHostname, nameof(iotHubHostname));
            this.deviceId              = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId));
            this.edgeHostname          = Preconditions.CheckNonWhiteSpace(edgeHostname, nameof(edgeHostname));
            this.proxyImage            = Preconditions.CheckNonWhiteSpace(proxyImage, nameof(proxyImage));
            this.proxyConfigPath       = Preconditions.CheckNonWhiteSpace(proxyConfigPath, nameof(proxyConfigPath));
            this.proxyConfigVolumeName = Preconditions.CheckNonWhiteSpace(proxyConfigVolumeName, nameof(proxyConfigVolumeName));
            this.serviceAccountName    = Preconditions.CheckNonWhiteSpace(serviceAccountName, nameof(serviceAccountName));
            this.k8sNamespace          = Preconditions.CheckNonWhiteSpace(k8sNamespace, nameof(k8sNamespace));
            this.workloadApiVersion    = Preconditions.CheckNonWhiteSpace(workloadApiVersion, nameof(workloadApiVersion));
            this.workloadUri           = Preconditions.CheckNotNull(workloadUri, nameof(workloadUri));
            this.managementUri         = Preconditions.CheckNotNull(managementUri, nameof(managementUri));
            this.defaultMapServiceType = Preconditions.CheckNotNull(defaultMapServiceType, nameof(defaultMapServiceType)).ToString();
            this.client             = Preconditions.CheckNotNull(client, nameof(client));
            this.podWatch           = Option.None <Watcher <V1Pod> >();
            this.resourceName       = KubeUtils.SanitizeK8sValue(this.iotHubHostname) + Constants.K8sNameDivider + KubeUtils.SanitizeK8sValue(this.deviceId);
            this.deploymentSelector = Constants.K8sEdgeDeviceLabel + " = " + KubeUtils.SanitizeK8sValue(this.deviceId) + "," + Constants.K8sEdgeHubNameLabel + "=" + KubeUtils.SanitizeK8sValue(this.iotHubHostname);
            var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> >
            {
                [typeof(IModule)] = new Dictionary <string, Type>
                {
                    ["docker"] = typeof(CombinedDockerModule)
                }
            };

            this.deploymentSerde = new TypeSpecificSerDe <EdgeDeploymentDefinition <TConfig> >(deserializerTypesMap, new CamelCasePropertyNamesContractResolver());

            this.moduleIdentityLifecycleManager = moduleIdentityLifecycleManager;
        }
 public EdgeDeploymentController(
     ResourceName resourceName,
     string deploymentSelector,
     string deviceNamespace,
     IKubernetes client,
     IModuleIdentityLifecycleManager moduleIdentityLifecycleManager,
     IKubernetesServiceMapper serviceMapper,
     IKubernetesDeploymentMapper deploymentMapper,
     IKubernetesServiceAccountMapper serviceAccountMapper)
 {
     this.resourceName                   = resourceName;
     this.deploymentSelector             = deploymentSelector;
     this.deviceNamespace                = deviceNamespace;
     this.moduleIdentityLifecycleManager = moduleIdentityLifecycleManager;
     this.client               = client;
     this.serviceMapper        = serviceMapper;
     this.deploymentMapper     = deploymentMapper;
     this.serviceAccountMapper = serviceAccountMapper;
 }
Beispiel #5
0
 public CrdWatcher(
     string iotHubHostname,
     string deviceId,
     string edgeHostname,
     string proxyImage,
     string proxyConfigPath,
     string proxyConfigVolumeName,
     string serviceAccountName,
     string resourceName,
     string deploymentSelector,
     string defaultMapServiceType,
     string k8sNamespace,
     string workloadApiVersion,
     Uri workloadUri,
     Uri managementUri,
     TypeSpecificSerDe <EdgeDeploymentDefinition <TConfig> > deploymentSerde,
     IModuleIdentityLifecycleManager moduleIdentityLifecycleManager,
     IKubernetes client)
 {
     this.iotHubHostname                 = iotHubHostname;
     this.deviceId                       = deviceId;
     this.edgeHostname                   = edgeHostname;
     this.proxyImage                     = proxyImage;
     this.proxyConfigPath                = proxyConfigPath;
     this.proxyConfigVolumeName          = proxyConfigVolumeName;
     this.serviceAccountName             = serviceAccountName;
     this.resourceName                   = resourceName;
     this.deploymentSelector             = deploymentSelector;
     this.defaultMapServiceType          = defaultMapServiceType;
     this.k8sNamespace                   = k8sNamespace;
     this.workloadApiVersion             = workloadApiVersion;
     this.workloadUri                    = workloadUri;
     this.managementUri                  = managementUri;
     this.deploymentSerde                = deploymentSerde;
     this.moduleIdentityLifecycleManager = moduleIdentityLifecycleManager;
     this.client = client;
 }
Beispiel #6
0
        private EdgeDeploymentController CreateDeploymentController(string deviceSelector, IModuleIdentityLifecycleManager moduleLifeCycleManager, string storageClassName)
        {
            var    resourceName             = new ResourceName("hostname", "deviceid");
            var    kubernetesServiceMapper  = new KubernetesServiceMapper(PortMapServiceType.ClusterIP);
            string proxyImagePullSecretName = null;
            IDictionary <string, bool> experimentalFeatures = null;
            var deploymentMapper = new KubernetesDeploymentMapper(
                this.client.DeviceNamespace,
                "edgehub",
                "proxy",
                Option.Maybe(proxyImagePullSecretName),
                "configPath",
                "config-volume",
                "configMapName",
                "trustBundlePath",
                "trust-bundle-volume",
                "trustBundleConfigMapName",
                PortMapServiceType.ClusterIP,
                true,
                storageClassName,
                Option.Some <uint>(100),
                "apiVersion",
                new Uri("http://localhost:35001"),
                new Uri("http://localhost:35000"),
                false,
                false,
                experimentalFeatures == null ? new Dictionary <string, bool>() : experimentalFeatures);
            var pvcMapper            = new KubernetesPvcMapper(true, storageClassName, 100);
            var serviceAccountMapper = new KubernetesServiceAccountMapper();

            return(new EdgeDeploymentController(
                       resourceName,
                       deviceSelector,
                       this.client.DeviceNamespace,
                       this.client.Kubernetes,
                       moduleLifeCycleManager,
                       kubernetesServiceMapper,
                       deploymentMapper,
                       pvcMapper,
                       serviceAccountMapper));
        }