diff --git a/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubeTopologyUtils.java b/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubeTopologyUtils.java index ed400b2..1ad3047 100644 --- a/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubeTopologyUtils.java +++ b/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubeTopologyUtils.java @@ -23,10 +23,12 @@ import alien4cloud.paas.plan.ToscaNodeLifecycleConstants; import alien4cloud.tosca.context.ToscaContext; import alien4cloud.utils.PropertyUtil; +import lombok.extern.java.Log; /** * A utility to browse Kube topologies (enhanced by Kube modifiers). */ +@Log public class KubeTopologyUtils { // A4C & normatives types @@ -72,6 +74,8 @@ public class KubeTopologyUtils { // K8S relationships public static final String K8S_TYPES_RSENDPOINT = "org.alien4cloud.kubernetes.api.relationships.K8SEndpointConnectToEndpoint"; + // A property name used by Service capability Endpoints + public static final String K8S_SERVICE_NAME_PROPERTY = "service_name"; /** * Get the image name from the type implementation artifact file. */ diff --git a/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubernetesLocationTopologyModifier.java b/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubernetesLocationTopologyModifier.java index df4d3a0..65384d8 100644 --- a/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubernetesLocationTopologyModifier.java +++ b/src/main/java/org/alien4cloud/plugin/kubernetes/modifier/KubernetesLocationTopologyModifier.java @@ -21,7 +21,9 @@ import static org.alien4cloud.plugin.kubernetes.modifier.KubeTopologyUtils.getContainerImageName; import static org.alien4cloud.plugin.kubernetes.modifier.KubeTopologyUtils.getValue; import static org.alien4cloud.tosca.utils.ToscaTypeUtils.isOfType; +import static org.alien4cloud.plugin.kubernetes.modifier.KubeTopologyUtils.K8S_SERVICE_NAME_PROPERTY; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -471,7 +473,8 @@ private void manageContainerEndpoints(Csar csar, Topology topology, NodeTemplate // Create the service NodeTemplate serviceNode = addNodeTemplate(csar, topology, containerNodeTemplate.getName() + "_" + controllerNodeTemplate.getName() + "_Service", K8S_TYPES_ABSTRACT_SERVICE, K8S_CSAR_VERSION); - setNodePropertyPathValue(csar, topology, serviceNode, "metadata.name", new ScalarPropertyValue(generateUniqueKubeName(context, serviceNode.getName()))); + String serviceName = generateUniqueKubeName(context, serviceNode.getName()); + setNodePropertyPathValue(csar, topology, serviceNode, "metadata.name", new ScalarPropertyValue(serviceName)); setNodePropertyPathValue(csar, topology, serviceNode, "spec.service_type", new ScalarPropertyValue("NodePort")); // fill properties of service // get the "controller name" @@ -479,6 +482,12 @@ private void manageContainerEndpoints(Csar csar, Topology topology, NodeTemplate setNodePropertyPathValue(csar, topology, serviceNode, "spec.selector.app", controllerName); for (String endpointName : endpointNames) { + // Update the K8S_SERVICE_NAME_PROPERTY capability property if exists + AbstractPropertyValue staticServiceName = containerNodeTemplate.getCapabilities().get(endpointName).getProperties().get(K8S_SERVICE_NAME_PROPERTY); + if (staticServiceName != null) { + setNodeCappabilityPropertyPathValue(csar, topology, containerNodeTemplate, endpointName, K8S_SERVICE_NAME_PROPERTY, new ScalarPropertyValue(serviceName), false); + } + AbstractPropertyValue port = containerNodeTemplate.getCapabilities().get(endpointName).getProperties().get("port"); if (port == null) { context.log().error("Connecting container to an external requires its endpoint port to be defined. Port of [" + containerNodeTemplate.getName() @@ -542,5 +551,4 @@ private void manageContainerEndpoints(Csar csar, Topology topology, NodeTemplate } } - }