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 reset service #105

Merged
merged 17 commits into from
Feb 14, 2022

Conversation

sivchari
Copy link
Member

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

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 11, 2022
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 11, 2022
@sivchari
Copy link
Member Author

/assign @sanposhiho

@sanposhiho
Copy link
Member

/assign
/ok-to-test
/retitle Add reset service

@k8s-ci-robot k8s-ci-robot changed the title Feature add reset method Add reset service Feb 12, 2022
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2022
Copy link
Member

@sanposhiho sanposhiho left a 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 {
Copy link
Member

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
Comment on lines 10 to 28
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
}
Copy link
Member

@sanposhiho sanposhiho Feb 12, 2022

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{
Copy link
Member

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.

@sanposhiho
Copy link
Member

@sivchari
Could you add the brief doc to this api.md?
https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/docs/api.md

/kind api-change

@k8s-ci-robot k8s-ci-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Feb 12, 2022
reset/reset.go Outdated
Comment on lines 35 to 43
type Service struct {
client clientset.Interface
nodeService NodeService
pvService PersistentVolumeService
pvcService PersistentVolumeClaimService
scSerivce StorageClassService
pcService PriorityClassService
schedService SchedulerService
}
Copy link
Member

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:

Suggested change
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
}

@sivchari
Copy link
Member Author

Thank !

reset/reset.go Outdated
emptyListOpts := metav1.ListOptions{}
for _, ds := range s.deleteServices {
if err := ds.DeleteCollection(ctx, emptyListOpts); err != nil {
return err
Copy link
Member

@sanposhiho sanposhiho Feb 12, 2022

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 {
Copy link
Member

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
Comment on lines 42 to 43
// We need emptyListOpts to satisfy interface.
emptyListOpts := metav1.ListOptions{}
Copy link
Member

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

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,
Copy link
Member

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{
Copy link
Member

@sanposhiho sanposhiho Feb 12, 2022

Choose a reason for hiding this comment

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

nits:

Suggested change
servicem := map[string]reset.DeleteService{
deleteServices := map[string]reset.DeleteService{

@sivchari
Copy link
Member Author

I fixed it :)

Copy link
Member

@sanposhiho sanposhiho left a 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
Comment on lines 55 to 58
"pv": c.pvService,
"pvc": c.pvcService,
"sc": c.storageClassService,
"pc": c.priorityClassService,
Copy link
Member

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")

Copy link
Member

@sanposhiho sanposhiho left a 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.
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
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.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I fixed it.

Copy link
Member

@sanposhiho sanposhiho left a comment

Choose a reason for hiding this comment

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

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 14, 2022
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 14, 2022
@k8s-ci-robot k8s-ci-robot merged commit fc420bc into kubernetes-sigs:master Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add reset button to reset all resources and scheduler configuration
3 participants