Skip to content

Commit

Permalink
remove force delete pod
Browse files Browse the repository at this point in the history
  • Loading branch information
timfeirg committed Aug 18, 2017
1 parent 9c0165d commit 9c655b8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
11 changes: 3 additions & 8 deletions cluster/calcium/create_container_test.go
Expand Up @@ -90,15 +90,10 @@ func TestCreateContainerWithMemPrior(t *testing.T) {
func TestClean(t *testing.T) {
initMockConfig()

// delete pod
err := mockc.store.DeletePod(podname, false)
// delete pod, which will fail because there are remaining nodes
err := mockc.store.DeletePod(podname)
assert.Error(t, err)
assert.Contains(t, err.Error(), "still has nodes, delete the nodes first")

// force delete
err = mockc.store.DeletePod(podname, true)
assert.NoError(t, err)

assert.Contains(t, err.Error(), "still has nodes")
}

func TestCreateContainerWithCPUPrior(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/mock_test.go
Expand Up @@ -344,7 +344,7 @@ func initMockConfig() {
return true
})).Return(nil)

mockStore.On("DeletePod", mockStringType, mock.AnythingOfType("bool")).Return(nil)
mockStore.On("DeletePod", mockStringType).Return(nil)

deployNodeInfo := []coretypes.NodeInfo{
coretypes.NodeInfo{
Expand Down
6 changes: 3 additions & 3 deletions store/etcd/pod.go
Expand Up @@ -86,15 +86,15 @@ func (k *krypton) GetAllPods() ([]*types.Pod, error) {
}

// DeletePod if the pod has no nodes left, otherwise return an error
func (k *krypton) DeletePod(podname string, force bool) error {
func (k *krypton) DeletePod(podname string) error {
key := fmt.Sprintf("%s/%s", allPodsKey, podname)

ns, err := k.GetNodesByPod(podname)
if err != nil && !client.IsKeyNotFound(err) {
return err
}
if len(ns) != 0 && force == false {
return fmt.Errorf("[DeletePod] pod %s still has nodes, delete the nodes first", podname)
if len(ns) != 0 {
return fmt.Errorf("[DeletePod] pod %s still has nodes: %s, delete them first", podname, ns)
}

_, err = k.etcd.Delete(context.Background(), key, &client.DeleteOptions{Dir: true, Recursive: true})
Expand Down
6 changes: 3 additions & 3 deletions store/mock/store.go
Expand Up @@ -42,15 +42,15 @@ func (m *MockStore) AddPod(name, favor, desc string) (*types.Pod, error) {
return nil, args.Error(1)
}

func (m *MockStore) DeletePod(podname string, force bool) error {
func (m *MockStore) DeletePod(podname string) error {
nodes, err := m.GetNodesByPod(podname)
if err != nil {
return err
}
if len(nodes) != 0 && force != true {
if len(nodes) != 0 {
return fmt.Errorf("[DeletePod] pod %s still has nodes, delete the nodes first", podname)
}
args := m.Called(podname, force)
args := m.Called(podname)
if args.Get(0) != nil {
return args.Error(0)
}
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Expand Up @@ -9,7 +9,7 @@ type Store interface {
// pod
AddPod(name, favor, desc string) (*types.Pod, error)
GetPod(podname string) (*types.Pod, error)
DeletePod(podname string, force bool) error
DeletePod(podname string) error
GetAllPods() ([]*types.Pod, error)

// node
Expand Down

0 comments on commit 9c655b8

Please sign in to comment.