CreatePodParameters(
     IReadOnlyList <string> env,
     IDictionary <string, EmptyStruct> exposedPorts,
     HostConfig hostConfig,
     string image,
     IDictionary <string, string> labels,
     IReadOnlyList <string> cmd,
     IReadOnlyList <string> entrypoint,
     string workingDir,
     IDictionary <string, string> nodeSelector,
     V1ResourceRequirements resources,
     IReadOnlyList <KubernetesModuleVolumeSpec> volumes,
     V1PodSecurityContext securityContext)
 {
     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);
 }
        public void AppliesResourcesFromCreateOptionsToContainerSpec()
        {
            var identity  = new ModuleIdentity("hostname", "gatewayhost", "deviceid", "Module1", Mock.Of <ICredentials>());
            var docker    = new DockerModule("module1", "v1", ModuleStatus.Running, RestartPolicy.Always, Config1, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVarsDict);
            var resources = new V1ResourceRequirements(
                new Dictionary <string, ResourceQuantity>
            {
                ["memory"] = new ResourceQuantity("128Mi"),
                ["cpu"]    = new ResourceQuantity("500M"),
                ["hardware-vendor.example/foo"] = 2
            },
                new Dictionary <string, ResourceQuantity>
            {
                ["memory"] = new ResourceQuantity("64Mi"),
                ["cpu"]    = new ResourceQuantity("250M"),
                ["hardware-vendor.example/foo"] = 1
            });
            var config = new KubernetesConfig("image", CreatePodParameters.Create(resources: resources), Option.None <AuthConfig>());
            var module = new KubernetesModule(docker, config, EdgeletModuleOwner);
            var labels = new Dictionary <string, string>();
            var mapper = CreateMapper();

            var deployment = mapper.CreateDeployment(identity, module, labels);

            var moduleContainer = deployment.Spec.Template.Spec.Containers.Single(container => container.Name == "module1");

            Assert.Equal(resources.Limits, moduleContainer.Resources.Limits);
            Assert.Equal(resources.Requests, moduleContainer.Resources.Requests);
        }
Beispiel #3
0
        public void AppliesResourcesFromCreateOptionsToContainerSpec()
        {
            var identity  = new ModuleIdentity("hostname", "gatewayhost", "deviceid", "Module1", Mock.Of <ICredentials>());
            var docker    = new DockerModule("module1", "v1", ModuleStatus.Running, RestartPolicy.Always, Config1, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVarsDict);
            var resources = new V1ResourceRequirements(
                new Dictionary <string, ResourceQuantity>
            {
                ["memory"] = new ResourceQuantity("128Mi"),
                ["cpu"]    = new ResourceQuantity("500M"),
                ["hardware-vendor.example/foo"] = 2
            },
                new Dictionary <string, ResourceQuantity>
            {
                ["memory"] = new ResourceQuantity("64Mi"),
                ["cpu"]    = new ResourceQuantity("250M"),
                ["hardware-vendor.example/foo"] = 1
            });
            var config = new KubernetesConfig("image", CreateOptions(resources: resources), Option.None <AuthConfig>());
            var module = new KubernetesModule(docker, config);
            var mapper = new KubernetesDeploymentMapper("namespace", "edgehub", "proxy", "configPath", "configVolumeName", "configMapName", "trustBundlePAth", "trustBundleVolumeName", "trustBindleConfigMapName", "apiVersion", new Uri("http://workload"), new Uri("http://management"));
            var labels = new Dictionary <string, string>();

            var deployment = mapper.CreateDeployment(identity, module, labels);

            var moduleContainer = deployment.Spec.Template.Spec.Containers.Single(container => container.Name == "module1");

            Assert.Equal(resources.Limits, moduleContainer.Resources.Limits);
            Assert.Equal(resources.Requests, moduleContainer.Resources.Requests);
        }
 internal static CreatePodParameters Create(
     IReadOnlyList <string> env = null,
     IDictionary <string, EmptyStruct> exposedPorts = null,
     HostConfig hostConfig = null,
     string image          = null,
     IDictionary <string, string> labels                = null,
     IDictionary <string, string> nodeSelector          = null,
     V1ResourceRequirements resources                   = null,
     IReadOnlyList <KubernetesModuleVolumeSpec> volumes = null)
 => new CreatePodParameters(env, exposedPorts, hostConfig, image, labels, nodeSelector, resources, volumes);
