-
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 reset service #105
Add reset service #105
Conversation
Hi @sivchari. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @sanposhiho |
/assign |
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!
@@ -39,12 +39,3 @@ func (h *SchedulerConfigHandler) ApplySchedulerConfig(c echo.Context) error { | |||
|
|||
return c.NoContent(http.StatusAccepted) | |||
} | |||
|
|||
func (h *SchedulerConfigHandler) ResetScheduler(c echo.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.
R.I.P
reset/reset.go
Outdated
type NodeService interface { | ||
DeleteCollection(ctx context.Context, lopts metav1.ListOptions) error | ||
} | ||
|
||
type PersistentVolumeService interface { | ||
DeleteCollection(ctx context.Context, lopts metav1.ListOptions) error | ||
} | ||
|
||
type PersistentVolumeClaimService interface { | ||
DeleteCollection(ctx context.Context, lopts metav1.ListOptions) error | ||
} | ||
|
||
type StorageClassService interface { | ||
DeleteCollection(ctx context.Context, lopts metav1.ListOptions) error | ||
} | ||
|
||
type PriorityClassService interface { | ||
DeleteCollection(ctx context.Context, lopts metav1.ListOptions) 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.
They all have the same interface. So, we can use just one interface (name will be like DeleteService
?) for better abstraction.
That way, when new resource is supported in the future, the changes to the Reset service will be small.
reset/reset.go
Outdated
|
||
// Reset cleans up all resources and scheduler configuration. | ||
func (s *Service) Reset(ctx context.Context) error { | ||
lopts := metav1.ListOptions{ |
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 not needed. Just passing emptyListOpts to all services should be enough.
@sivchari /kind api-change |
reset/reset.go
Outdated
type Service struct { | ||
client clientset.Interface | ||
nodeService NodeService | ||
pvService PersistentVolumeService | ||
pvcService PersistentVolumeClaimService | ||
scSerivce StorageClassService | ||
pcService PriorityClassService | ||
schedService SchedulerService | ||
} |
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.
With this change, the field will be like this:
type Service struct { | |
client clientset.Interface | |
nodeService NodeService | |
pvService PersistentVolumeService | |
pvcService PersistentVolumeClaimService | |
scSerivce StorageClassService | |
pcService PriorityClassService | |
schedService SchedulerService | |
} | |
type Service struct { | |
client clientset.Interface | |
// deleteServices has the all services for each resource. | |
// key: service name. | |
deleteServices map[string]DeleteService | |
schedService SchedulerService | |
} |
Thank ! |
reset/reset.go
Outdated
emptyListOpts := metav1.ListOptions{} | ||
for _, ds := range s.deleteServices { | ||
if err := ds.DeleteCollection(ctx, emptyListOpts); err != nil { | ||
return 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.
Please wrap error with deleteServices's key. Like:
xerrors.Errorf("delete all %s: %w", key, err)
reset/reset.go
Outdated
// We need emptyListOpts to satisfy interface. | ||
emptyListOpts := metav1.ListOptions{} | ||
for _, ds := range s.deleteServices { | ||
if err := ds.DeleteCollection(ctx, emptyListOpts); err != 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.
Do it in parallel with error group
reset/reset.go
Outdated
// We need emptyListOpts to satisfy interface. | ||
emptyListOpts := metav1.ListOptions{} |
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 can just remove this emptyListOpts
.
reset/reset.go
Outdated
return err | ||
} | ||
} | ||
return s.schedService.ResetScheduler() |
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.
Please wrap error as well
server/di/di.go
Outdated
@@ -46,6 +48,15 @@ func NewDIContainer(client clientset.Interface, restclientCfg *restclient.Config | |||
|
|||
c.priorityClassService = priorityclass.NewPriorityClassService(client) | |||
c.exportService = export.NewExportService(client, c.podService, c.nodeService, c.pvService, c.pvcService, c.storageClassService, c.priorityClassService, c.schedulerService) | |||
|
|||
servicem := map[string]reset.DeleteService{ | |||
"node": c.nodeService, |
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.
You miss pod service maybe?
server/di/di.go
Outdated
@@ -46,6 +48,15 @@ func NewDIContainer(client clientset.Interface, restclientCfg *restclient.Config | |||
|
|||
c.priorityClassService = priorityclass.NewPriorityClassService(client) | |||
c.exportService = export.NewExportService(client, c.podService, c.nodeService, c.pvService, c.pvcService, c.storageClassService, c.priorityClassService, c.schedulerService) | |||
|
|||
servicem := map[string]reset.DeleteService{ |
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:
servicem := map[string]reset.DeleteService{ | |
deleteServices := map[string]reset.DeleteService{ |
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.
Sorry, one more nits 🙏 Looks good otherwise.
server/di/di.go
Outdated
"pv": c.pvService, | ||
"pvc": c.pvcService, | ||
"sc": c.storageClassService, | ||
"pc": c.priorityClassService, |
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 change it to use the full names of resources for better loggings? (like "Persistent volume")
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.
sorry, "one more nits" again.. 🤦♂️
docs/api.md
Outdated
|
||
restart scheduler with default configuration. | ||
clean up all resources and scheduler configuration. |
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.
clean up all resources and scheduler configuration. | |
clean up all resources and restore the initial scheduler configuration. | |
(If you didn't pass the initial scheduler configuration via `KUBE_SCHEDULER_CONFIG_PATH`, the default scheduler configuration will be restored.) |
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.
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 reset service to reset resources.
Which issue(s) this PR fixes:
Fixes #26
Special notes for your reviewer:
/label tide/merge-method-squash