Skip to content

Commit 8cf9479

Browse files
committed
init poc, add prepare ufs
Signed-off-by: xliuqq <xlzq1992@gmail.com>
1 parent 1c1d870 commit 8cf9479

41 files changed

Lines changed: 2160 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/v1alpha1/cacheruntimeclass_types.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
type RuntimeTopology struct {
2828
// Master is the configuration for master component
2929
// +optional
30-
Master *RuntimeComponentDefinition `json:"master,omitempty"`
30+
Master *RuntimeMasterComponentDefinition `json:"master,omitempty"`
3131

3232
// Worker is the configuration for worker component
3333
// +optional
@@ -38,6 +38,32 @@ type RuntimeTopology struct {
3838
Client *RuntimeComponentDefinition `json:"client,omitempty"`
3939
}
4040

41+
type RuntimeMasterComponentDefinition struct {
42+
RuntimeComponentDefinition
43+
44+
// TODO: declared in RuntimeComponentDefinition, or add ComponentType(Master/Worker) in ExecutionCommonEntry.
45+
46+
// ExecutionEntries entries for Master Pod to support out-of-tree integration.
47+
// +optional
48+
ExecutionEntries *ExecutionEntries `json:"executionEntries,omitempty"`
49+
}
50+
51+
type ExecutionEntries struct {
52+
// MountUFS defines the operations for mounting UFS
53+
MountUFS *ExecutionCommonEntry `json:"mountUFS,omitempty"`
54+
55+
// ReportSummary it defines the operation how to get cache status like capacity, hit ratio etc.
56+
ReportSummary *ExecutionCommonEntry `json:"reportSummary,omitempty"`
57+
}
58+
59+
type ExecutionCommonEntry struct {
60+
// 执行的命令,必选,会在 Master Pod 中执行
61+
Command []string `json:"command"`
62+
63+
// 执行命令的超时时间(单位:秒),默认(最小值)为 5s.
64+
Timeout int `json:"timeout,omitempty"`
65+
}
66+
4167
// RuntimeComponentDefinition defines the configuration for a CacheRuntime component
4268
type RuntimeComponentDefinition struct {
4369
// WorkloadType is the default workload type of the component

charts/fluid/fluid/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ image:
1212
imagePullSecrets: []
1313

1414
# Default registry, namespace and version tag for images managed by fluid
15-
imagePrefix: &defaultImagePrefix fluidcloudnative
15+
imagePrefix: &defaultImagePrefix registry.cn-hangzhou.aliyuncs.com/xliu1992
1616
# imagePrefix: &defaultImagePrefix registry.aliyuncs.com/fluid
17-
version: &defaultVersion v1.1.0-b457855
17+
version: &defaultVersion v1.1.0-b0bdac58
1818

1919
crdUpgrade:
2020
enabled: true

docker/Dockerfile.cacheruntime

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Build the cacheruntime-controller manager binary
22
# golang:1.24.12-bookworm
3-
FROM golang:1.24.12-bookworm@sha256:1c64c586e1cf9dc4c394c5896ec574659c792a0840f4fa0eb54a88de146e978b as builder
3+
# FROM golang:1.24.12-bookworm@sha256:1c64c586e1cf9dc4c394c5896ec574659c792a0840f4fa0eb54a88de146e978b as builder
4+
FROM registry.cn-hangzhou.aliyuncs.com/xliu1992/golang:1.24.12-bookworm as builder
45

56
WORKDIR /go/src/github.com/fluid-cloudnative/fluid
67
COPY . .
@@ -11,16 +12,20 @@ RUN make cacheruntime-controller-build && \
1112
RUN bash hack/helm/pin_runtime_chart_version.sh "${FLUID_VERSION}"
1213

1314
# alpine:3.20.6
14-
FROM alpine:3.20.6@sha256:de4fe7064d8f98419ea6b49190df1abbf43450c1702eeb864fe9ced453c1cc5f
15-
RUN apk add --update bash curl wget iproute2 libc6-compat tzdata vim && \
16-
rm -rf /var/cache/apk/* && \
17-
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
18-
echo "Asia/Shanghai" > /etc/timezone
15+
# FROM alpine:3.20.6@sha256:de4fe7064d8f98419ea6b49190df1abbf43450c1702eeb864fe9ced453c1cc5f
16+
FROM registry.cn-hangzhou.aliyuncs.com/xliu1992/alpine:3.20.6
17+
18+
#RUN apk add --update bash curl wget iproute2 libc6-compat tzdata vim && \
19+
# rm -rf /var/cache/apk/* && \
20+
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
21+
# echo "Asia/Shanghai" > /etc/timezone
1922

2023
ARG TARGETARCH
2124
ARG HELM_VERSION
22-
RUN wget -O helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz https://github.com/fluid-cloudnative/helm/releases/download/${HELM_VERSION}/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz && \
23-
tar -xvf helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz && \
25+
#RUN wget -O helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz https://github.com/fluid-cloudnative/helm/releases/download/${HELM_VERSION}/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz && \
26+
COPY helm-v3.19.5-linux-amd64.tar.gz .
27+
28+
RUN tar -xvf helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz && \
2429
mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \
2530
chmod u+x /usr/local/bin/ddc-helm && \
2631
rm -f helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz && \
@@ -32,5 +37,3 @@ COPY --from=builder /go/bin/cacheruntime-controller /usr/local/bin/cacheruntime-
3237
RUN chmod -R u+x /usr/local/bin/
3338

3439
CMD ["cacheruntime-controller", "start"]
35-
36-

docker/Dockerfile.dataset

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Build the dataset-controller manager binary
22
# golang:1.24.12-bookworm
3-
FROM golang:1.24.12-bookworm@sha256:1c64c586e1cf9dc4c394c5896ec574659c792a0840f4fa0eb54a88de146e978b as builder
3+
#FROM golang:1.24.12-bookworm@sha256:1c64c586e1cf9dc4c394c5896ec574659c792a0840f4fa0eb54a88de146e978b as builder
4+
FROM registry.cn-hangzhou.aliyuncs.com/xliu1992/golang:1.24.12-bookworm as builder
45

56
WORKDIR /go/src/github.com/fluid-cloudnative/fluid
67
COPY . .
@@ -14,11 +15,13 @@ RUN bash hack/helm/pin_runtime_chart_version.sh "${FLUID_VERSION}"
1415
# RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
1516

1617
# alpine:3.23.3
17-
FROM alpine:3.23.3@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659
18-
RUN apk add --update bash curl wget iproute2 libc6-compat tzdata vim && \
19-
rm -rf /var/cache/apk/* && \
20-
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
21-
echo "Asia/Shanghai" > /etc/timezone
18+
FROM registry.cn-hangzhou.aliyuncs.com/xliu1992/alpine:3.20.6
19+
20+
#FROM alpine:3.23.3@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659
21+
#RUN apk add --update bash curl wget iproute2 libc6-compat tzdata vim && \
22+
# rm -rf /var/cache/apk/* && \
23+
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
24+
# echo "Asia/Shanghai" > /etc/timezone
2225

2326
ARG TARGETARCH
2427
ARG HELM_VERSION

pkg/common/cacheruntime.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package common
1818

19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
1924
type ComponentType string
2025

2126
const (
@@ -24,12 +29,71 @@ const (
2429
CacheEngineImpl = CacheRuntime
2530
)
2631

32+
const (
33+
ComponentTypeMaster ComponentType = "master"
34+
ComponentTypeWorker ComponentType = "worker"
35+
ComponentTypeClient ComponentType = "client"
36+
)
37+
2738
type CacheRuntimeValue struct {
39+
// RuntimeIdentity is used to identify the runtime (name/namespace)
40+
RuntimeIdentity RuntimeIdentity `json:"runtimeIdentity"`
41+
2842
Master *CacheRuntimeComponentValue `json:"master,omitempty"`
2943
Worker *CacheRuntimeComponentValue `json:"worker,omitempty"`
3044
Client *CacheRuntimeComponentValue `json:"client,omitempty"`
3145
}
3246

47+
// CacheRuntimeComponentValue is the common value for building CacheRuntimeValue.
3348
type CacheRuntimeComponentValue struct {
34-
Enabled bool `json:"enabled"`
49+
// Component name, not Runtime name
50+
Name string
51+
Namespace string
52+
Enabled bool
53+
WorkloadType metav1.TypeMeta
54+
Replicas int32
55+
PodTemplateSpec corev1.PodTemplateSpec
56+
Owner *OwnerReference
57+
ComponentType ComponentType `json:"componentType,omitempty"`
58+
59+
// Service name, can be not same as Component name
60+
Service *CacheRuntimeComponentServiceConfig
61+
}
62+
63+
// CacheRuntimeConfig defines the config of runtime, will be auto mounted by configmap in the component pod.
64+
type CacheRuntimeConfig struct {
65+
// Mounts from Dataset Spec
66+
Mounts []MountConfig `json:"mounts,omitempty"`
67+
// AccessModes from Dataset Spec
68+
AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"`
69+
// fuse mount path, used in Worker or Client Pod according to Topology.
70+
TargetPath string `json:"targetPath,omitempty"`
71+
72+
Master *CacheRuntimeComponentConfig `json:"master,omitempty"`
73+
Worker *CacheRuntimeComponentConfig `json:"worker,omitempty"`
74+
Client *CacheRuntimeComponentConfig `json:"client,omitempty"`
75+
}
76+
77+
// MountConfig defines the mount config about dataset Mounts
78+
type MountConfig struct {
79+
MountPoint string `json:"mountPoint"`
80+
// TODO: separate encrypt options with mount files for security
81+
Options map[string]string `json:"options,omitempty"`
82+
Name string `json:"name,omitempty"`
83+
Path string `json:"path,omitempty"`
84+
ReadOnly bool `json:"readOnly,omitempty"`
85+
Shared bool `json:"shared,omitempty"`
86+
}
87+
88+
type CacheRuntimeComponentConfig struct {
89+
Enabled bool `json:"enabled,omitempty"`
90+
Name string `json:"name,omitempty"`
91+
Options map[string]string `json:"options,omitempty"`
92+
Replicas int32 `json:"replicas,omitempty"`
93+
94+
Service CacheRuntimeComponentServiceConfig `json:"service,omitempty"`
95+
}
96+
97+
type CacheRuntimeComponentServiceConfig struct {
98+
Name string `json:"name"`
3599
}

pkg/common/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ const (
184184
PodRoleType = "role"
185185
DataloadPod = "dataload-pod"
186186
NamespaceFluidSystem = "fluid-system"
187+
188+
DefaultNameSpace = "default"
187189
)
188190

189191
const (

pkg/common/label.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ const (
146146
UpdateLabel OperationType = "UpdateValue"
147147
)
148148

149+
// label and annotations for cacheRuntime
150+
const (
151+
CacheRuntimeLabelAnnotationPrefix = "cacheruntime." + LabelAnnotationPrefix
152+
153+
LabelCacheRuntimeName = CacheRuntimeLabelAnnotationPrefix + "name"
154+
155+
LabelCacheRuntimeComponentName = CacheRuntimeLabelAnnotationPrefix + "component-name"
156+
)
157+
149158
// LabelToModify modifies the labelKey in operationType.
150159
type LabelToModify struct {
151160
labelKey string

pkg/ddc/base/runtime.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func convertToTieredstoreInfo(tieredstore datav1alpha1.TieredStore) (TieredStore
433433
return tieredstoreInfo, nil
434434
}
435435

436-
// GetRuntimeInfo gets the RuntimeInfo according to name and namespace of it
436+
// GetRuntimeInfo gets the RuntimeInfo according to name and namespace of it, must be called after dataset bound.
437437
func GetRuntimeInfo(reader client.Reader, name, namespace string) (runtimeInfo RuntimeInfoInterface, err error) {
438438
dataset, err := utils.GetDataset(reader, name, namespace)
439439
if err != nil {
@@ -574,6 +574,8 @@ func GetRuntimeInfo(reader client.Reader, name, namespace string) (runtimeInfo R
574574
}
575575
runtimeInfo.SetFuseNodeSelector(cacheRuntime.Spec.Client.NodeSelector)
576576
runtimeInfo.SetupFuseCleanPolicy(cacheRuntime.Spec.Client.CleanPolicy)
577+
// TODO(cache runtime): is this common logic for all runtimes? If so, move to below 'SetOwnerDatasetUID' line.
578+
runtimeInfo.SetupWithDataset(dataset)
577579
default:
578580
err = fmt.Errorf("fail to get runtimeInfo for runtime type: %s", runtimeType)
579581
return
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2026 The Fluid 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 component
18+
19+
import (
20+
"context"
21+
"github.com/fluid-cloudnative/fluid/api/v1alpha1"
22+
"github.com/fluid-cloudnative/fluid/pkg/common"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/client"
26+
)
27+
28+
type ComponentManager interface {
29+
Reconciler(ctx context.Context, component *common.CacheRuntimeComponentValue) error
30+
ConstructComponentStatus(todo context.Context, value *common.CacheRuntimeComponentValue) (v1alpha1.RuntimeComponentStatus, error)
31+
}
32+
33+
func NewComponentHelper(workloadType metav1.TypeMeta, scheme *runtime.Scheme, client client.Client) ComponentManager {
34+
if workloadType.APIVersion == "apps/v1" {
35+
if workloadType.Kind == "StatefulSet" {
36+
return newStatefulSetManager(scheme, client)
37+
} else if workloadType.Kind == "DaemonSet" {
38+
return newDaemonSetManager(scheme, client)
39+
}
40+
}
41+
42+
return newStatefulSetManager(scheme, client)
43+
}
44+
45+
// getCommonLabelsFromComponent returns the common labels for component used for stateful
46+
func getCommonLabelsFromComponent(component *common.CacheRuntimeComponentValue) map[string]string {
47+
// These labels are used as sts.spec.selector which cannot be updated.
48+
// If changed, may cause all exist runtime failed.
49+
return map[string]string{
50+
common.LabelCacheRuntimeName: component.Owner.Name,
51+
// format: runtimeName-componentType
52+
common.LabelCacheRuntimeComponentName: component.Name,
53+
}
54+
}

0 commit comments

Comments
 (0)