Adds support for several applications in single Pod
Kubernetes doesn't allow to add containers to a Pod that is already deployed. With this change old pods will be deleted and either new pod created which will include new container or Replication Controller will be modified (before Pod delete so that updated Pods be created instead) Also now Pods are created only when replica number set to 0. Otherwise Pods created by ReplicationController alone. Change-Id: I8552793f39083de47ad07e7013dedb72e0550885 Closes-Bug: #1444208
This commit is contained in:
parent
e9a04c4db0
commit
a855e9a879
@ -28,15 +28,22 @@ Methods:
|
|||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
Body:
|
Body:
|
||||||
- $._environment.reporter.report($this, 'Waiting for the host to be ready')
|
|
||||||
- $.host.deploy()
|
- $.host.deploy()
|
||||||
- $container: $.getContainer()
|
- $container: $.getContainer()
|
||||||
- $repr: $._getContainerRepresentation($container)
|
- $repr: $._getContainerRepresentation($container)
|
||||||
- If: $.getAttr(container, null) != $repr
|
- If: $.getAttr(container, null) != $repr
|
||||||
Then:
|
Then:
|
||||||
- $.onInstallationStart()
|
- $.onInstallationStart()
|
||||||
|
- Try:
|
||||||
- $.applicationEndpoints: $.host.hostContainer($container)
|
- $.applicationEndpoints: $.host.hostContainer($container)
|
||||||
- $.setAttr(container, $repr)
|
- $.setAttr(container, $repr)
|
||||||
|
Catch:
|
||||||
|
- As: e
|
||||||
|
Do:
|
||||||
|
- $formatString: 'Error: {0}'
|
||||||
|
- $._environment.reporter.report_error($, $formatString.format($e.message))
|
||||||
|
- Rethrow:
|
||||||
|
Else:
|
||||||
- $.onInstallationFinish()
|
- $.onInstallationFinish()
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ Methods:
|
|||||||
Body:
|
Body:
|
||||||
Return: $.masterNode.getIp()
|
Return: $.masterNode.getIp()
|
||||||
|
|
||||||
|
|
||||||
createPod:
|
createPod:
|
||||||
Arguments:
|
Arguments:
|
||||||
- definition:
|
- definition:
|
||||||
@ -159,6 +160,18 @@ Methods:
|
|||||||
- $.masterNode.instance.agent.call($template, $resources)
|
- $.masterNode.instance.agent.call($template, $resources)
|
||||||
|
|
||||||
|
|
||||||
|
deletePods:
|
||||||
|
Arguments:
|
||||||
|
- labels:
|
||||||
|
Contract:
|
||||||
|
$.string().notNull(): $.string().notNull()
|
||||||
|
Body:
|
||||||
|
- $.deploy()
|
||||||
|
- $resources: new(sys:Resources)
|
||||||
|
- $template: $resources.yaml('DeletePods.template').bind(dict(labels => $labels))
|
||||||
|
- $.masterNode.instance.agent.call($template, $resources)
|
||||||
|
|
||||||
|
|
||||||
createServices:
|
createServices:
|
||||||
Arguments:
|
Arguments:
|
||||||
- applicationName:
|
- applicationName:
|
||||||
@ -339,6 +352,7 @@ Methods:
|
|||||||
- $serviceIp: $endpoint.address
|
- $serviceIp: $endpoint.address
|
||||||
- Return: $serviceIp
|
- Return: $serviceIp
|
||||||
|
|
||||||
|
|
||||||
_updateEndpoints:
|
_updateEndpoints:
|
||||||
Body:
|
Body:
|
||||||
- For: endpoint
|
- For: endpoint
|
||||||
@ -428,6 +442,7 @@ Methods:
|
|||||||
- $result.publicIPs: $.minionNodes.take($.nodeCount).select($.getIp())
|
- $result.publicIPs: $.minionNodes.take($.nodeCount).select($.getIp())
|
||||||
- Return: $result
|
- Return: $result
|
||||||
|
|
||||||
|
|
||||||
scaleNodesUp:
|
scaleNodesUp:
|
||||||
Usage: Action
|
Usage: Action
|
||||||
Body:
|
Body:
|
||||||
@ -437,6 +452,7 @@ Methods:
|
|||||||
- $.nodeCount: $.nodeCount + 1
|
- $.nodeCount: $.nodeCount + 1
|
||||||
- $.deploy()
|
- $.deploy()
|
||||||
|
|
||||||
|
|
||||||
scaleNodesDown:
|
scaleNodesDown:
|
||||||
Usage: Action
|
Usage: Action
|
||||||
Body:
|
Body:
|
||||||
@ -446,6 +462,7 @@ Methods:
|
|||||||
- $.nodeCount: $.nodeCount - 1
|
- $.nodeCount: $.nodeCount - 1
|
||||||
- $.deploy()
|
- $.deploy()
|
||||||
|
|
||||||
|
|
||||||
scaleGatewaysUp:
|
scaleGatewaysUp:
|
||||||
Usage: Action
|
Usage: Action
|
||||||
Body:
|
Body:
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
FormatVersion: 2.0.0
|
||||||
|
Version: 1.0.0
|
||||||
|
Name: Delete Pods
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
labels: $labels
|
||||||
|
|
||||||
|
Body: |
|
||||||
|
labels_str = ','.join(map(lambda t: '='.join(t), args.labels.items()))
|
||||||
|
deletePods(labels_str)
|
||||||
|
|
||||||
|
Scripts:
|
||||||
|
deletePods:
|
||||||
|
Type: Application
|
||||||
|
Version: 1.0.0
|
||||||
|
EntryPoint: deletePods.sh
|
||||||
|
Files: []
|
||||||
|
Options:
|
||||||
|
captureStdout: true
|
||||||
|
captureStderr: true
|
||||||
|
|
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Deleting Pods" >> /tmp/murano-kube.log
|
||||||
|
/opt/bin/kubectl delete pod -l $1 >> /tmp/murano-kube.log
|
@ -65,6 +65,17 @@ Methods:
|
|||||||
- container:
|
- container:
|
||||||
Contract: $.class(docker:DockerContainer)
|
Contract: $.class(docker:DockerContainer)
|
||||||
Body:
|
Body:
|
||||||
|
- $podName: $._getPodName()
|
||||||
|
- For: port
|
||||||
|
In: $container.ports
|
||||||
|
Do:
|
||||||
|
- $endpoints: $.kubernetesCluster.serviceEndpoints.where(
|
||||||
|
$.containerPort = $port.port and $.protocol = $port.protocol and $.podId = $podName)
|
||||||
|
- If: len($endpoints) > 0
|
||||||
|
Then:
|
||||||
|
- $msg: format('Port {0} is already used in the Pod {1}', $port.port, $.name)
|
||||||
|
- Throw: PortConflictException
|
||||||
|
Message: $msg
|
||||||
- $._deleteContainer($container.name)
|
- $._deleteContainer($container.name)
|
||||||
|
|
||||||
- $containerDef:
|
- $containerDef:
|
||||||
@ -89,7 +100,7 @@ Methods:
|
|||||||
- $.kubernetesCluster.createServices(
|
- $.kubernetesCluster.createServices(
|
||||||
applicationName => $container.name,
|
applicationName => $container.name,
|
||||||
applicationPorts => $container.ports,
|
applicationPorts => $container.ports,
|
||||||
podId => $._getPodName())
|
podId => $podName)
|
||||||
- Return: $.getEndpoints($container.name)
|
- Return: $.getEndpoints($container.name)
|
||||||
|
|
||||||
|
|
||||||
@ -171,33 +182,39 @@ Methods:
|
|||||||
Body:
|
Body:
|
||||||
Return: toLower($volume.name)
|
Return: toLower($volume.name)
|
||||||
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
Body:
|
Body:
|
||||||
- $prevPod: $.getAttr(lastPodDeployed, null)
|
- $prevPod: $.getAttr(lastPodDeployed, null)
|
||||||
- $prevReplicas: $.getAttr(lastReplicas, 0)
|
- $prevReplicas: $.getAttr(lastReplicas, 0)
|
||||||
|
|
||||||
- $podDefinition: $._podDefinition
|
- $podDefinition: $._podDefinition
|
||||||
- If: $prevPod != $podDefinition
|
- $replicas: $.replicas
|
||||||
|
- If: len($podDefinition.desiredState.manifest.containers) = 0
|
||||||
Then:
|
Then:
|
||||||
- $._environment.reporter.report($, 'Deploying Pod {0}'.format($.name))
|
- $replicas: 0
|
||||||
- $.kubernetesCluster.createPod(
|
- $.setAttr(lastReplicas, $replicas)
|
||||||
definition => $podDefinition, isNew => not $.getAttr(deployed, false))
|
- If: $replicas != $prevReplicas or $prevPod != $podDefinition
|
||||||
- $.setAttr(lastPodDeployed, $podDefinition)
|
|
||||||
- $.setAttr(deployed, true)
|
|
||||||
|
|
||||||
- If: $.replicas != $prevReplicas or $prevPod != $podDefinition
|
|
||||||
Then:
|
Then:
|
||||||
- If: $.replicas > 0
|
- If: $replicas > 0
|
||||||
Then:
|
Then:
|
||||||
- $._environment.reporter.report($, 'Deploying Replication Controller for Pod {0}'.format($.name))
|
- $._environment.reporter.report($, 'Deploying Replication Controller for Pod {0}'.format($.name))
|
||||||
- $rcDefinition: $._buildReplicationControllerDefinition($podDefinition)
|
- $rcDefinition: $._buildReplicationControllerDefinition($podDefinition)
|
||||||
- $.kubernetesCluster.createReplicationController(
|
- $.kubernetesCluster.createReplicationController(
|
||||||
definition => $rcDefinition, isNew => $prevReplicas = 0)
|
definition => $rcDefinition, isNew => $prevReplicas = 0)
|
||||||
- If: $.replicas = 0 and $prevReplicas > 0
|
- If: $replicas = 0 and $prevReplicas > 0
|
||||||
Then:
|
Then:
|
||||||
- $.kubernetesCluster.deleteReplicationController($._getReplicationControllerId())
|
- $.kubernetesCluster.deleteReplicationController($._getReplicationControllerId())
|
||||||
- $.setAttr(lastReplicas, $.replicas)
|
- If: $prevPod != $podDefinition
|
||||||
|
Then:
|
||||||
|
- $.kubernetesCluster.deletePods(dict(id => $._getPodName()))
|
||||||
|
- If: $.replicas = 0 and len($podDefinition.desiredState.manifest.containers) > 0
|
||||||
|
Then:
|
||||||
|
- $.kubernetesCluster.createPod(definition => $podDefinition, isNew => true)
|
||||||
|
|
||||||
- $._environment.reporter.report($, 'Pod {0} is ready'.format($.name))
|
- $._environment.reporter.report($, 'Pod {0} is ready'.format($.name))
|
||||||
|
- $.setAttr(lastPodDeployed, $podDefinition)
|
||||||
|
|
||||||
|
|
||||||
_buildReplicationControllerDefinition:
|
_buildReplicationControllerDefinition:
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -216,10 +233,12 @@ Methods:
|
|||||||
desiredState: $podDefinition.desiredState
|
desiredState: $podDefinition.desiredState
|
||||||
labels: $podDefinition.labels
|
labels: $podDefinition.labels
|
||||||
|
|
||||||
|
|
||||||
_getReplicationControllerId:
|
_getReplicationControllerId:
|
||||||
Body:
|
Body:
|
||||||
- Return: $._getPodName()
|
- Return: $._getPodName()
|
||||||
|
|
||||||
|
|
||||||
getInternalScopeId:
|
getInternalScopeId:
|
||||||
Body:
|
Body:
|
||||||
Return: $.kubernetesCluster.id()
|
Return: $.kubernetesCluster.id()
|
||||||
|
Loading…
Reference in New Issue
Block a user