Fix clusterInfoSnapshot may be nil it will caused painc
Signed-off-by: mathlsj <mathlsj@outlook.com>
This commit is contained in:
parent
93817a9a58
commit
4c39d8deec
|
@ -15,7 +15,7 @@ type Cache interface {
|
||||||
UpdateCluster(cluster *clusterv1alpha1.Cluster)
|
UpdateCluster(cluster *clusterv1alpha1.Cluster)
|
||||||
DeleteCluster(cluster *clusterv1alpha1.Cluster)
|
DeleteCluster(cluster *clusterv1alpha1.Cluster)
|
||||||
// Snapshot returns a snapshot of the current clusters info
|
// Snapshot returns a snapshot of the current clusters info
|
||||||
Snapshot() *Snapshot
|
Snapshot() Snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
type schedulerCache struct {
|
type schedulerCache struct {
|
||||||
|
@ -42,13 +42,14 @@ func (c *schedulerCache) DeleteCluster(cluster *clusterv1alpha1.Cluster) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need optimization, only clone when necessary
|
// 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())
|
clusters, err := c.clusterLister.List(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to list clusters: %v", err)
|
klog.Errorf("Failed to list clusters: %v", err)
|
||||||
return nil
|
return out
|
||||||
}
|
}
|
||||||
out := NewEmptySnapshot()
|
|
||||||
out.clusterInfoList = make([]*framework.ClusterInfo, 0, len(clusters))
|
out.clusterInfoList = make([]*framework.ClusterInfo, 0, len(clusters))
|
||||||
for _, cluster := range clusters {
|
for _, cluster := range clusters {
|
||||||
cloned := cluster.DeepCopy()
|
cloned := cluster.DeepCopy()
|
||||||
|
|
|
@ -15,8 +15,8 @@ type Snapshot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEmptySnapshot initializes a Snapshot struct and returns it.
|
// NewEmptySnapshot initializes a Snapshot struct and returns it.
|
||||||
func NewEmptySnapshot() *Snapshot {
|
func NewEmptySnapshot() Snapshot {
|
||||||
return &Snapshot{}
|
return Snapshot{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NumOfClusters returns the number of clusters.
|
// NumOfClusters returns the number of clusters.
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, placement *policyv1alph
|
||||||
return result, fmt.Errorf("no clusters available to schedule")
|
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 {
|
if err != nil {
|
||||||
return result, fmt.Errorf("failed to findClustersThatFit: %v", err)
|
return result, fmt.Errorf("failed to findClustersThatFit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue