diff --git a/k8s/pkg/schedulers/scheduling_strategy.go b/k8s/pkg/schedulers/scheduling_strategy.go index b8c8c0b7..553bc386 100644 --- a/k8s/pkg/schedulers/scheduling_strategy.go +++ b/k8s/pkg/schedulers/scheduling_strategy.go @@ -121,9 +121,18 @@ func (b *BestEffortStrategy) TrackingChunksByCRD() *BestEffortStrategy { _ = multierr.Append(errList, err) } - // if there is no local objects, return error - if len(localObjects) == 0 && len(globalObjects) != 0 { - _ = multierr.Append(errList, errors.Errorf("No local chunks found")) + if len(localObjects) == 0 { + if len(globalObjects) == 0 { + localObjects, err = b.GetLocalObjectsByID(b.required) + // if there is no local objects, return error + if err != nil { + _ = multierr.Append(errList, err) + } + } else { + // if there is no local objects, return error + _ = multierr.Append(errList, errors.Errorf("Failed to get local objects")) + } + } if errList != nil { @@ -335,6 +344,28 @@ func (b *BestEffortStrategy) GetGlobalObjectsByID( return objects, nil } +// GetLocalObjectsByID returns the local objects by the given jobname. +func (b *BestEffortStrategy) GetLocalObjectsByID( + jobNames []string, +) ([]*v1alpha1.LocalObject, error) { + requiredJobs := make(map[string]bool) + for _, n := range jobNames { + requiredJobs[n] = true + } + objects := []*v1alpha1.LocalObject{} + localObjects := &v1alpha1.LocalObjectList{} + if err := b.List(context.TODO(), localObjects); err != nil { + return nil, err + } + for i, obj := range localObjects.Items { + if jobname, exist := obj.Labels[labels.VineyardObjectJobLabel]; exist && requiredJobs[jobname] { + objects = append(objects, &localObjects.Items[i]) + } + } + + return objects, nil +} + // CreateConfigmapForID creates a configmap for the object id and the nodes. func (b *BestEffortStrategy) CreateConfigmapForID( jobname []string, diff --git a/k8s/test/e2e/kind-with-local-registry.yaml b/k8s/test/e2e/kind-with-local-registry.yaml index 037ecbdf..0184c687 100644 --- a/k8s/test/e2e/kind-with-local-registry.yaml +++ b/k8s/test/e2e/kind-with-local-registry.yaml @@ -6,10 +6,10 @@ containerdConfigPatches: endpoint = ["http://kind-registry:5000"] nodes: - role: control-plane - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 \ No newline at end of file + image: kindest/node:v1.25.11 \ No newline at end of file diff --git a/k8s/test/e2e/kind.yaml b/k8s/test/e2e/kind.yaml index 86c5f143..d9275d68 100644 --- a/k8s/test/e2e/kind.yaml +++ b/k8s/test/e2e/kind.yaml @@ -17,10 +17,10 @@ kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11 - role: worker - image: kindest/node:v1.24.0 + image: kindest/node:v1.25.11