public async Task <IActionResult> Pod(PodDeploymentModel model) { if (!ModelState.IsValid) { return(BadRequest("Model was not properly fed")); } var podDeployment = await m_kube.CreatePodDeploymentInNamespace(model); return(new JsonResult(podDeployment)); }
public async Task <dynamic> CreatePodDeploymentInNamespace(PodDeploymentModel podModel) { dynamic pod = new ExpandoObject(); var createdPods = new List <V1Pod>(); var count = podModel.Count == 0 ? 1 : podModel.Count; try { for (int i = 0; i < count; i++) { var podConfiguration = new V1Pod { ApiVersion = "v1", Kind = "Pod", Metadata = new V1ObjectMeta { Name = $"{podModel.Name}{i}" }, Spec = new V1PodSpec { Containers = new List <V1Container> { new V1Container { Name = podModel.Name, Image = podModel.Image, ImagePullPolicy = "Always", Command = new List <string> { podModel.Command }, Args = new List <string> { podModel.Arguments }, Resources = new V1ResourceRequirements { Requests = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("0.3") }, { "memory", new ResourceQuantity("10Mi") } }, Limits = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("0.9") }, { "memory", new ResourceQuantity("15Mi") } } } } } } }; var newPod = await m_service.CreateNamespacedPodAsync(podConfiguration, podModel.Namespace); createdPods.Add(newPod); } } catch (Exception ex) { m_logger.LogError(ex, ex.Message); } pod.Pods = createdPods; return(pod); }