Skip to content

Commit

Permalink
[1/N] Implement controller
Browse files Browse the repository at this point in the history
Signed-off-by: kerthcet <[email protected]>
  • Loading branch information
kerthcet committed Sep 28, 2024
1 parent 8ad598a commit a701c53
Show file tree
Hide file tree
Showing 37 changed files with 1,271 additions and 408 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ARG BASE_IMAGE
ARG BUILDER_IMAGE

# Build the manager binary
FROM golang:1.20 as builder
FROM ${BUILDER_IMAGE} as builder
ARG TARGETOS
ARG TARGETARCH

Expand All @@ -14,7 +17,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY pkg/controller/ pkg/controller/
COPY pkg/ pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand All @@ -25,7 +28,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
FROM ${BASE_IMAGE}
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2024.
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.
*/

// +kubebuilder:object:generate=true
// +groupName=manta.io

package v1alpha1
2 changes: 1 addition & 1 deletion api/v1alpha1/nodetracker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type NodeTrackerSpec struct {

// NodeTrackerStatus defines the observed state of NodeTracker
type NodeTrackerStatus struct {
Files []FileTracker `json:"files,omitempty"`
// Files []FileTracker `json:"files,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
22 changes: 14 additions & 8 deletions api/v1alpha1/replication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ import (
// Source couldn't be nil, but if destination is nil,
// it means to delete the file.
type Target struct {
// FileName represents the target file name.
FileName string `json:"filename"`
// Path represents the location of the file in source or
// the location where to put the file in destination.
Path string `json:"path"`
// ChunkName represents the target chunk name.
ChunkName string `json:"chunkName"`
// TODO
// Address represents the communication address of the Pod.
Address *string `json:"Address"`
// +optional
Address *string `json:"address,omitempty"`
}

// ReplicationSpec defines the desired state of Replication
type ReplicationSpec struct {
// Tuple represents a pair of source and destination.
type Tuple struct {
// Source represents the source file.
// Source couldn't be nil.
Source Target `json:"source"`
Expand All @@ -43,6 +42,13 @@ type ReplicationSpec struct {
Destination *Target `json:"destination,omitempty"`
}

// ReplicationSpec defines the desired state of Replication
type ReplicationSpec struct {
// Tuples represents a slice of tuples.
// +optional
Tuples []Tuple `json:"tuples,omitempty"`
}

type ReplicateState string

const (
Expand Down
58 changes: 41 additions & 17 deletions api/v1alpha1/torrent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ type ModelHub struct {
// TODO: this is only supported with Huggingface, add support for ModelScope
// in the near future.
Filename *string `json:"filename,omitempty"`

// TODO: not supported
// Revision refers to a Git revision id which can be a branch name, a tag, or a commit hash.
// Most of the time, you don't need to specify it.
// +kubebuilder:default=main
// +optional
// Revision *string `json:"revision,omitempty"`
Revision *string `json:"revision,omitempty"`
}

// URIProtocol represents the protocol of the URI.
Expand Down Expand Up @@ -95,23 +93,49 @@ const (
ReadyTrackerState TrackerState = "Ready"
)

type FileTracker struct {
// Name represents the name of the file.
type ChunkStatus struct {
// Name represents the name of the chunk. It's a hashed value.
Name string `json:"name"`
// State represents the state of the file, whether in downloading
// State represents the state of the chunk, whether in downloading
// or downloaded ready.
State TrackerState `json:"State"`
// SizeBytes represents the file size.
// This is only used in nodeTracker.
// +optional
SizeBytes *int64 `json:"sizeBytes,omitempty"`
// Path represents the absolute path of the file in the node.
// This is only used in nodeTracker.
State TrackerState `json:"state"`
// SizeBytes represents the chunk size.
SizeBytes int64 `json:"sizeBytes"`
}

type ObjectType string

const (
FileObjectType ObjectType = "file"
DirectoryObjectType ObjectType = "directory"
)

// ObjectStatus tracks the object info.
type ObjectStatus struct {
// Path represents the path of the object.
Path string `json:"path"`
// Chunks represents the whole chunks which makes up the object.
Chunks []*ChunkStatus `json:"chunks,omitempty"`
// Type represents the object type, limits to file or directory.
// +kubebuilder:validation:Enum={file,directory}
Type ObjectType `json:"type"`

// TODO: for embedding files.
// Objects []ObjectStatus `json:"objects,omitempty"`
}

type RepoStatus struct {
// RepoName represents the repo name of the file,
// it could be nil once the file has no repo.
// +optional
Path *string `json:"path,omitempty"`
Name *string `json:"name,omitempty"`
// Objects represents the whole objects belongs to the repo.
Objects []*ObjectStatus `json:"objects,omitempty"`
}

const (
// PendingConditionType represents the Torrent is Pending.
PendingConditionType = string(PendingTrackerState)
// DownloadConditionType represents the Torrent is under downloading.
DownloadConditionType = string(DownloadTrackerState)
// ReadyConditionType represents the Torrent is downloaded successfully.
Expand All @@ -122,8 +146,8 @@ const (
type TorrentStatus struct {
// Conditions represents the Torrent condition.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Files tracks the files belong to the source.
Files []FileTracker `json:"files,omitempty"`
// Repo tracks the objects belong to the source.
Repo *RepoStatus `json:"repo,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
143 changes: 110 additions & 33 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a701c53

Please sign in to comment.