Skip to content

Commit 1734b23

Browse files
committed
Update Torrent API and add tests
Signed-off-by: kerthcet <[email protected]>
1 parent 54fa28b commit 1734b23

17 files changed

+489
-50
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: CI Workflow
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
golang-ci:
11+
# Use a released version for stable.
12+
uses: kerthcet/github-workflow-as-kube/.github/workflows/[email protected]

api/v1alpha1/nodetracker_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
// NodeTrackerSpec defines the desired state of NodeTracker
2424
// It acts like a cache.
2525
type NodeTrackerSpec struct {
26-
NodeName string `json:"nodeName"`
26+
// TODO: GC disk rate.
2727
}
2828

2929
// NodeTrackerStatus defines the observed state of NodeTracker

api/v1alpha1/torrent_types.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import (
2323
// This is inspired by https://github.com/InftyAI/llmaz.
2424
// ModelHub represents the model registry for model downloads.
2525
type ModelHub struct {
26+
// TODO: support ModelScope
2627
// Name refers to the model registry, such as huggingface.
2728
// +kubebuilder:default=Huggingface
28-
// +kubebuilder:validation:Enum={Huggingface,ModelScope}
29+
// +kubebuilder:validation:Enum={Huggingface}
2930
// +optional
3031
Name *string `json:"name,omitempty"`
3132
// ModelID refers to the model identifier on model hub,
@@ -37,15 +38,26 @@ type ModelHub struct {
3738
// TODO: this is only supported with Huggingface, add support for ModelScope
3839
// in the near future.
3940
Filename *string `json:"filename,omitempty"`
41+
42+
// TODO: not supported
4043
// Revision refers to a Git revision id which can be a branch name, a tag, or a commit hash.
4144
// Most of the time, you don't need to specify it.
4245
// +optional
43-
Revision *string `json:"revision,omitempty"`
46+
// Revision *string `json:"revision,omitempty"`
4447
}
4548

4649
// URIProtocol represents the protocol of the URI.
4750
type URIProtocol string
4851

52+
type ReclaimPolicy string
53+
54+
const (
55+
// RetainReclaimPolicy represents keep the files when Torrent is deleted.
56+
RetainReclaimPolicy ReclaimPolicy = "Retain"
57+
// DeleteReclaimPolicy represents delete the files when Torrent is deleted.
58+
DeleteReclaimPolicy ReclaimPolicy = "Delete"
59+
)
60+
4961
// TorrentSpec defines the desired state of Torrent
5062
type TorrentSpec struct {
5163
// ModelHub represents the model registry for model downloads.
@@ -58,29 +70,45 @@ type TorrentSpec struct {
5870
// - Image: img://nginx:1.14.2
5971
// - OSS: oss://<bucket>.<endpoint>/<path-to-your-files>
6072
// +optional
61-
// URI *URIProtocol `json:"uriuri,omitempty"`
73+
// URI *URIProtocol `json:"uri,omitempty"`
6274

6375
// Replicas represents the replication number of each file.
6476
// +kubebuilder:default=1
6577
// +optional
66-
Replicas *int32 ` json:"replicas,omitempty"`
78+
Replicas *int32 `json:"replicas,omitempty"`
79+
// ReclaimPolicy represents how to handle the file replicas when Torrent is deleted.
80+
// +kubebuilder:default=Retain
81+
// +kubebuilder:validation:Enum={Retain,Delete}
82+
// +optional
83+
ReclaimPolicy *ReclaimPolicy `json:"reclaimPolicy,omitempty"`
84+
// NodeSelector represents the node constraint to download the chunks.
85+
// It can be used to download the model to one node for special case.
86+
// +optional
87+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
6788
}
6889

6990
type TrackerState string
7091

7192
const (
93+
PendingTrackerState TrackerState = "Pending"
7294
DownloadTrackerState TrackerState = "Downloading"
7395
ReadyTrackerState TrackerState = "Ready"
7496
)
7597

7698
type FileTracker struct {
7799
// Name represents the name of the file.
78100
Name string `json:"name"`
79-
// State represents the state of the file, whether Pending
80-
// for download or downloaded ready.
101+
// State represents the state of the file, whether in downloading
102+
// or downloaded ready.
81103
State TrackerState `json:"State"`
82104
// SizeBytes represents the file size.
83-
SizeBytes int64 `json:"sizeBytes"`
105+
// This is only used in nodeTracker.
106+
// +optional
107+
SizeBytes *int64 `json:"sizeBytes,omitempty"`
108+
// Path represents the absolute path of the file in the node.
109+
// This is only used in nodeTracker.
110+
// +optional
111+
Path *string `json:"path,omitempty"`
84112
}
85113

86114
const (

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/manta.io_nodetrackers.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ spec:
4040
description: |-
4141
NodeTrackerSpec defines the desired state of NodeTracker
4242
It acts like a cache.
43-
properties:
44-
nodeName:
45-
type: string
46-
required:
47-
- nodeName
4843
type: object
4944
status:
5045
description: NodeTrackerStatus defines the observed state of NodeTracker
@@ -54,20 +49,26 @@ spec:
5449
properties:
5550
State:
5651
description: |-
57-
State represents the state of the file, whether Pending
58-
for download or downloaded ready.
52+
State represents the state of the file, whether in downloading
53+
or downloaded ready.
5954
type: string
6055
name:
6156
description: Name represents the name of the file.
6257
type: string
58+
path:
59+
description: |-
60+
Path represents the absolute path of the file in the node.
61+
This is only used in nodeTracker.
62+
type: string
6363
sizeBytes:
64-
description: SizeBytes represents the file size.
64+
description: |-
65+
SizeBytes represents the file size.
66+
This is only used in nodeTracker.
6567
format: int64
6668
type: integer
6769
required:
6870
- State
6971
- name
70-
- sizeBytes
7172
type: object
7273
type: array
7374
type: object

config/crd/bases/manta.io_torrents.yaml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,25 @@ spec:
6161
description: Name refers to the model registry, such as huggingface.
6262
enum:
6363
- Huggingface
64-
- ModelScope
65-
type: string
66-
revision:
67-
description: |-
68-
Revision refers to a Git revision id which can be a branch name, a tag, or a commit hash.
69-
Most of the time, you don't need to specify it.
7064
type: string
7165
required:
7266
- modelID
7367
type: object
68+
nodeSelector:
69+
additionalProperties:
70+
type: string
71+
description: |-
72+
NodeSelector represents the node constraint to download the chunks.
73+
It can be used to download the model to one node for special case.
74+
type: object
75+
reclaimPolicy:
76+
default: Retain
77+
description: ReclaimPolicy represents how to handle the file replicas
78+
when Torrent is deleted.
79+
enum:
80+
- Retain
81+
- Delete
82+
type: string
7483
replicas:
7584
default: 1
7685
description: Replicas represents the replication number of each file.
@@ -143,20 +152,26 @@ spec:
143152
properties:
144153
State:
145154
description: |-
146-
State represents the state of the file, whether Pending
147-
for download or downloaded ready.
155+
State represents the state of the file, whether in downloading
156+
or downloaded ready.
148157
type: string
149158
name:
150159
description: Name represents the name of the file.
151160
type: string
161+
path:
162+
description: |-
163+
Path represents the absolute path of the file in the node.
164+
This is only used in nodeTracker.
165+
type: string
152166
sizeBytes:
153-
description: SizeBytes represents the file size.
167+
description: |-
168+
SizeBytes represents the file size.
169+
This is only used in nodeTracker.
154170
format: int64
155171
type: integer
156172
required:
157173
- State
158174
- name
159-
- sizeBytes
160175
type: object
161176
type: array
162177
type: object

pkg/controller/nodetracker_controller.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,24 @@ import (
2121

2222
"k8s.io/apimachinery/pkg/runtime"
2323
ctrl "sigs.k8s.io/controller-runtime"
24+
"sigs.k8s.io/controller-runtime/pkg/cache"
2425
"sigs.k8s.io/controller-runtime/pkg/client"
2526
"sigs.k8s.io/controller-runtime/pkg/log"
2627

27-
inftyaicomv1alpha1 "github.com/inftyai/manta/api/v1alpha1"
28+
api "github.com/inftyai/manta/api/v1alpha1"
2829
)
2930

3031
// NodeTrackerReconciler reconciles a NodeTracker object
3132
type NodeTrackerReconciler struct {
3233
client.Client
3334
Scheme *runtime.Scheme
35+
Cache cache.Cache
3436
}
3537

3638
//+kubebuilder:rbac:groups=manta.io,resources=nodetrackers,verbs=get;list;watch;create;update;patch;delete
3739
//+kubebuilder:rbac:groups=manta.io,resources=nodetrackers/status,verbs=get;update;patch
3840
//+kubebuilder:rbac:groups=manta.io,resources=nodetrackers/finalizers,verbs=update
3941

40-
// Reconcile is part of the main kubernetes reconciliation loop which aims to
41-
// move the current state of the cluster closer to the desired state.
42-
// TODO(user): Modify the Reconcile function to compare the state specified by
43-
// the NodeTracker object against the actual cluster state, and then
44-
// perform operations to make the cluster state reflect the state specified by
45-
// the user.
46-
//
4742
// For more details, check Reconcile and its Result here:
4843
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4944
func (r *NodeTrackerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -57,6 +52,6 @@ func (r *NodeTrackerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5752
// SetupWithManager sets up the controller with the Manager.
5853
func (r *NodeTrackerReconciler) SetupWithManager(mgr ctrl.Manager) error {
5954
return ctrl.NewControllerManagedBy(mgr).
60-
For(&inftyaicomv1alpha1.NodeTracker{}).
55+
For(&api.NodeTracker{}).
6156
Complete(r)
6257
}

pkg/controller/replication_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"k8s.io/apimachinery/pkg/runtime"
2323
ctrl "sigs.k8s.io/controller-runtime"
2424
"sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/controller"
2526
"sigs.k8s.io/controller-runtime/pkg/log"
2627

2728
inftyaicomv1alpha1 "github.com/inftyai/manta/api/v1alpha1"
@@ -58,5 +59,6 @@ func (r *ReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5859
func (r *ReplicationReconciler) SetupWithManager(mgr ctrl.Manager) error {
5960
return ctrl.NewControllerManagedBy(mgr).
6061
For(&inftyaicomv1alpha1.Replication{}).
62+
WithOptions(controller.Options{MaxConcurrentReconciles: 5}).
6163
Complete(r)
6264
}

0 commit comments

Comments
 (0)