-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add resources "delete all" method in each service #68
add resources "delete all" method in each service #68
Conversation
server/di/interface.go
Outdated
@@ -18,6 +18,7 @@ type PodService interface { | |||
List(ctx context.Context) (*corev1.PodList, error) | |||
Apply(ctx context.Context, pod *configv1.PodApplyConfiguration) (*corev1.Pod, error) | |||
Delete(ctx context.Context, name string) error | |||
Deletes(ctx context.Context) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot guess what Deletes
does.
Maybe DeleteAll
or Reset
is better.
node/node.go
Outdated
return xerrors.Errorf("list pods: %w", err) | ||
} | ||
|
||
// delete all pods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use the ”delete all method” on Pod service?
node/node.go
Outdated
|
||
// delete all nodes | ||
if err := s.client.CoreV1().Nodes().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete nodes: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete nodes: %w", err) | |
return xerrors.Errorf("delete all nodes: %w", err) |
persistentvolume/persistentvolume.go
Outdated
// Deletes deletes all persistentVolumes. | ||
func (s *Service) Deletes(ctx context.Context) error { | ||
if err := s.client.CoreV1().PersistentVolumes().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete persistentVolumes: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete persistentVolumes: %w", err) | |
return xerrors.Errorf("delete all persistentVolumes: %w", err) |
// Deletes deletes all persistentVolumeClaims. | ||
func (s *Service) Deletes(ctx context.Context) error { | ||
if err := s.client.CoreV1().PersistentVolumeClaims(defaultNamespaceName).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete persistentVolumeClaims: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete persistentVolumeClaims: %w", err) | |
return xerrors.Errorf("delete all persistentVolumeClaims: %w", err) |
pod/pod.go
Outdated
// Deltes deletes all pods. | ||
func (s *Service) Deletes(ctx context.Context) error { | ||
if err := s.client.CoreV1().Pods(defaultNamespaceName).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return fmt.Errorf("delete pods: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("delete pods: %w", err) | |
return fmt.Errorf("delete all pods: %w", err) |
priorityclass/priorityclass.go
Outdated
// Deletes deletes all priority classes. | ||
func (s *Service) Deletes(ctx context.Context) error { | ||
if err := s.client.SchedulingV1().PriorityClasses().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete priorityClasses: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete priorityClasses: %w", err) | |
return xerrors.Errorf("delete all priorityClasses: %w", err) |
storageclass/storageclass.go
Outdated
// Deletes deletes all storageClasss. | ||
func (s *Service) Deletes(ctx context.Context) error { | ||
if err := s.client.StorageV1().StorageClasses().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete storageClasss: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete storageClasss: %w", err) | |
return xerrors.Errorf("delete all storageClasses: %w", err) |
Let me retitle this to be more appropriate. /retitle add resources "delete all" method in each service. |
/retitle add resources "delete all" method in each service |
4c70044
to
ab2aa35
Compare
storageclass/storageclass.go
Outdated
// DeleteAll deletes all storageClassses. | ||
func (s *Service) DeleteAll(ctx context.Context) error { | ||
if err := s.client.StorageV1().StorageClasses().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { | ||
return xerrors.Errorf("delete all storageClassses: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo (the same typo on the DeleteAll
comment.)
return xerrors.Errorf("delete all storageClassses: %w", err) | |
return xerrors.Errorf("delete all storageClasses: %w", err) |
node/node.go
Outdated
} | ||
if len(pl.Items) == 0 { | ||
klog.Info("delete all nodes: no pods to delete") | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can we return here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I mistook.
node/node_test.go
Outdated
@@ -146,3 +146,122 @@ func TestService_Delete(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestService_DeleteAll(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
node/node.go
Outdated
return xerrors.Errorf("list pods: %w", err) | ||
} | ||
if len(pl.Items) == 0 { | ||
klog.Info("delete all nodes: no pods to delete") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to list pod only to log it.
node/node.go
Outdated
|
||
// delete all pods | ||
if err := s.podService.DeleteAll(ctx); err != nil { | ||
return xerrors.Errorf("delete all nodes: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xerrors.Errorf("delete all nodes: %w", err) | |
return xerrors.Errorf("delete all pods: %w", err) |
node/node_test.go
Outdated
wantErr bool | ||
}{ | ||
{ | ||
name: "delete all nodes and pods on nodes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, Do you want to delete only Pods on node? (= do you want not to delete unscheduled pods?)
Yeah, I think it is better than deleting all nodes and all pods (include unscheduled pods.).
Currently, DeleteAll
deletes all nodes and all pods, so, should be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fixed it.
node/node_test.go
Outdated
wantErr: false, | ||
}, | ||
{ | ||
name: "fail to delete no nodes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you double-check? I think this name is incorrect.
name: "fail to delete no nodes", | |
name: "fail if deleting all pods returns error", |
I fixed DeleteAll method of pod.go. |
pod/pod.go
Outdated
@@ -74,3 +74,39 @@ func (s *Service) Delete(ctx context.Context, name string) error { | |||
|
|||
return nil | |||
} | |||
|
|||
// DelteAll deletes all pods. | |||
func (s *Service) DeleteAll(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this DeleteAll method, you should delete all Pods.
But, in DeleteAll of node service, you shouldn't delete all Pods but delete all scheduled Pods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,
- rename this method to
DeleteAllScheduledPod
- use
DeleteAllScheduledPod
fromDeleteAll
in node service - create new
DeleteAll
which deletes all pods(= scheduled pods + unscheduled pods.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review.
create new DeleteAll which deletes all pods(= scheduled pods + unscheduled pods.)
This method will be not used now, so I think it's better not to create it.
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will be not used now,
No. DeleteAll
method is needed to delete all Pods.
You'd like to create "delete all" method in each service now, right?
Deleting all Nodes means "delete all Nodes and delete all scheduled Pods". So, you need to create "DeleteAllScheduledPod" to delete all scheduled Pods in "DeleteAll" in node service.
Deleting all Pods means "delete all pods whether they are scheduled or not." So, you also need to create "DeleteAll" to delete all Pods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this PR is scoped to create delete all
method in each service, so we should create DeleteAllScheduledPod
and DeleteAll
, right ?
Deleting all Nodes means "delete all Nodes and delete all scheduled Pods". So, you need to create
"DeleteAllScheduledPod" to delete all scheduled Pods in "DeleteAll" in node service.
Deleting all Pods means "delete all pods whether they are scheduled or not." So, you also need to create
"DeleteAll" to delete all Pods.
I know, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added DeleteAll method, too. pod service
test isn't existed, now.
Shall I add a test? Or do you hope to create different PR because the scope is larger than this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I've just commented about the test. Yes, please add test for DeleteAllScheduledPod.
#68 (comment)
node/node.go
Outdated
func (s *Service) DeleteAll(ctx context.Context) error { | ||
// delete all pods | ||
if err := s.podService.DeleteAllScheduledPod(ctx); err != nil { | ||
return xerrors.Errorf("delete all pods: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
return xerrors.Errorf("delete all pods: %w", err) | |
return xerrors.Errorf("delete all scheduled pods: %w", err) |
node/node_test.go
Outdated
wantErr: false, | ||
}, | ||
{ | ||
name: "fail if delteing all pods returns error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "fail if delteing all pods returns error", | |
name: "fail if deleting all pods returns error", |
node/node_test.go
Outdated
{ | ||
name: "delete all nodes and pods scheduled on them", | ||
preparePodServiceMockFn: func(m *mock_node.MockPodService) { | ||
m.EXPECT().List(gomock.Any()).Return(&corev1.PodList{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List method on Pod service is not called.
pod/pod.go
Outdated
@@ -74,3 +73,21 @@ func (s *Service) Delete(ctx context.Context, name string) error { | |||
|
|||
return nil | |||
} | |||
|
|||
// DeleteAllPod deletes all pods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// DeleteAllPod deletes all pods. | |
// DeleteAll deletes all pods. |
storageclass/storageclass.go
Outdated
@@ -62,3 +62,12 @@ func (s *Service) Delete(ctx context.Context, name string) error { | |||
|
|||
return nil | |||
} | |||
|
|||
// DeleteAll deletes all storageClassses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// DeleteAll deletes all storageClassses. | |
// DeleteAll deletes all storageClasses. |
pod/pod.go
Outdated
} | ||
|
||
// DelteAllScheduledPod deletes all scheduled pods. | ||
func (s *Service) DeleteAllScheduledPod(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you 念のため add a brief test for this method? :)
I'm checking, now. so I'll notify you I ready to review 👍 |
server/di/interface.go
Outdated
@@ -18,6 +18,8 @@ type PodService interface { | |||
List(ctx context.Context) (*corev1.PodList, error) | |||
Apply(ctx context.Context, pod *configv1.PodApplyConfiguration) (*corev1.Pod, error) | |||
Delete(ctx context.Context, name string) error | |||
DeleteAll(ctx context.Context) error | |||
DeleteAllScheduledPod(ctx context.Context) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeleteAllScheduledPod
is not expected to call from handler layer for now, so I think it is not needed to add this.
pod/pod.go
Outdated
// DelteAllScheduledPod deletes all scheduled pods. | ||
func (s *Service) DeleteAllScheduledPod(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: DeleteAllScheduledPod → DeleteAllScheduledPods
// DelteAllScheduledPod deletes all scheduled pods. | |
func (s *Service) DeleteAllScheduledPod(ctx context.Context) error { | |
// DeleteAllScheduledPods deletes all scheduled pods. | |
func (s *Service) DeleteAllScheduledPods(ctx context.Context) error { |
On my second thought, it is better to implement DeleteCollection in pod service and use it from node service.
Yes, we can delete all Pods with this What do you think about this? Could you re-implement like the above if no objections? 🙇 |
/assign |
@sanposhiho |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!! One comment.
persistentvolume/persistentvolume.go
Outdated
@@ -62,3 +62,12 @@ func (s *Service) Delete(ctx context.Context, name string) error { | |||
|
|||
return nil | |||
} | |||
|
|||
// DeleteCollection deletes all persistentVolumes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to try to make interfaces of all services same.
Currently, the pod service's DeleteCollection only accepts metav1.ListOptions arg. So, let's add ListOptions to other service's DeleteCollection arg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this commit is failed.
I fixed it later.
/test pull-kube-scheduler-simulator-backend-unit-test |
I fixed. Please review 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ❤️
One comment from me.
node/node.go
Outdated
lopts := metav1.ListOptions{ | ||
FieldSelector: "spec.nodeName=" + n.Name, | ||
} | ||
if err := s.podService.DeleteCollection(ctx, lopts); err != nil { | ||
return xerrors.Errorf("failed to delete pods on node %s: %w", n.Name, err) | ||
} | ||
|
||
// delete specific node | ||
if err := s.client.CoreV1().Nodes().Delete(ctx, n.Name, metav1.DeleteOptions{}); err != nil { | ||
return xerrors.Errorf("delete node: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process these part in parallel with errgroup or waitgroup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ! I agree with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
node/node.go
Outdated
@@ -90,3 +92,33 @@ func (s *Service) Delete(ctx context.Context, name string) error { | |||
} | |||
return nil | |||
} | |||
|
|||
// DeleteCollection deletes all nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nits:
Please change other services doc as well
// DeleteCollection deletes all nodes. | |
// DeleteCollection deletes Nodes according to the list options. | |
// And it also deletes Pods scheduled on those Nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sanposhiho, sivchari The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
I added delete all resources of each objects.
Which issue(s) this PR fixes:
Fixes #67
Special notes for your reviewer:
/label tide/merge-method-squash