Skip to content

Commit 91c16b1

Browse files
committed
Create Slice for each PodSet in Workload.
1 parent 9c1c13b commit 91c16b1

File tree

13 files changed

+906
-152
lines changed

13 files changed

+906
-152
lines changed

slice/api/v1alpha1/slice_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import (
2626
type SliceSpec struct {
2727
// AcceleratorType specifies the type of accelerator used in this slice.
2828
// +kubebuilder:validation:Immutable
29+
// +kubebuilder:validation:Required
2930
AcceleratorType string `json:"acceleratorType"`
3031

3132
// Topology represents the network topology of the slice.
3233
// +kubebuilder:validation:Immutable
34+
// +kubebuilder:validation:Required
3335
AcceleratorTopology string `json:"acceleratorTopology"`
3436

3537
// Required, set of nodes to use to form a slice.

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.SetupIndexer(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/hack/kind-cluster.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ nodes:
2424
- role: worker
2525
labels:
2626
instance-type: on-demand
27+
cloud.google.com/gke-tpu-topology: 2x2x2
28+
cloud.google.com/gke-tpu-accelerator: tpu-v4-podslice
29+
cloud.google.com/gke-tpu-reservation-subblock: tpu-subblock-1
2730
- role: worker
2831
labels:
29-
instance-type: spot
30-
32+
instance-type: on-demand
33+
cloud.google.com/gke-tpu-topology: 2x2x2
34+
cloud.google.com/gke-tpu-accelerator: tpu-v4-podslice
35+
cloud.google.com/gke-nodepool: tpu-v4-pool
3136
kubeadmConfigPatches:
3237
- |
3338
kind: JoinConfiguration

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+
// SetupIndexer sets the index with the given fields for core apis.
39+
func SetupIndexer(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)