Beispiel #5
0
 static CreatePodParameters CreateOptions(
     IList <string> env = null,
     IDictionary <string, EmptyStruct> exposedPorts = null,
     HostConfig hostConfig = null,
     string image          = null,
     IDictionary <string, string> labels       = null,
     NetworkingConfig networkingConfig         = null,
     IDictionary <string, string> nodeSelector = null,
     V1ResourceRequirements resources          = null)
 => new CreatePodParameters(env, exposedPorts, hostConfig, image, labels, networkingConfig)
 {
     NodeSelector = Option.Maybe(nodeSelector),
     Resources    = Option.Maybe(resources)
 };
Beispiel #6
0
 internal static CreatePodParameters Create(
     IReadOnlyList <string> env = null,
     IDictionary <string, EmptyStruct> exposedPorts = null,
     HostConfig hostConfig = null,
     string image          = null,
     IDictionary <string, string> labels = null,
     IReadOnlyList <string> cmd          = null,
     IReadOnlyList <string> entrypoint   = null,
     string workingDir = null,
     IDictionary <string, string> nodeSelector          = null,
     V1ResourceRequirements resources                   = null,
     IReadOnlyList <KubernetesModuleVolumeSpec> volumes = null,
     V1PodSecurityContext securityContext               = null,
     V1DeploymentStrategy deploymentStrategy            = null)
 => new CreatePodParameters(env, exposedPorts, hostConfig, image, labels, cmd, entrypoint, workingDir, nodeSelector, resources, volumes, securityContext, deploymentStrategy);
 CreatePodParameters(
     IReadOnlyList <string> env,
     IDictionary <string, EmptyStruct> exposedPorts,
     HostConfig hostConfig,
     string image,
     IDictionary <string, string> labels,
     IDictionary <string, string> nodeSelector,
     V1ResourceRequirements resources,
     IReadOnlyList <KubernetesModuleVolumeSpec> volumes)
 {
     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.NodeSelector = Option.Maybe(nodeSelector);
     this.Resources    = Option.Maybe(resources);
     this.Volumes      = Option.Maybe(volumes);
 }
 CreatePodParameters(
     IList <string> env,
     IDictionary <string, global::Docker.DotNet.Models.EmptyStruct> exposedPorts,
     HostConfig hostConfig,
     string image,
     IDictionary <string, string> labels,
     NetworkingConfig networkingConfig,
     IDictionary <string, string> nodeSelector,
     V1ResourceRequirements resources)
 {
     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.NetworkingConfig = Option.Maybe(networkingConfig);
     this.NodeSelector     = Option.Maybe(nodeSelector);
     this.Resources        = Option.Maybe(resources);
 }
Beispiel #9
0
        public async Task <Job> SubmitJob(Job job)
        {
            var resources = new V1ResourceRequirements
            {
                Requests = new Dictionary <string, ResourceQuantity>()
                {
                    { "cpu", new ResourceQuantity("1") },
                    { "memory", new ResourceQuantity($"1Gi") }
                }
            };

            var podSpec = new V1PodSpec
            {
                Containers = new[]
                {
                    new V1Container
                    {
                        Name    = job.Id,
                        Image   = _config["Pi:Docker:Image"],
                        Command = new []
                        {
                            "/app/Pi.Runtime.NetFx",
                            "-dp",
                            job.DecimalPlaces.ToString()
                        },
                        Resources = resources
                    }
                },
                RestartPolicy = "Never"
            };

            //for running in AKS with ACI integration:
            if (_config.GetValue <bool>("Pi:Processors:Kubernetes:UseAci"))
            {
                AddAciConfiguration(podSpec);
            }

            var jobSpec = new V1JobSpec()
            {
                Template = new V1PodTemplateSpec(spec: podSpec)
            };

            var jobMetadata = new V1ObjectMeta(name: job.Id)
            {
                Labels = new Dictionary <string, string>()
                {
                    { "com.pi", "1" }
                }
            };

            var k8sJob = new V1Job(metadata: jobMetadata, spec: jobSpec);

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("*** Generated YAML: ***");
                var yaml = Yaml.SaveToString(k8sJob);
                _logger.LogDebug(yaml);
                _logger.LogDebug("---");
            }

            await _kubernetes.CreateNamespacedJobAsync(k8sJob, _namespace);

            job.ProcessingId = k8sJob.Metadata.Name;
            return(job);
        }