Skip to content

Commit

Permalink
TAS: TopologyUngater (kubernetes-sigs#3266)
Browse files Browse the repository at this point in the history
* TAS: TopologyUngater

# Conflicts:
#	go.mod

* review comments
  • Loading branch information
mimowo authored and PBundyra committed Nov 5, 2024
1 parent 498bd49 commit 5bb03b1
Show file tree
Hide file tree
Showing 10 changed files with 1,440 additions and 5 deletions.
15 changes: 15 additions & 0 deletions cmd/kueue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"sigs.k8s.io/kueue/pkg/controller/core"
"sigs.k8s.io/kueue/pkg/controller/core/indexer"
"sigs.k8s.io/kueue/pkg/controller/jobframework"
"sigs.k8s.io/kueue/pkg/controller/tas"
"sigs.k8s.io/kueue/pkg/debugger"
"sigs.k8s.io/kueue/pkg/features"
"sigs.k8s.io/kueue/pkg/metrics"
Expand Down Expand Up @@ -216,6 +217,13 @@ func setupIndexes(ctx context.Context, mgr ctrl.Manager, cfg *configapi.Configur
}
}

if features.Enabled(features.TopologyAwareScheduling) {
if err := tas.SetupIndexes(ctx, mgr.GetFieldIndexer()); err != nil {
setupLog.Error(err, "Could not setup TAS indexer")
os.Exit(1)
}
}

if features.Enabled(features.MultiKueue) {
if err := multikueue.SetupIndexer(ctx, mgr.GetFieldIndexer(), *cfg.Namespace); err != nil {
setupLog.Error(err, "Could not setup multikueue indexer")
Expand Down Expand Up @@ -265,6 +273,13 @@ func setupControllers(ctx context.Context, mgr ctrl.Manager, cCache *cache.Cache
}
}

if features.Enabled(features.TopologyAwareScheduling) {
if failedCtrl, err := tas.SetupControllers(mgr, queues, cCache, cfg); err != nil {
setupLog.Error(err, "Could not setup TAS controller", "controller", failedCtrl)
os.Exit(1)
}
}

if failedWebhook, err := webhooks.Setup(mgr); err != nil {
setupLog.Error(err, "Unable to create webhook", "webhook", failedWebhook)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/json-iterator/go v1.1.12
github.com/kubeflow/mpi-operator v0.6.0
github.com/kubeflow/training-operator v1.8.1
github.com/onsi/ginkgo/v2 v2.20.2
Expand Down Expand Up @@ -80,7 +81,6 @@ require (
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/tas/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tas

const (
TASTopologyUngater = "tas-topology-ungater"
)
33 changes: 33 additions & 0 deletions pkg/controller/tas/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tas

import (
ctrl "sigs.k8s.io/controller-runtime"

configapi "sigs.k8s.io/kueue/apis/config/v1beta1"
"sigs.k8s.io/kueue/pkg/cache"
"sigs.k8s.io/kueue/pkg/queue"
)

func SetupControllers(mgr ctrl.Manager, queues *queue.Manager, cache *cache.Cache, cfg *configapi.Configuration) (string, error) {
topologyUngater := newTopologyUngater(mgr.GetClient())
if ctrlName, err := topologyUngater.setupWithManager(mgr, cfg); err != nil {
return ctrlName, err
}
return "", nil
}
44 changes: 44 additions & 0 deletions pkg/controller/tas/indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tas

import (
"context"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

kueuealpha "sigs.k8s.io/kueue/apis/kueue/v1alpha1"
)

const (
workloadNameKey = "metadata.workload"
)

func SetupIndexes(ctx context.Context, indexer client.FieldIndexer) error {
return indexer.IndexField(ctx, &corev1.Pod{}, workloadNameKey, func(o client.Object) []string {
pod, ok := o.(*corev1.Pod)
if !ok {
return nil
}
value, found := pod.Annotations[kueuealpha.WorkloadAnnotation]
if !found {
return nil
}
return []string{value}
})
}
Loading

0 comments on commit 5bb03b1

Please sign in to comment.