-
Notifications
You must be signed in to change notification settings - Fork 900
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
Fix clusterInfoSnapshot may be nil it will caused painc #2645
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2645 +/- ##
==========================================
- Coverage 23.81% 23.70% -0.12%
==========================================
Files 184 184
Lines 18502 18505 +3
==========================================
- Hits 4407 4387 -20
- Misses 13749 13770 +21
- Partials 346 348 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
/lgtm |
@jwcesign: changing LGTM is restricted to collaborators In response to this:
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. |
Given the diff --git a/pkg/scheduler/cache/cache.go b/pkg/scheduler/cache/cache.go
index ecd8b335..c221e781 100644
--- a/pkg/scheduler/cache/cache.go
+++ b/pkg/scheduler/cache/cache.go
@@ -15,7 +15,7 @@ type Cache interface {
UpdateCluster(cluster *clusterv1alpha1.Cluster)
DeleteCluster(cluster *clusterv1alpha1.Cluster)
// Snapshot returns a snapshot of the current clusters info
- Snapshot() *Snapshot
+ Snapshot() Snapshot
}
type schedulerCache struct {
@@ -42,13 +42,15 @@ func (c *schedulerCache) DeleteCluster(cluster *clusterv1alpha1.Cluster) {
}
// TODO: need optimization, only clone when necessary
-func (c *schedulerCache) Snapshot() *Snapshot {
+func (c *schedulerCache) Snapshot() Snapshot {
+ out := NewEmptySnapshot()
+
clusters, err := c.clusterLister.List(labels.Everything())
if err != nil {
klog.Errorf("Failed to list clusters: %v", err)
- return nil
+ return out
}
- out := NewEmptySnapshot()
+
out.clusterInfoList = make([]*framework.ClusterInfo, 0, len(clusters))
for _, cluster := range clusters {
cloned := cluster.DeepCopy()
diff --git a/pkg/scheduler/cache/snapshot.go b/pkg/scheduler/cache/snapshot.go
index 7b9c3b84..2bc5e319 100644
--- a/pkg/scheduler/cache/snapshot.go
+++ b/pkg/scheduler/cache/snapshot.go
@@ -15,8 +15,8 @@ type Snapshot struct {
}
// NewEmptySnapshot initializes a Snapshot struct and returns it.
-func NewEmptySnapshot() *Snapshot {
- return &Snapshot{}
+func NewEmptySnapshot() Snapshot {
+ return Snapshot{}
}
// NumOfClusters returns the number of clusters.
|
Signed-off-by: mathlsj <mathlsj@outlook.com>
@RainbowMango Update |
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango 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 |
Signed-off-by: mathlsj mathlsj@outlook.com
What type of PR is this?
Fix clusterInfoSnapshot may be nil it will caused painc
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: