Adds ability to delete docker applications from the host

Application deletion were supported on DSH/Pod but not exposed
in DockerApplication. Once it became exposed number of bugs in
KubernetesPod and DSH became visible.

Change-Id: I33650936a73994668f72348a909b7a51bae2b98c
Closes-Bug: #1446582
(cherry picked from commit a74293e2b4ed5695737066d9154d51a4170b8a80)
This commit is contained in:
Stan Lagun 2015-04-29 18:21:31 +03:00
parent fbc1ee11f8
commit 39a9001c04
7 changed files with 101 additions and 31 deletions

View File

@ -59,6 +59,16 @@ Methods:
- $.onInstallationFinish()
destroy:
Body:
- $.host.deploy()
- If: $.getAttr(container, null) != null
Then:
- $container: $.getContainer()
- $.host.deleteContainer($container.name)
- $.setAttr(container, null)
getConnectionTo:
Arguments:
- application:

View File

@ -34,6 +34,7 @@ Methods:
- name:
Contract: $.string().notNull()
getEndpoints:
Arguments:
- applicationName:

View File

@ -200,7 +200,7 @@ Methods:
- $applicationPorts: $.getAttr(applicationPorts, dict())
- $key: format('{0}-{1}-{2}', $applicationPort.port, $applicationPort.protocol, $applicationName)
- If: $key in $applicationPorts
- If: $key in $applicationPorts.keys()
Then:
- Return: $applicationPorts.get($key)
@ -242,7 +242,7 @@ Methods:
- For: key
In: $applicationPorts.keys()
Do:
- $value: $applicationPorts.get($port)
- $value: $applicationPorts.get($key)
- If: not $value in $portsToDelete
Then:
- $newApplicationPorts[$key]: $value

View File

