Skip to content

Commit faaacef

Browse files
committed
Create Slice for each PodSet in Workload.
1 parent 4f00dab commit faaacef

File tree

10 files changed

+738
-110
lines changed

10 files changed

+738
-110
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.SetupSliceIndexer(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/internal/controller/indexer.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
26+
"tpu-slice-controller/api/v1alpha1"
27+
"tpu-slice-controller/internal/util/slices"
28+
)
29+
30+
const (
31+
OwnerReferenceUID = "metadata.ownerReferences.uid"
32+
)
33+
34+
func indexOwnerReferenceUID(obj client.Object) []string {
35+
return slices.Map(obj.GetOwnerReferences(), func(o *metav1.OwnerReference) string { return string(o.UID) })
36+
}
37+
38+
// SetupSliceIndexer configures the indexer to index specific fields for v1alpha1.Slice resources.
39+
func SetupSliceIndexer(ctx context.Context, indexer client.FieldIndexer) error {
40+
if err := indexer.IndexField(ctx, &v1alpha1.Slice{}, OwnerReferenceUID, indexOwnerReferenceUID); err != nil {
41+
return fmt.Errorf("setting index on ownerReferences.uid for Slice: %w", err)
42+
}
43+
return nil
44+
}

0 commit comments

Comments
 (0)