Example #1
0
 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,
     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);
 }
Example #2
0
        public void ApplyDeploymentStrategyWhenProvided()
        {
            var identity           = new ModuleIdentity("hostname", "deviceid", "Module1", Mock.Of <ICredentials>());
            var deploymentStrategy = new V1DeploymentStrategy {
                Type = "Recreate"
            };
            var config = new KubernetesConfig("image", CreatePodParameters.Create(deploymentStrategy: deploymentStrategy), Option.Some(new AuthConfig("user-registry1")));
            var module = new KubernetesModule("module1", "v1", "docker", ModuleStatus.Running, Core.RestartPolicy.Always, DefaultConfigurationInfo, EnvVarsDict, config, ImagePullPolicy.OnCreate, EdgeletModuleOwner);
            var labels = new Dictionary <string, string>();
            var mapper = CreateMapper();

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

            Assert.Equal("Recreate", deployment.Spec.Strategy.Type);
        }
Example #3
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);
        V1Deployment PrepareDeployment(IModuleIdentity identity, KubernetesModule module, IDictionary <string, string> labels)
        {
            string name = identity.DeploymentName();

            var podSpec = this.GetPod(name, identity, module, labels);

            var selector = new V1LabelSelector(matchLabels: labels);

            V1DeploymentStrategy deploymentStrategy = module.Config.CreateOptions.DeploymentStrategy.OrDefault();

            // Desired status in Deployment should only be Running or Stopped. Assume Running if not Stopped
            int replicas       = (module.DesiredStatus != ModuleStatus.Stopped) ? 1 : 0;
            var deploymentSpec = new V1DeploymentSpec(replicas: replicas, selector: selector, strategy: deploymentStrategy, template: podSpec);

            var deploymentMeta = new V1ObjectMeta(
                name: name,
                labels: labels,
                annotations: new Dictionary <string, string>(),
                ownerReferences: module.Owner.ToOwnerReferences());

            return(new V1Deployment(metadata: deploymentMeta, spec: deploymentSpec));
        }