Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Feature/k8s job #67

Merged
merged 17 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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
7 changes: 4 additions & 3 deletions documentation/location.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <location_config_meta_props_section>`) 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.
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<properties>
<alien4cloud.version>2.1.0-SM7</alien4cloud.version>
<alien4cloud.kubernetes.api.version>2.1.0-SM7</alien4cloud.kubernetes.api.version>
<tosca.normative.types.version>1.0.0-ALIEN20</tosca.normative.types.version>
<alien4cloud.dsl.version>alien_dsl_2_0_0</alien4cloud.dsl.version>
</properties>
Expand Down
66 changes: 66 additions & 0 deletions tosca-samples/org/ystia/yorc/samples/kube/jobs/types.yaml
Original file line number Diff line number Diff line change
@@ -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