-
Notifications
You must be signed in to change notification settings - Fork 140
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
Changes from 2 commits
7fb47db
134ea53
2ee215f
17ab3a3
e630aa8
ab2aa35
b89cc50
84f3e29
762bfb0
f52d712
2b2d6c7
10b4156
6a2f797
cd13f02
d059edb
1a19929
417f8de
53bc8dc
0115af4
d65e090
6e15fe7
703ebd1
f1579d0
2fa99f9
f9fdba5
4373b32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We cannot guess what |
||
} | ||
|
||
// NodeService represents service for manage Nodes. | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
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 don't you use the ”delete all method” on Pod service?