@ -72,6 +72,7 @@ Methods:
deploy:
Body:
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
- If: not $.getAttr(deployed, false)
Then:
- $._environment.reporter.report($this, 'Creating VMs for Kubernetes cluster')
@ -127,6 +128,7 @@ Methods:
- $.setAttr(lastNodeCount, $.nodeCount)
- $.setAttr(lastGatewayCount, $.gatewayCount)
- $._environment.reporter.report($this, 'Kubernetes cluster is up and running')
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
getIp:
@ -201,6 +203,7 @@ Methods:
- podId:
Contract: $.string().notNull()
Body:
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
- $currentEndpoints: $.serviceEndpoints.where($.applicationName = $applicationName and $.podId = $podId and $.scope = internal)
- $serviceName: format('svc-{0}', randomName())
- $endpointMap: {}
@ -256,6 +259,7 @@ Methods:
serviceIp => $serviceIp
)
- $._environment.stack.push()
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
_createOrUpdateService:
@ -396,18 +400,22 @@ Methods:
- $.masterNode.instance.agent.call($template, $resources)
deleteService:
deleteServices:
Arguments:
- applicationName:
Contract: $.string().notNull()
- podId:
Contract: $.string().notNull()
Body:
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
- $resources: new(sys:Resources)
- $template: $resources.yaml('DeleteService.template').bind(dict(
serviceId => $service
- $services: $.serviceEndpoints.where($.scope = internal and $.podId = $podId).select($.serviceName)
- $template: $resources.yaml('DeleteServices.template').bind(dict(
services => $services
))
- $.masterNode.instance.agent.call($template, $resources)
- $.serviceEndpoints: $.serviceEndpoints.where($.podId != $podId)
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
_findUnusedPort:

View File

@ -12,13 +12,15 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Delete Service
Name: Delete Services
Parameters:
serviceId: $serviceId
services: $services
Body: |
return deleteService('{0}'.format(args.serviceId)).stdout
services = set(args.services)
for service in services:
deleteService(service)
Scripts:
deleteService:

View File

@ -1,3 +1,3 @@
#!/bin/bash
echo "Deleting a Service" >> /tmp/murano-kube.log
/opt/bin/kubectl delete services $1 >> /tmp/murano-kube.log
/opt/bin/kubectl delete service $1 >> /tmp/murano-kube.log

View File

@ -41,23 +41,37 @@ Methods:
initialize:
Body:
- $._environment: $.find(std:Environment).require()
- $._podDefinition: null
- $podName: $._getPodName()
- $podDefinition: $.getAttr(lastPodDeployed, null)
- If: $podDefinition = null
# this is a workaround for early initialization. If docker application was deleted
# its destroy method will call deleteContainer method that will change _podDefinition
# on KubernetesPod loaded from ObjectsCopy
# but ininitialize method on a KubernetesPod from Objects is called before destruction
# and because we have 2 different KubernetesPod objects that share attributes but
# not private variables _podDefinition of real object will still contain outdated data
_loadCurrentPodDefinition:
Body:
- If: $._podDefinition = null
Then:
- $podDefinition:
apiVersion: v1beta3
kind: Pod
metadata:
name: $podName
labels: $._getPodLabels($podName)
spec:
containers: []
volumes: []
- $podName: $._getPodName()
- $podDefinition: $.getAttr(lastPodDeployed, null)
- If: $podDefinition = null
Then:
- $podDefinition:
apiVersion: v1beta3
kind: Pod
metadata:
name: $podName
labels: $._getPodLabels($podName)
spec:
containers: []
volumes: []
- $.setAttr(lastPodDeployed, $podDefinition)
- $._podDefinition: $podDefinition
- Return: $._podDefinition
- $.setAttr(lastPodDeployed, $podDefinition)
- $._podDefinition: $podDefinition
_getPodName:
Body:
@ -75,6 +89,7 @@ Methods:
- container:
Contract: $.class(docker:DockerContainer)
Body:
- $._loadCurrentPodDefinition()
- $podName: $._getPodName()
- For: port
In: $container.ports
@ -93,11 +108,15 @@ Methods:
image: $container.image
args: $container.commands
ports: $container.ports.select($this._getPortDefinition($))
volumeMounts: $container.volumes.keys().select(dict(name => $this._generateVolumeName($container.volumes.get($)), mountPath => $))
volumeMounts: $container.volumes.keys().select(
dict(
name => $this._generateVolumeName($container.name, $container.volumes.get($)),
mountPath => $
))
env: $container.env.keys().select(dict(name => $, value => $container.env.get($)))
- $newVolumes: $container.volumes.values().where(not $this._generateVolumeName($) in $this._podDefinition.spec.volumes.name).
select($this._buildVolumeEntry($))
- $newVolumes: $container.volumes.values().select(
$this._buildVolumeEntry($container.name, $))
- $diff:
spec:
@ -136,6 +155,8 @@ Methods:
_buildVolumeEntry:
Arguments:
- name:
Contract: $.string().notNull()
- volume:
Contract: $.class(docker:DockerVolume).notNull()
Body:
@ -153,7 +174,7 @@ Methods:
- Throw: UnknownDockerVolumeType
Message: format('Unknown docker volume type {0}', $type)
- Return:
name: $._generateVolumeName($volume)
name: $._generateVolumeName($name, $volume)
source: $spec
@ -163,9 +184,25 @@ Methods:
Contract: $.string().notNull()
Body:
- $lenBefore: len($._podDefinition.spec.containers) + len($._podDefinition.spec.volumes)
- $newContainers: $._podDefinition.spec.containers.where($.name != $name)
- $containerName: toLower($name)
- $newContainers: $._podDefinition.spec.containers.where($.name != $containerName)
- $volumeNameMap: $.getAttr(volumeNameMap, dict())
- $newVolumeNameMap: {}
- $volumesToDelete: []
- $prefix: format('{0}/'.format($name))
- For: key
In: $volumeNameMap.keys()
Do:
- $volumeName: $volumeNameMap.get($key)
- If: $key.startsWith($prefix)
Then:
- $volumesToDelete: $volumesToDelete + list($volumeName)
Else:
- $newVolumeNameMap[$key]: $volumeName
- $.setAttr(volumeNameMap, $newVolumeNameMap)
- $newVolumes: $._podDefinition.spec.volumes.where(
$.name in $._podDefinition.spec.containers.volumeMounts.name)
not ($.name in $volumesToDelete))
- If: len($newContainers) + len($newVolumes) != $lenBefore
Then:
- $._podDefinition.spec.containers: $newContainers
@ -177,8 +214,9 @@ Methods:
- name:
Contract: $.string().notNull()
Body:
- $._loadCurrentPodDefinition()
- $._deleteContainer($name)
- $.kubernetesCluster.deleteService(
- $.kubernetesCluster.deleteServices(
applicationName => $name,
podId => $._getPodName())
- $.deploy()
@ -186,14 +224,25 @@ Methods:
_generateVolumeName:
Arguments:
- name:
Contract: $.string().notNull()
- volume:
Contract: $.class(docker:DockerVolume).notNull()
Body:
Return: toLower($volume.name)
- $key: format('{0}/{1}', $name, $volume.name)
- $map: $.getAttr(volumeNameMap, dict())
- $volumeName: $map.get($key)
- If: $volumeName = null
Then:
- $volumeName: randomName()
- $map[$key]: $volumeName
- $.setAttr(volumeNameMap, $map)
- Return: $volumeName
deploy:
Body:
- $._loadCurrentPodDefinition()
- $prevPod: $.getAttr(lastPodDeployed, null)
- $prevReplicas: $.getAttr(lastReplicas, 0)