Skip to content

Commit d8d4db5

Browse files
committed
Remove Slice finalizer, once all Pods in the Workload have gracefully terminated.
1 parent 4f00dab commit d8d4db5

File tree

14 files changed

+1329
-88
lines changed

14 files changed

+1329
-88
lines changed

slice/cmd/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,18 @@ func main() {
232232
}
233233
}
234234

235+
ctx := ctrl.SetupSignalHandler()
236+
if err := controller.SetupWorkloadIndexer(ctx, mgr.GetFieldIndexer()); err != nil {
237+
setupLog.Error(err, "unable to setup indexes")
238+
os.Exit(1)
239+
}
240+
235241
go setupControllers(mgr, certsReady)
236242

237243
setupProbeEndpoints(mgr, certsReady)
238244

239245
setupLog.Info("starting manager")
240-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
246+
if err := mgr.Start(ctx); err != nil {
241247
setupLog.Error(err, "problem running manager")
242248
os.Exit(1)
243249
}

slice/config/rbac/role.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ rules:
1313
- patch
1414
- update
1515
- watch
16+
- apiGroups:
17+
- ""
18+
resources:
19+
- pods
20+
verbs:
21+
- get
22+
- list
23+
- watch
1624
- apiGroups:
1725
- ""
1826
resources:
@@ -31,6 +39,14 @@ rules:
3139
- list
3240
- update
3341
- watch
42+
- apiGroups:
43+
- jobset.x-k8s.io
44+
resources:
45+
- jobsets
46+
verbs:
47+
- get
48+
- list
49+
- watch
3450
- apiGroups:
3551
- kueue.x-k8s.io
3652
resources:

slice/internal/controller/indexer.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
26+
27+
"tpu-slice-controller/internal/util/slices"
28+
)
29+
30+
const (
31+
OwnerReferenceUID = "metadata.ownerReferences.uid"
32+
)
33+
34+
// SetupWorkloadIndexer configures the indexer to index specific fields for kueue.Workload resources.
35+
func SetupWorkloadIndexer(ctx context.Context, indexer client.FieldIndexer) error {
36+
if err := indexer.IndexField(ctx, &kueue.Workload{}, OwnerReferenceUID, func(obj client.Object) []string {
37+
return slices.Map(obj.GetOwnerReferences(), func(o *metav1.OwnerReference) string { return string(o.UID) })
38+
}); err != nil {
39+
return fmt.Errorf("setting index on ownerReferences.uid for Workload: %w", err)
40+
}
41+
return nil
42+
}

0 commit comments

Comments
 (0)