Esempio n. 1
0
        public bool CreateFunctionsContainer(string containerName, out string status, string image = "mcr.microsoft.com/azure-functions/mesh:2.0.12490", int numberOfContainers = 1)
        {
            var deploymentList = client.ListDeploymentForAllNamespaces();

            foreach (var item in deploymentList.Items)
            {
                if (item.Metadata.Name == containerName)
                {
                    status = string.Format("Deployment {0} found! Skipping creation", item.Metadata.Name);
                    return(false);
                }
            }


            try
            {
                /*Creating Deployment*/

                var containerport = new k8s.Models.V1ContainerPort
                {
                    ContainerPort = 80
                };

                var containerports = new List <k8s.Models.V1ContainerPort>
                {
                    containerport
                };

                var container = new k8s.Models.V1Container
                {
                    Name  = containerName,
                    Image = image,
                    Ports = containerports
                };

                var containers = new List <k8s.Models.V1Container>
                {
                    container
                };

                var podSpec = new k8s.Models.V1PodSpec
                {
                    Containers = containers
                };

                var template = new k8s.Models.V1PodTemplateSpec
                {
                    Metadata = new k8s.Models.V1ObjectMeta {
                        Labels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    },
                    Spec = podSpec
                };

                var spec = new k8s.Models.Appsv1beta1DeploymentSpec
                {
                    Replicas = numberOfContainers,
                    Selector = new k8s.Models.V1LabelSelector {
                        MatchLabels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    },
                    Template = template
                };

                var deployment = new k8s.Models.Appsv1beta1Deployment
                {
                    Metadata = new k8s.Models.V1ObjectMeta {
                        Name = containerName
                    },
                    Spec = spec
                };


                client.CreateNamespacedDeployment1(deployment, "default");


                /*Creating Service*/
                var serviceport = new k8s.Models.V1ServicePort
                {
                    Port = 80
                };

                var serviceports = new List <k8s.Models.V1ServicePort>
                {
                    serviceport
                };

                var service = new k8s.Models.V1Service
                {
                    Spec = new k8s.Models.V1ServiceSpec
                    {
                        Type     = "LoadBalancer",
                        Selector = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        },
                        Ports = serviceports
                    },
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name   = containerName,
                        Labels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    }
                };

                client.CreateNamespacedService(service, "default");
            }
            catch (Exception ex)
            {
                status = ex.Message;
                return(false);
            }

            status = string.Format("Created container {0}", containerName);
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArgoTemplate" /> class.
 /// </summary>
 /// <param name="activeDeadlineSeconds">Optional duration in seconds relative to the StartTime that the pod may be active on a node before the system actively tries to terminate the pod; value must be positive integer This field is only applicable to container and script templates..</param>
 /// <param name="affinity">Affinity sets the pod&#39;s scheduling constraints Overrides the affinity set at the workflow level (if any).</param>
 /// <param name="archiveLocation">Location in which all files related to the step will be stored (logs, artifacts, etc...). Can be overridden by individual items in Outputs. If omitted, will use the default artifact repository location configured in the controller, appended with the &lt;workflowname&gt;/&lt;nodename&gt; in the key..</param>
 /// <param name="arguments">Arguments hold arguments to the template..</param>
 /// <param name="container">Container is the main container image to run in the pod.</param>
 /// <param name="daemon">Deamon will allow a workflow to proceed to the next step so long as the container reaches readiness.</param>
 /// <param name="dag">DAG template subtype which runs a DAG.</param>
 /// <param name="hostAliases">HostAliases is an optional list of hosts and IPs that will be injected into the pod spec.</param>
 /// <param name="initContainers">InitContainers is a list of containers which run before the main container..</param>
 /// <param name="inputs">Inputs describe what inputs parameters and artifacts are supplied to this template.</param>
 /// <param name="metadata">Metdata sets the pods&#39;s metadata, i.e. annotations and labels.</param>
 /// <param name="name">Name is the name of the template (required).</param>
 /// <param name="nodeSelector">NodeSelector is a selector to schedule this step of the workflow to be run on the selected node(s). Overrides the selector set at the workflow level..</param>
 /// <param name="outputs">Outputs describe the parameters and artifacts that this template produces.</param>
 /// <param name="parallelism">Parallelism limits the max total parallel pods that can execute at the same time within the boundaries of this template invocation. If additional steps/dag templates are invoked, the pods created by those templates will not be counted towards this total..</param>
 /// <param name="priority">Priority to apply to workflow pods..</param>
 /// <param name="priorityClassName">PriorityClassName to apply to workflow pods..</param>
 /// <param name="resource">Resource template subtype which can run k8s resources.</param>
 /// <param name="retryStrategy">RetryStrategy describes how to retry a template when it fails.</param>
 /// <param name="schedulerName">If specified, the pod will be dispatched by specified scheduler. Or it will be dispatched by workflow scope scheduler if specified. If neither specified, the pod will be dispatched by default scheduler..</param>
 /// <param name="script">Script runs a portion of code against an interpreter.</param>
 /// <param name="securityContext">SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty.  See type description for default values of each field..</param>
 /// <param name="serviceAccountName">ServiceAccountName to apply to workflow pods.</param>
 /// <param name="sidecars">Sidecars is a list of containers which run alongside the main container Sidecars are automatically killed when the main container completes.</param>
 /// <param name="steps">Steps define a series of sequential/parallel workflow steps.</param>
 /// <param name="suspend">Suspend template subtype which can suspend a workflow when reaching the step.</param>
 /// <param name="template">Template is the name of the template which is used as the base of this template..</param>
 /// <param name="templateRef">TemplateRef is the reference to the template resource which is used as the base of this template..</param>
 /// <param name="tolerations">Tolerations to apply to workflow pods..</param>
 /// <param name="volumes">Volumes is a list of volumes that can be mounted by containers in a template..</param>
 public ArgoTemplate(long?activeDeadlineSeconds = default(long?), k8s.Models.V1Affinity affinity = default(k8s.Models.V1Affinity), ArgoArtifactLocation archiveLocation = default(ArgoArtifactLocation), ArgoArguments arguments = default(ArgoArguments), k8s.Models.V1Container container = default(k8s.Models.V1Container), bool?daemon = default(bool?), ArgoDAGTemplate dag = default(ArgoDAGTemplate), List <k8s.Models.V1HostAlias> hostAliases = default(List <k8s.Models.V1HostAlias>), List <ArgoUserContainer> initContainers = default(List <ArgoUserContainer>), ArgoInputs inputs = default(ArgoInputs), ArgoMetadata metadata = default(ArgoMetadata), string name = default(string), Dictionary <string, string> nodeSelector = default(Dictionary <string, string>), ArgoOutputs outputs = default(ArgoOutputs), long?parallelism = default(long?), int?priority = default(int?), string priorityClassName = default(string), ArgoResourceTemplate resource = default(ArgoResourceTemplate), ArgoRetryStrategy retryStrategy = default(ArgoRetryStrategy), string schedulerName = default(string), ArgoScriptTemplate script = default(ArgoScriptTemplate), k8s.Models.V1PodSecurityContext securityContext = default(k8s.Models.V1PodSecurityContext), string serviceAccountName = default(string), List <ArgoUserContainer> sidecars = default(List <ArgoUserContainer>), List <List <ArgoWorkflowStep> > steps = default(List <List <ArgoWorkflowStep> >), ArgoSuspendTemplate suspend = default(ArgoSuspendTemplate), string template = default(string), ArgoTemplateRef templateRef = default(ArgoTemplateRef), List <k8s.Models.V1Toleration> tolerations = default(List <k8s.Models.V1Toleration>), List <k8s.Models.V1Volume> volumes = default(List <k8s.Models.V1Volume>))
 {
     // to ensure "name" is required (not null)
     if (name == null)
     {
         throw new InvalidDataException("name is a required property for ArgoTemplate and cannot be null");
     }
     else
     {
         this.Name = name;
     }
     this.ActiveDeadlineSeconds = activeDeadlineSeconds;
     this.Affinity           = affinity;
     this.ArchiveLocation    = archiveLocation;
     this.Arguments          = arguments;
     this.Container          = container;
     this.Daemon             = daemon;
     this.Dag                = dag;
     this.HostAliases        = hostAliases;
     this.InitContainers     = initContainers;
     this.Inputs             = inputs;
     this.Metadata           = metadata;
     this.NodeSelector       = nodeSelector;
     this.Outputs            = outputs;
     this.Parallelism        = parallelism;
     this.Priority           = priority;
     this.PriorityClassName  = priorityClassName;
     this.Resource           = resource;
     this.RetryStrategy      = retryStrategy;
     this.SchedulerName      = schedulerName;
     this.Script             = script;
     this.SecurityContext    = securityContext;
     this.ServiceAccountName = serviceAccountName;
     this.Sidecars           = sidecars;
     this.Steps              = steps;
     this.Suspend            = suspend;
     this.Template           = template;
     this.TemplateRef        = templateRef;
     this.Tolerations        = tolerations;
     this.Volumes            = volumes;
 }