Skip to content

Commit

Permalink
Fix clusterInfoSnapshot may be nil it will caused painc
Browse files Browse the repository at this point in the history
Signed-off-by: mathlsj <mathlsj@outlook.com>
  • Loading branch information
mathlsj committed Oct 17, 2022
1 parent 93817a9 commit 4c39d8d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,13 +42,14 @@ 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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/core/generic_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, placement *policyv1alph
return result, fmt.Errorf("no clusters available to schedule")
}

feasibleClusters, diagnosis, err := g.findClustersThatFit(ctx, g.scheduleFramework, placement, spec, clusterInfoSnapshot)
feasibleClusters, diagnosis, err := g.findClustersThatFit(ctx, g.scheduleFramework, placement, spec, &clusterInfoSnapshot)
if err != nil {
return result, fmt.Errorf("failed to findClustersThatFit: %v", err)
}
Expand Down

0 comments on commit 4c39d8d

Please sign in to comment.