Skip to content

Commit

Permalink
Merge pull request #17 from alien4cloud/feature/GH-16-Update-capability
Browse files Browse the repository at this point in the history
Update the K8S_SERVICE_NAME_PROPERTY capability property if exists
  • Loading branch information
adidanes authored Mar 12, 2020
2 parents 2c8cf82 + 676dfe7 commit c779acc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -471,14 +473,21 @@ 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"
AbstractPropertyValue controllerName = PropertyUtil.getPropertyValueFromPath(safe(controllerNodeTemplate.getProperties()), "metadata.name");
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()
Expand Down Expand Up @@ -542,5 +551,4 @@ private void manageContainerEndpoints(Csar csar, Topology topology, NodeTemplate
}
}


}

0 comments on commit c779acc

Please sign in to comment.