Correctly delete replica controller
The correct way to delete a rc should be: 1. Resize the rc to 0. 2. Delete all pods in the rc. 3. Delete the rc. So, we should use 'kubectl stop rc id' to completely delete a rc. This command will first resize a rc to 0 and then delete all pods, before deleting the rc. Change-Id: I3666606f15440942c192aa81635899fa135d036d Closes-Bug: 1424304
This commit is contained in:
parent
34ecd53afe
commit
318ad3cefe
|
@ -109,7 +109,7 @@ required action is to install kubectl manually.
|
||||||
|
|
||||||
Install binary distribution of kubectl distributed by Google::
|
Install binary distribution of kubectl distributed by Google::
|
||||||
|
|
||||||
wget https://github.com/GoogleCloudPlatform/kubernetes/releases/download/v0.7.0/kubernetes.tar.gz
|
wget https://github.com/GoogleCloudPlatform/kubernetes/releases/download/v0.11.0/kubernetes.tar.gz
|
||||||
tar -xzvf kubernetes.tar.gz
|
tar -xzvf kubernetes.tar.gz
|
||||||
sudo cp -a kubernetes/platforms/linux/amd64/kubectl /usr/bin/kubectl
|
sudo cp -a kubernetes/platforms/linux/amd64/kubectl /usr/bin/kubectl
|
||||||
|
|
||||||
|
|
|
@ -262,15 +262,15 @@ class KubeClient(object):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def rc_delete(self, master_address, name):
|
def rc_stop(self, master_address, name):
|
||||||
LOG.debug("rc_delete %s" % name)
|
LOG.debug("rc_stop %s" % name)
|
||||||
try:
|
try:
|
||||||
out, err = utils.trycmd('kubectl', 'delete', 'rc', name,
|
out, err = utils.trycmd('kubectl', 'stop', 'rc', name,
|
||||||
'-s', master_address)
|
'-s', master_address)
|
||||||
if err:
|
if err:
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(_LE("Couldn't delete rc %(rc)s due to error %(error)s")
|
LOG.error(_LE("Couldn't stop rc %(rc)s due to error %(error)s")
|
||||||
% {'rc': name, 'error': e})
|
% {'rc': name, 'error': e})
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -224,7 +224,7 @@ class Handler(object):
|
||||||
k8s_master_url = _retrieve_k8s_master_url(context, rc)
|
k8s_master_url = _retrieve_k8s_master_url(context, rc)
|
||||||
if _object_has_stack(context, rc):
|
if _object_has_stack(context, rc):
|
||||||
# trigger a kubectl command
|
# trigger a kubectl command
|
||||||
status = self.kube_cli.rc_delete(k8s_master_url, rc.name)
|
status = self.kube_cli.rc_stop(k8s_master_url, rc.name)
|
||||||
if not status:
|
if not status:
|
||||||
return None
|
return None
|
||||||
# call the rc object to persist in db
|
# call the rc object to persist in db
|
||||||
|
|
|
@ -248,3 +248,27 @@ class TestKube(base.TestCase):
|
||||||
self.kube_handler.rc_create({}, expected_rc)
|
self.kube_handler.rc_create({}, expected_rc)
|
||||||
mock_kube_cli.rc_create.assert_called_once_with(
|
mock_kube_cli.rc_create.assert_called_once_with(
|
||||||
expected_master_url, expected_rc)
|
expected_master_url, expected_rc)
|
||||||
|
|
||||||
|
@patch('magnum.conductor.handlers.kube._object_has_stack')
|
||||||
|
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||||
|
@patch('magnum.objects.ReplicationController.get_by_uuid')
|
||||||
|
def test_rc_delete_with_success(self,
|
||||||
|
mock_rc_get_by_uuid,
|
||||||
|
mock_retrieve_k8s_master_url,
|
||||||
|
mock_object_has_stack):
|
||||||
|
expected_master_url = 'master_address'
|
||||||
|
mock_rc = mock.MagicMock()
|
||||||
|
mock_rc.name = 'test-rc'
|
||||||
|
mock_rc.uuid = 'test-uuid'
|
||||||
|
mock_rc_get_by_uuid.return_value = mock_rc
|
||||||
|
|
||||||
|
mock_retrieve_k8s_master_url.return_value = expected_master_url
|
||||||
|
mock_object_has_stack.return_value = True
|
||||||
|
with patch.object(self.kube_handler, 'kube_cli') as mock_kube_cli:
|
||||||
|
mock_kube_cli.rc_stop.return_value = True
|
||||||
|
|
||||||
|
self.kube_handler.rc_delete(self.context, mock_rc.uuid)
|
||||||
|
|
||||||
|
mock_kube_cli.rc_stop.assert_called_once_with(
|
||||||
|
expected_master_url, mock_rc.name)
|
||||||
|
mock_rc.destroy.assert_called_once_with(self.context)
|
||||||
|
|
Loading…
Reference in New Issue