diff --git a/Framework/KubernetesWorkflow/K8sController.cs b/Framework/KubernetesWorkflow/K8sController.cs index 4d4ca11c..e0ca025a 100644 --- a/Framework/KubernetesWorkflow/K8sController.cs +++ b/Framework/KubernetesWorkflow/K8sController.cs @@ -656,17 +656,17 @@ namespace KubernetesWorkflow private RunningService? CreateInternalService(ContainerRecipe[] recipes) { - return CreateService(recipes, r => r.InternalPorts.Concat(r.ExposedPorts).ToArray(), "ClusterIP", "int"); + return CreateService(recipes, r => r.InternalPorts.Concat(r.ExposedPorts).ToArray(), "ClusterIP", "int", false); } private RunningService? CreateExternalService(ContainerRecipe[] recipes) { - return CreateService(recipes, r => r.ExposedPorts, "NodePort", "ext"); + return CreateService(recipes, r => r.ExposedPorts, "NodePort", "ext", true); } - private RunningService? CreateService(ContainerRecipe[] recipes, Func portSelector, string serviceType, string namePostfix) + private RunningService? CreateService(ContainerRecipe[] recipes, Func portSelector, string serviceType, string namePostfix, bool isNodePort) { - var ports = CreateServicePorts(recipes, portSelector); + var ports = CreateServicePorts(recipes, portSelector, isNodePort); if (!ports.Any()) return null; var serviceSpec = new V1Service @@ -740,7 +740,7 @@ namespace KubernetesWorkflow }; } - private List CreateServicePorts(ContainerRecipe[] recipes, Func portSelector) + private List CreateServicePorts(ContainerRecipe[] recipes, Func portSelector, bool isNodePort) { var result = new List(); foreach (var recipe in recipes) @@ -748,29 +748,33 @@ namespace KubernetesWorkflow var ports = portSelector(recipe); foreach (var port in ports) { - result.AddRange(CreateServicePorts(recipe, port)); + result.AddRange(CreateServicePorts(recipe, port, isNodePort)); } } return result; } - private List CreateServicePorts(ContainerRecipe recipe, Port recipePort) + private List CreateServicePorts(ContainerRecipe recipe, Port recipePort, bool isNodePort) { var result = new List(); - if (recipePort.IsTcp()) CreateServicePort(result, recipe, recipePort, "TCP"); - if (recipePort.IsUdp()) CreateServicePort(result, recipe, recipePort, "UDP"); + if (recipePort.IsTcp()) CreateServicePort(result, recipe, recipePort, "TCP", isNodePort); + if (recipePort.IsUdp()) CreateServicePort(result, recipe, recipePort, "UDP", isNodePort); return result; } - private void CreateServicePort(List result, ContainerRecipe recipe, Port port, string protocol) + private void CreateServicePort(List result, ContainerRecipe recipe, Port port, string protocol, bool isNodePort) { - result.Add(new V1ServicePort + var p = new V1ServicePort { Name = GetNameForPort(recipe, port), Protocol = protocol, Port = port.Number, TargetPort = GetNameForPort(recipe, port) - }); + }; + + if (isNodePort) p.NodePort = port.Number; + + result.Add(p); } #endregion