Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,26 @@ func (s *Service) Delete(ctx context.Context, name string) error {
}
return nil
}

// Deletes deletes all nodes.
func (s *Service) Deletes(ctx context.Context) error {
pl, err := s.podService.List(ctx)
if err != nil {
return xerrors.Errorf("list pods: %w", err)
}

// delete all pods
Copy link
Member

@sanposhiho sanposhiho Dec 20, 2021

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?

for i := range pl.Items {
pod := pl.Items[i]
if err := s.podService.Delete(ctx, pod.Name); err != nil {
return xerrors.Errorf("delete pod: %w", err)
}
}

// delete all nodes
if err := s.client.CoreV1().Nodes().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
return xerrors.Errorf("delete nodes: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xerrors.Errorf("delete nodes: %w", err)
return xerrors.Errorf("delete all nodes: %w", err)

}

return nil
}
9 changes: 9 additions & 0 deletions persistentvolume/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ func (s *Service) Delete(ctx context.Context, name string) error {

return nil
}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xerrors.Errorf("delete persistentVolumes: %w", err)
return xerrors.Errorf("delete all persistentVolumes: %w", err)

}

return nil
}
9 changes: 9 additions & 0 deletions persistentvolumeclaim/persistentvolumeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ func (s *Service) Delete(ctx context.Context, name string) error {

return nil
}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xerrors.Errorf("delete persistentVolumeClaims: %w", err)
return xerrors.Errorf("delete all persistentVolumeClaims: %w", err)

}

return nil
}
9 changes: 9 additions & 0 deletions pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ func (s *Service) Delete(ctx context.Context, name string) error {

return nil
}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("delete pods: %w", err)
return fmt.Errorf("delete all pods: %w", err)

}

return nil
}
9 changes: 9 additions & 0 deletions priorityclass/priorityclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ func (s *Service) Delete(ctx context.Context, name string) error {

return nil
}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xerrors.Errorf("delete priorityClasses: %w", err)
return xerrors.Errorf("delete all priorityClasses: %w", err)

}

return nil
}
6 changes: 6 additions & 0 deletions server/di/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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.

}

// NodeService represents service for manage Nodes.
Expand All @@ -26,6 +27,7 @@ type NodeService interface {
List(ctx context.Context) (*corev1.NodeList, error)
Apply(ctx context.Context, node *configv1.NodeApplyConfiguration) (*corev1.Node, error)
Delete(ctx context.Context, name string) error
Deletes(ctx context.Context) error
}

// PersistentVolumeService represents service for manage Pods.
Expand All @@ -34,6 +36,7 @@ type PersistentVolumeService interface {
List(ctx context.Context) (*corev1.PersistentVolumeList, error)
Apply(ctx context.Context, pv *configv1.PersistentVolumeApplyConfiguration) (*corev1.PersistentVolume, error)
Delete(ctx context.Context, name string) error
Deletes(ctx context.Context) error
}

// PersistentVolumeClaimService represents service for manage Nodes.
Expand All @@ -42,6 +45,7 @@ type PersistentVolumeClaimService interface {
List(ctx context.Context) (*corev1.PersistentVolumeClaimList, error)
Apply(ctx context.Context, pvc *configv1.PersistentVolumeClaimApplyConfiguration) (*corev1.PersistentVolumeClaim, error)
Delete(ctx context.Context, name string) error
Deletes(ctx context.Context) error
}

// StorageClassService represents service for manage Pods.
Expand All @@ -50,6 +54,7 @@ type StorageClassService interface {
List(ctx context.Context) (*storagev1.StorageClassList, error)
Apply(ctx context.Context, sc *storageconfigv1.StorageClassApplyConfiguration) (*storagev1.StorageClass, error)
Delete(ctx context.Context, name string) error
Deletes(ctx context.Context) error
}

// SchedulerService represents service for manage scheduler.
Expand All @@ -67,4 +72,5 @@ type PriorityClassService interface {
List(ctx context.Context) (*v1.PriorityClassList, error)
Apply(ctx context.Context, priorityClass *schedulingv1.PriorityClassApplyConfiguration) (*v1.PriorityClass, error)
Delete(ctx context.Context, name string) error
Deletes(ctx context.Context) error
}
9 changes: 9 additions & 0 deletions storageclass/storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ func (s *Service) Delete(ctx context.Context, name string) error {

return nil
}

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xerrors.Errorf("delete storageClasss: %w", err)
return xerrors.Errorf("delete all storageClasses: %w", err)

}

return nil
}