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:
parent
fbc1ee11f8
commit
39a9001c04
@ -59,6 +59,16 @@ Methods:
|
|||||||
- $.onInstallationFinish()
|
- $.onInstallationFinish()
|
||||||
|
|
||||||
|
|
||||||
|
destroy:
|
||||||
|
Body:
|
||||||
|
- $.host.deploy()
|
||||||
|
- If: $.getAttr(container, null) != null
|
||||||
|
Then:
|
||||||
|
- $container: $.getContainer()
|
||||||
|
- $.host.deleteContainer($container.name)
|
||||||
|
- $.setAttr(container, null)
|
||||||
|
|
||||||
|
|
||||||
getConnectionTo:
|
getConnectionTo:
|
||||||
Arguments:
|
Arguments:
|
||||||
- application:
|
- application:
|
||||||
|
@ -34,6 +34,7 @@ Methods:
|
|||||||
- name:
|
- name:
|
||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
|
|
||||||
|
|
||||||
getEndpoints:
|
getEndpoints:
|
||||||
Arguments:
|
Arguments:
|
||||||
- applicationName:
|
- applicationName:
|
||||||
|
@ -200,7 +200,7 @@ Methods:
|
|||||||
- $applicationPorts: $.getAttr(applicationPorts, dict())
|
- $applicationPorts: $.getAttr(applicationPorts, dict())
|
||||||
- $key: format('{0}-{1}-{2}', $applicationPort.port, $applicationPort.protocol, $applicationName)
|
- $key: format('{0}-{1}-{2}', $applicationPort.port, $applicationPort.protocol, $applicationName)
|
||||||
|
|
||||||
- If: $key in $applicationPorts
|
- If: $key in $applicationPorts.keys()
|
||||||
Then:
|
Then:
|
||||||
- Return: $applicationPorts.get($key)
|
- Return: $applicationPorts.get($key)
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ Methods:
|
|||||||
- For: key
|
- For: key
|
||||||
In: $applicationPorts.keys()
|
In: $applicationPorts.keys()
|
||||||
Do:
|
Do:
|
||||||
- $value: $applicationPorts.get($port)
|
- $value: $applicationPorts.get($key)
|
||||||
- If: not $value in $portsToDelete
|
- If: not $value in $portsToDelete
|
||||||
Then:
|
Then:
|
||||||
- $newApplicationPorts[$key]: $value
|
- $newApplicationPorts[$key]: $value
|
||||||
|
@ -72,6 +72,7 @@ Methods:
|
|||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
Body:
|
Body:
|
||||||
|
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
|
||||||
- If: not $.getAttr(deployed, false)
|
- If: not $.getAttr(deployed, false)
|
||||||
Then:
|
Then:
|
||||||
- $._environment.reporter.report($this, 'Creating VMs for Kubernetes cluster')
|
- $._environment.reporter.report($this, 'Creating VMs for Kubernetes cluster')
|
||||||
@ -127,6 +128,7 @@ Methods:
|
|||||||
- $.setAttr(lastNodeCount, $.nodeCount)
|
- $.setAttr(lastNodeCount, $.nodeCount)
|
||||||
- $.setAttr(lastGatewayCount, $.gatewayCount)
|
- $.setAttr(lastGatewayCount, $.gatewayCount)
|
||||||
- $._environment.reporter.report($this, 'Kubernetes cluster is up and running')
|
- $._environment.reporter.report($this, 'Kubernetes cluster is up and running')
|
||||||
|
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
|
||||||
|
|
||||||
|
|
||||||
getIp:
|
getIp:
|
||||||
@ -201,6 +203,7 @@ Methods:
|
|||||||
- podId:
|
- podId:
|
||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
Body:
|
Body:
|
||||||
|
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
|
||||||
- $currentEndpoints: $.serviceEndpoints.where($.applicationName = $applicationName and $.podId = $podId and $.scope = internal)
|
- $currentEndpoints: $.serviceEndpoints.where($.applicationName = $applicationName and $.podId = $podId and $.scope = internal)
|
||||||
- $serviceName: format('svc-{0}', randomName())
|
- $serviceName: format('svc-{0}', randomName())
|
||||||
- $endpointMap: {}
|
- $endpointMap: {}
|
||||||
@ -256,6 +259,7 @@ Methods:
|
|||||||
serviceIp => $serviceIp
|
serviceIp => $serviceIp
|
||||||
)
|
)
|
||||||
- $._environment.stack.push()
|
- $._environment.stack.push()
|
||||||
|
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
|
||||||
|
|
||||||
|
|
||||||
_createOrUpdateService:
|
_createOrUpdateService:
|
||||||
@ -396,18 +400,22 @@ Methods:
|
|||||||
- $.masterNode.instance.agent.call($template, $resources)
|
- $.masterNode.instance.agent.call($template, $resources)
|
||||||
|
|
||||||
|
|
||||||
deleteService:
|
deleteServices:
|
||||||
Arguments:
|
Arguments:
|
||||||
- applicationName:
|
- applicationName:
|
||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
- podId:
|
- podId:
|
||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
Body:
|
Body:
|
||||||
|
- $.serviceEndpoints: $.getAttr(serviceEndpoints, list())
|
||||||
- $resources: new(sys:Resources)
|
- $resources: new(sys:Resources)
|
||||||
- $template: $resources.yaml('DeleteService.template').bind(dict(
|
- $services: $.serviceEndpoints.where($.scope = internal and $.podId = $podId).select($.serviceName)
|
||||||
serviceId => $service
|
- $template: $resources.yaml('DeleteServices.template').bind(dict(
|
||||||
|
services => $services
|
||||||
))
|
))
|
||||||
- $.masterNode.instance.agent.call($template, $resources)
|
- $.masterNode.instance.agent.call($template, $resources)
|
||||||
|
- $.serviceEndpoints: $.serviceEndpoints.where($.podId != $podId)
|
||||||
|
- $.setAttr(serviceEndpoints, $.serviceEndpoints)
|
||||||
|
|
||||||
|
|
||||||
_findUnusedPort:
|
_findUnusedPort:
|
||||||
|
@ -12,13 +12,15 @@
|
|||||||
|
|
||||||
FormatVersion: 2.0.0
|
FormatVersion: 2.0.0
|
||||||
Version: 1.0.0
|
Version: 1.0.0
|
||||||
Name: Delete Service
|
Name: Delete Services
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
serviceId: $serviceId
|
services: $services
|
||||||
|
|
||||||
Body: |
|
Body: |
|
||||||
return deleteService('{0}'.format(args.serviceId)).stdout
|
services = set(args.services)
|
||||||
|
for service in services:
|
||||||
|
deleteService(service)
|
||||||
|
|
||||||
Scripts:
|
Scripts:
|
||||||
deleteService:
|
deleteService:
|
@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo "Deleting a Service" >> /tmp/murano-kube.log
|
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
|
||||||
|
@ -41,23 +41,37 @@ Methods:
|
|||||||
initialize:
|
initialize:
|
||||||
Body:
|
Body:
|
||||||
- $._environment: $.find(std:Environment).require()
|
- $._environment: $.find(std:Environment).require()
|
||||||
|
- $._podDefinition: null
|
||||||
|
|
||||||
- $podName: $._getPodName()
|
|
||||||
- $podDefinition: $.getAttr(lastPodDeployed, null)
|
# this is a workaround for early initialization. If docker application was deleted
|
||||||
- If: $podDefinition = null
|
# 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:
|
Then:
|
||||||
- $podDefinition:
|
- $podName: $._getPodName()
|
||||||
apiVersion: v1beta3
|
- $podDefinition: $.getAttr(lastPodDeployed, null)
|
||||||
kind: Pod
|
- If: $podDefinition = null
|
||||||
metadata:
|
Then:
|
||||||
name: $podName
|
- $podDefinition:
|
||||||
labels: $._getPodLabels($podName)
|
apiVersion: v1beta3
|
||||||
spec:
|
kind: Pod
|
||||||
containers: []
|
metadata:
|
||||||
volumes: []
|
name: $podName
|
||||||
|
labels: $._getPodLabels($podName)
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
|
volumes: []
|
||||||
|
|
||||||
|
- $.setAttr(lastPodDeployed, $podDefinition)
|
||||||
|
- $._podDefinition: $podDefinition
|
||||||
|
- Return: $._podDefinition
|
||||||
|
|
||||||
- $.setAttr(lastPodDeployed, $podDefinition)
|
|
||||||
- $._podDefinition: $podDefinition
|
|
||||||
|
|
||||||
_getPodName:
|
_getPodName:
|
||||||
Body:
|
Body:
|
||||||
@ -75,6 +89,7 @@ Methods:
|
|||||||
- container:
|
- container:
|
||||||
Contract: $.class(docker:DockerContainer)
|
Contract: $.class(docker:DockerContainer)
|
||||||
Body:
|
Body:
|
||||||
|
- $._loadCurrentPodDefinition()
|
||||||
- $podName: $._getPodName()
|
- $podName: $._getPodName()
|
||||||
- For: port
|
- For: port
|
||||||
In: $container.ports
|
In: $container.ports
|
||||||
@ -93,11 +108,15 @@ Methods:
|
|||||||
image: $container.image
|
image: $container.image
|
||||||
args: $container.commands
|
args: $container.commands
|
||||||
ports: $container.ports.select($this._getPortDefinition($))
|
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($)))
|
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).
|
- $newVolumes: $container.volumes.values().select(
|
||||||
select($this._buildVolumeEntry($))
|
$this._buildVolumeEntry($container.name, $))
|
||||||
|
|
||||||
- $diff:
|
- $diff:
|
||||||
spec:
|
spec:
|
||||||
@ -136,6 +155,8 @@ Methods:
|
|||||||
|
|
||||||
_buildVolumeEntry:
|
_buildVolumeEntry:
|
||||||
Arguments:
|
Arguments:
|
||||||
|
- name:
|
||||||
|
Contract: $.string().notNull()
|
||||||
- volume:
|
- volume:
|
||||||
Contract: $.class(docker:DockerVolume).notNull()
|
Contract: $.class(docker:DockerVolume).notNull()
|
||||||
Body:
|
Body:
|
||||||
@ -153,7 +174,7 @@ Methods:
|
|||||||
- Throw: UnknownDockerVolumeType
|
- Throw: UnknownDockerVolumeType
|
||||||
Message: format('Unknown docker volume type {0}', $type)
|
Message: format('Unknown docker volume type {0}', $type)
|
||||||
- Return:
|
- Return:
|
||||||
name: $._generateVolumeName($volume)
|
name: $._generateVolumeName($name, $volume)
|
||||||
source: $spec
|
source: $spec
|
||||||
|
|
||||||
|
|
||||||
@ -163,9 +184,25 @@ Methods:
|
|||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
Body:
|
Body:
|
||||||
- $lenBefore: len($._podDefinition.spec.containers) + len($._podDefinition.spec.volumes)
|
- $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(
|
- $newVolumes: $._podDefinition.spec.volumes.where(
|
||||||
$.name in $._podDefinition.spec.containers.volumeMounts.name)
|
not ($.name in $volumesToDelete))
|
||||||
- If: len($newContainers) + len($newVolumes) != $lenBefore
|
- If: len($newContainers) + len($newVolumes) != $lenBefore
|
||||||
Then:
|
Then:
|
||||||
- $._podDefinition.spec.containers: $newContainers
|
- $._podDefinition.spec.containers: $newContainers
|
||||||
@ -177,8 +214,9 @@ Methods:
|
|||||||
- name:
|
- name:
|
||||||
Contract: $.string().notNull()
|
Contract: $.string().notNull()
|
||||||
Body:
|
Body:
|
||||||
|
- $._loadCurrentPodDefinition()
|
||||||
- $._deleteContainer($name)
|
- $._deleteContainer($name)
|
||||||
- $.kubernetesCluster.deleteService(
|
- $.kubernetesCluster.deleteServices(
|
||||||
applicationName => $name,
|
applicationName => $name,
|
||||||
podId => $._getPodName())
|
podId => $._getPodName())
|
||||||
- $.deploy()
|
- $.deploy()
|
||||||
@ -186,14 +224,25 @@ Methods:
|
|||||||
|
|
||||||
_generateVolumeName:
|
_generateVolumeName:
|
||||||
Arguments:
|
Arguments:
|
||||||
|
- name:
|
||||||
|
Contract: $.string().notNull()
|
||||||
- volume:
|
- volume:
|
||||||
Contract: $.class(docker:DockerVolume).notNull()
|
Contract: $.class(docker:DockerVolume).notNull()
|
||||||
Body:
|
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:
|
deploy:
|
||||||
Body:
|
Body:
|
||||||
|
- $._loadCurrentPodDefinition()
|
||||||
- $prevPod: $.getAttr(lastPodDeployed, null)
|
- $prevPod: $.getAttr(lastPodDeployed, null)
|
||||||
- $prevReplicas: $.getAttr(lastReplicas, 0)
|
- $prevReplicas: $.getAttr(lastReplicas, 0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user