diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c92633b..98ecca88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## UNRELEASED +### FEATURES + +* Support Kubernetes Jobs. ([GH-67](https://github.com/ystia/yorc-a4c-plugin/issues/67)) + ### ENHANCEMENTS * Take advantage of Alien4Cloud meta-properties to specify a namespace in which to deploy Kubernetes resources ([GH-76](https://github.com/ystia/yorc/issues/76)) diff --git a/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/KubernetesTopologyModifier.java b/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/KubernetesTopologyModifier.java index 81c48c13..e395f6fa 100644 --- a/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/KubernetesTopologyModifier.java +++ b/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/KubernetesTopologyModifier.java @@ -40,10 +40,12 @@ public class KubernetesTopologyModifier extends TopologyModifierSupport { // Yorc K8S resource types protected static final String YORC_KUBERNETES_TYPES_DEPLOYMENT_RESOURCE = "yorc.nodes.kubernetes.api.types.DeploymentResource"; + protected static final String YORC_KUBERNETES_TYPES_JOB_RESOURCE = "yorc.nodes.kubernetes.api.types.JobResource"; protected static final String YORC_KUBERNETES_TYPES_SERVICE_RESOURCE = "yorc.nodes.kubernetes.api.types.ServiceResource"; // A4C K8S resource types defined in org.alien4cloud.plugin.kubernetes.modifier public static final String K8S_TYPES_DEPLOYMENT_RESOURCE = "org.alien4cloud.kubernetes.api.types.DeploymentResource"; + public static final String K8S_TYPES_JOB_RESOURCE = "org.alien4cloud.kubernetes.api.types.JobResource"; public static final String K8S_TYPES_SERVICE_RESOURCE = "org.alien4cloud.kubernetes.api.types.ServiceResource"; @@ -93,6 +95,8 @@ private void doProcess(Topology topology, FlowExecutionContext context) { // // Treat deployment resource types transformKubernetesResourceTypes(topology, csar, "deployment", yorcKubernetesTypesArchiveVersion); + // Treat job resource types + transformKubernetesResourceTypes(topology, csar, "job", yorcKubernetesTypesArchiveVersion); // Treat service resource types transformKubernetesResourceTypes(topology, csar, "service", yorcKubernetesTypesArchiveVersion); @@ -116,12 +120,17 @@ private void transformKubernetesResourceTypes(Topology topology, Csar csar, Stri sourceResourceType = K8S_TYPES_SERVICE_RESOURCE; targetResourceType = YORC_KUBERNETES_TYPES_SERVICE_RESOURCE; break; + case "job" : + sourceResourceType = K8S_TYPES_JOB_RESOURCE; + targetResourceType = YORC_KUBERNETES_TYPES_JOB_RESOURCE; + break; case "deployment" : sourceResourceType = K8S_TYPES_DEPLOYMENT_RESOURCE; targetResourceType = YORC_KUBERNETES_TYPES_DEPLOYMENT_RESOURCE; break; default: - log.info("Yorc K8S Plugin : currently supported K8S resources are " + "service" + " and " + "deployment"); + log.info("Yorc K8S Plugin : currently supported K8S resources are " + "service" + ", job" + " and " + "deployment"); + //log.info("Yorc K8S Plugin : currently supported K8S resources are " + "service" + " and " + "deployment"); break; } diff --git a/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/WorkflowsUtils.java b/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/WorkflowsUtils.java index 3c3464b9..3de9c85c 100644 --- a/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/WorkflowsUtils.java +++ b/alien4cloud-yorc-plugin/src/main/java/org/ystia/yorc/alien4cloud/plugin/modifiers/WorkflowsUtils.java @@ -95,6 +95,19 @@ private static void replaceDelegateStep(Workflow workflow, String stepName, Work workflow.getSteps().remove(stepName); } + /** + * + * @param workflow + * @param step Workflow Step to look for + * @param stepName name of the step to remove + */ + private static void removeStep(Workflow workflow, String step, String stepName) { + WorkflowStep ws = workflow.getSteps().get(step); + if (ws != null) { + ws.getOnSuccess().remove(stepName); + } + } + private static String addSetStateStep(Workflow workflow, String hostId, NodeTemplate nodeTemplate, String state) { SetStateWorkflowActivity sswa = new SetStateWorkflowActivity(); sswa.setStateName(state); diff --git a/alien4cloud-yorc-plugin/src/main/resources/commons/resources/yorc-types.yaml b/alien4cloud-yorc-plugin/src/main/resources/commons/resources/yorc-types.yaml index 29cdac3d..19b7b7cd 100644 --- a/alien4cloud-yorc-plugin/src/main/resources/commons/resources/yorc-types.yaml +++ b/alien4cloud-yorc-plugin/src/main/resources/commons/resources/yorc-types.yaml @@ -76,11 +76,4 @@ node_types: type: yorc.capabilities.Endpoint.ProvisioningAdmin # NOTE: Alien specific - org.alien4cloud.nodes.Job: - abstract: true - derived_from: tosca.nodes.Root - interfaces: - tosca.interfaces.node.lifecycle.Runnable: - run: - description: Standard lifecycle run operation. diff --git a/alien4cloud-yorc-plugin/src/main/resources/kubernetes/resources/resources.yaml b/alien4cloud-yorc-plugin/src/main/resources/kubernetes/resources/resources.yaml index 1f888574..f3acbfee 100644 --- a/alien4cloud-yorc-plugin/src/main/resources/kubernetes/resources/resources.yaml +++ b/alien4cloud-yorc-plugin/src/main/resources/kubernetes/resources/resources.yaml @@ -4,6 +4,8 @@ template_name: yorc-kubernetes-types template_author: Yorc template_version: ${yorc.k8s.types.version} +description: "Defines kubernetes resources for the Yorc plugin." + imports: - org.alien4cloud.kubernetes.api:${alien4cloud.version} @@ -20,5 +22,8 @@ node_types: yorc.nodes.kubernetes.api.types.DeploymentResource: derived_from: org.alien4cloud.kubernetes.api.types.DeploymentResource + yorc.nodes.kubernetes.api.types.JobResource: + derived_from: org.alien4cloud.kubernetes.api.types.JobResource + yorc.nodes.kubernetes.api.types.ServiceResource: derived_from: org.alien4cloud.kubernetes.api.types.ServiceResource diff --git a/documentation/location.rst b/documentation/location.rst index 28cc6e65..8babaa42 100644 --- a/documentation/location.rst +++ b/documentation/location.rst @@ -290,14 +290,15 @@ Go to |OrchLocODRBtn| and search in the ``Catalog`` resources with type prefix ` You have to add the following resources: * ``k8s_api.Deployment`` + * ``k8s_api.Job`` * ``k8s_api.Container`` * ``k8s_api.Service`` * ``k8s_api.volume.*`` # the volume types needed by applications -Go to |OrchLocTMBtn| view to setup modifiers on your location: +Go to |OrchLocTMBtn| view to check modifiers are uploaded to your location: - * add ``Kubernetes modifier`` at the phase ``post location match`` - * add ``Yorc modifier for kubernetes`` at the phase ``post-node-match`` + * ``Kubernetes modifier`` wi having ``post location match`` deployment phase + * ``Yorc modifier for kubernetes`` having ``post-node-match`` deployment phase If you defined a K8S_NAMESPACE meta-property (:ref:`see here how to do so `) with ``location`` target, you can use its value to specify the namespace in which the Kubernetes resources will be created when deploying applications to this location. diff --git a/pom.xml b/pom.xml index 3dbd1571..d7e61f3f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ 2.1.0-SM7 + 2.1.0-SM7 1.0.0-ALIEN20 alien_dsl_2_0_0 diff --git a/tosca-samples/org/ystia/yorc/samples/kube/jobs/types.yaml b/tosca-samples/org/ystia/yorc/samples/kube/jobs/types.yaml new file mode 100644 index 00000000..ddad6b5c --- /dev/null +++ b/tosca-samples/org/ystia/yorc/samples/kube/jobs/types.yaml @@ -0,0 +1,66 @@ +tosca_definitions_version: alien_dsl_2_0_0 + +metadata: + template_name: org.ystia.yorc.samples.kube.jobs + template_version: 1.0.0-SNAPSHOT + template_author: Yorc team + +imports: + - tosca-normative-types:1.0.0-ALIEN20 + - docker-types:2.1.0-SM7 + +description: Contains types for testing Jobs in Kubernetes + +repositories: + docker: + url: https://hub.docker.com/ + type: http + +node_types: + org.ystia.yorc.samples.kube.containers.nodes.ComputePIJob: + derived_from: tosca.nodes.Container.Application.DockerContainer + properties: + docker_run_cmd: + type: list + entry_schema: + type: string + default: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] + interfaces: + Standard: + create: + implementation: + file: perl:latest + repository: docker + type: tosca.artifacts.Deployment.Image.Container.Docker + + org.ystia.yorc.samples.kube.containers.nodes.ComputeBashLoop: + derived_from: tosca.nodes.Container.Application.DockerContainer + properties: + docker_run_cmd: + type: list + entry_schema: + type: string + default: ["/bin/bash", "-c", "for d in $(seq 1 15); do echo $d; sleep $d; done; echo 'Computation done!';"] + interfaces: + Standard: + create: + implementation: + file: "yikaus/alpine-bash:latest" + repository: docker + type: tosca.artifacts.Deployment.Image.Container.Docker + + org.ystia.yorc.samples.kube.containers.nodes.ComputeFail: + derived_from: tosca.nodes.Container.Application.DockerContainer + properties: + docker_run_cmd: + type: list + entry_schema: + type: string + default: ["/bin/bash", "-c", "sleep 10; >&2 echo 'Computation Failed!'; exit 1"] + interfaces: + Standard: + create: + implementation: + file: "yikaus/alpine-bash:latest" + repository: docker + type: tosca.artifacts.Deployment.Image.Container.Docker