Skip to content

Commit

Permalink
feat: graceful group member change (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxh326 authored Dec 10, 2024
1 parent 15326cc commit b0a1f5c
Show file tree
Hide file tree
Showing 16 changed files with 940 additions and 164 deletions.
40 changes: 36 additions & 4 deletions api/v1/cachegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,32 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

type CacheDirType string

var (
CacheDirTypeHostPath CacheDirType = "HostPath"
CacheDirTypePVC CacheDirType = "PVC"
)

type CacheDir struct {
// +kubebuilder:validation:Enum=HostPath;PVC
Type CacheDirType `json:"type,omitempty"`
// required for HostPath type
// +optional
Path string `json:"path,omitempty"`
// required for PVC type
// +optional
Name string `json:"name,omitempty"`
}

// CacheGroupWorkerTemplate defines cache group worker template
type CacheGroupWorkerTemplate struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
HostNetwork *bool `json:"hostNetwork,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
CacheDirs []CacheDir `json:"cacheDirs,omitempty"`

// Container image.
// More info: https://kubernetes.io/docs/concepts/containers/images
Expand Down Expand Up @@ -121,6 +140,14 @@ type CacheGroupSpec struct {
CleanCache bool `json:"cleanCache,omitempty"`
CacheGroup string `json:"cacheGroup,omitempty"`
Worker CacheGroupWorkerSpec `json:"worker,omitempty"`
// Duration for new node to join cluster with group-backup option
// Default is 10 minutes
// +optional
BackupDuration *metav1.Duration `json:"backupDuration,omitempty"`
// Maximum time to wait for data migration when deleting
// Default is 1 hour
// +optional
WaitingDeletedMaxDuration *metav1.Duration `json:"waitingDeletedMaxDuration,omitempty"`
}

type CacheGroupPhase string
Expand All @@ -145,17 +172,22 @@ type CacheGroupStatus struct {
Phase CacheGroupPhase `json:"phase,omitempty"`
Conditions []CacheGroupCondition `json:"conditions,omitempty"`

ReadyWorker int32 `json:"readyWorker,omitempty"`
ExpectWorker int32 `json:"expectWorker,omitempty"`
ReadyStr string `json:"readyStr,omitempty"`
CacheGroup string `json:"cacheGroup,omitempty"`
FileSystem string `json:"fileSystem,omitempty"`
ReadyWorker int32 `json:"readyWorker,omitempty"`
BackUpWorker int32 `json:"backUpWorker,omitempty"`
WaitingDeletedWorker int32 `json:"waitingDeletedWorker,omitempty"`
ExpectWorker int32 `json:"expectWorker,omitempty"`
ReadyStr string `json:"readyStr,omitempty"`
CacheGroup string `json:"cacheGroup,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=cg
// +kubebuilder:printcolumn:name="Cache Group",type="string",JSONPath=".status.cacheGroup"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Back up",type="string",JSONPath=".status.backUpWorker"
// +kubebuilder:printcolumn:name="Waiting Deleted",type="string",JSONPath=".status.WaitingDeletedWorker"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.readyStr"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// CacheGroup is the Schema for the cachegroups API
Expand Down
31 changes: 31 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

46 changes: 46 additions & 0 deletions config/crd/bases/juicefs.io_cachegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ spec:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.backUpWorker
name: Back up
type: string
- jsonPath: .status.WaitingDeletedWorker
name: Waiting Deleted
type: string
- jsonPath: .status.readyStr
name: Ready
type: string
Expand All @@ -41,6 +47,8 @@ spec:
type: object
spec:
properties:
backupDuration:
type: string
cacheGroup:
type: string
cleanCache:
Expand Down Expand Up @@ -72,11 +80,27 @@ spec:
type:
type: string
type: object
waitingDeletedMaxDuration:
type: string
worker:
properties:
overwrite:
items:
properties:
cacheDirs:
items:
properties:
name:
type: string
path:
type: string
type:
enum:
- HostPath
- PVC
type: string
type: object
type: array
dnsPolicy:
type: string
env:
Expand Down Expand Up @@ -1471,6 +1495,20 @@ spec:
type: array
template:
properties:
cacheDirs:
items:
properties:
name:
type: string
path:
type: string
type:
enum:
- HostPath
- PVC
type: string
type: object
type: array
dnsPolicy:
type: string
env:
Expand Down Expand Up @@ -2862,6 +2900,9 @@ spec:
type: object
status:
properties:
backUpWorker:
format: int32
type: integer
cacheGroup:
type: string
conditions:
Expand All @@ -2883,13 +2924,18 @@ spec:
expectWorker:
format: int32
type: integer
fileSystem:
type: string
phase:
type: string
readyStr:
type: string
readyWorker:
format: int32
type: integer
waitingDeletedWorker:
format: int32
type: integer
type: object
type: object
served: true
Expand Down
42 changes: 15 additions & 27 deletions config/samples/v1_cachegroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: juicefs-secret
namespace: default
type: Opaque
stringData:
name: juicefs-xx
Expand All @@ -13,9 +14,14 @@ apiVersion: juicefs.io/v1
kind: CacheGroup
metadata:
name: cachegroup-sample
namespace: default
spec:
secretRef:
name: juicefs-secret
# Duration for new node to join cluster with group-backup option
backupDuration: "10m"
# Maximum time to wait for data migration when deleting
waitingDeletedMaxDuration: "1h"
updateStrategy:
# support:
# - RollingUpdate: default policy
Expand All @@ -36,36 +42,18 @@ spec:
limits:
cpu: 1
memory: 1Gi
cacheDirs:
- path: /var/jfsCache-0
type: HostPath
opts:
- cache-dir=/mnt/juicefs:/mnt/juicefs2:/mnt/juicefs3
volumeMounts:
- name: cachedir-0
mountPath: /mnt/juicefs
- name: cachedir-1
mountPath: /mnt/juicefs2
- name: cachedir-2
mountPath: /mnt/juicefs3
volumes:
- name: cachedir-0
hostPath:
path: /mnt/juicefs
- name: cachedir-1
hostPath:
path: /dev/sda/juicefs2
- name: cachedir-2
persistentVolumeClaim:
claimName: juicefs-cache-pvc
- group-weight=100
overwrite:
- nodes:
- k8s-03
opts:
- cache-dir=/mnt/juicefs
- group-weight=50
volumeMounts:
- name: cachedir-0
mountPath: /mnt/juicefs
volumes:
- name: cachedir-0
hostPath:
path: /mnt/juicefs

cacheDirs:
- path: /var/jfsCache-1
type: HostPath
- path: /var/jfsCache-2
type: HostPath
46 changes: 46 additions & 0 deletions dist/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ spec:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.backUpWorker
name: Back up
type: string
- jsonPath: .status.WaitingDeletedWorker
name: Waiting Deleted
type: string
- jsonPath: .status.readyStr
name: Ready
type: string
Expand All @@ -40,6 +46,8 @@ spec:
type: object
spec:
properties:
backupDuration:
type: string
cacheGroup:
type: string
cleanCache:
Expand Down Expand Up @@ -71,11 +79,27 @@ spec:
type:
type: string
type: object
waitingDeletedMaxDuration:
type: string
worker:
properties:
overwrite:
items:
properties:
cacheDirs:
items:
properties:
name:
type: string
path:
type: string
type:
enum:
- HostPath
- PVC
type: string
type: object
type: array
dnsPolicy:
type: string
env:
Expand Down Expand Up @@ -1470,6 +1494,20 @@ spec:
type: array
template:
properties:
cacheDirs:
items:
properties:
name:
type: string
path:
type: string
type:
enum:
- HostPath
- PVC
type: string
type: object
type: array
dnsPolicy:
type: string
env:
Expand Down Expand Up @@ -2861,6 +2899,9 @@ spec:
type: object
status:
properties:
backUpWorker:
format: int32
type: integer
cacheGroup:
type: string
conditions:
Expand All @@ -2882,13 +2923,18 @@ spec:
expectWorker:
format: int32
type: integer
fileSystem:
type: string
phase:
type: string
readyStr:
type: string
readyWorker:
format: int32
type: integer
waitingDeletedWorker:
format: int32
type: integer
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit b0a1f5c

Please sign in to comment.