Skip to content

Commit d0941d3

Browse files
committed
service name should be exposed
Signed-off-by: liuzhiqiang <923463801@qq.com>
1 parent 8cf9479 commit d0941d3

14 files changed

Lines changed: 262 additions & 61 deletions

api/v1alpha1/cacheruntimeclass_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type RuntimeTopology struct {
3939
}
4040

4141
type RuntimeMasterComponentDefinition struct {
42-
RuntimeComponentDefinition
42+
RuntimeComponentDefinition `json:",inline"`
4343

4444
// TODO: declared in RuntimeComponentDefinition, or add ComponentType(Master/Worker) in ExecutionCommonEntry.
4545

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/fluid/fluid/crds/data.fluid.io_cacheruntimeclasses.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,31 @@ spec:
34533453
type: array
34543454
type: object
34553455
type: object
3456+
executionEntries:
3457+
properties:
3458+
mountUFS:
3459+
properties:
3460+
command:
3461+
items:
3462+
type: string
3463+
type: array
3464+
timeout:
3465+
type: integer
3466+
required:
3467+
- command
3468+
type: object
3469+
reportSummary:
3470+
properties:
3471+
command:
3472+
items:
3473+
type: string
3474+
type: array
3475+
timeout:
3476+
type: integer
3477+
required:
3478+
- command
3479+
type: object
3480+
type: object
34563481
options:
34573482
additionalProperties:
34583483
type: string

config/crd/bases/data.fluid.io_cacheruntimeclasses.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,31 @@ spec:
34533453
type: array
34543454
type: object
34553455
type: object
3456+
executionEntries:
3457+
properties:
3458+
mountUFS:
3459+
properties:
3460+
command:
3461+
items:
3462+
type: string
3463+
type: array
3464+
timeout:
3465+
type: integer
3466+
required:
3467+
- command
3468+
type: object
3469+
reportSummary:
3470+
properties:
3471+
command:
3472+
items:
3473+
type: string
3474+
type: array
3475+
timeout:
3476+
type: integer
3477+
required:
3478+
- command
3479+
type: object
3480+
type: object
34563481
options:
34573482
additionalProperties:
34583483
type: string

pkg/ddc/cache/component/daemonset_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *DaemonSetManager) reconcileDaemonSet(ctx context.Context, component *co
5959
return err
6060
}
6161
// return if already created
62-
if ds != nil {
62+
if err == nil {
6363
return nil
6464
}
6565
// create the stateful set
@@ -111,12 +111,12 @@ func (s *DaemonSetManager) reconcileService(ctx context.Context, component *comm
111111
logger.Info("start to reconciling headless service")
112112

113113
svc := &corev1.Service{}
114-
err := s.client.Get(ctx, types.NamespacedName{Name: component.Name, Namespace: component.Namespace}, svc)
114+
err := s.client.Get(ctx, types.NamespacedName{Name: component.Service.Name, Namespace: component.Namespace}, svc)
115115
if err != nil && !apierrors.IsNotFound(err) {
116116
return err
117117
}
118118
// return if already created
119-
if svc != nil {
119+
if err == nil {
120120
return nil
121121
}
122122
svc = s.constructService(component)

pkg/ddc/cache/component/statefulset_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *StatefulSetManager) reconcileStatefulSet(ctx context.Context, component
5959
return err
6060
}
6161
// return if already created
62-
if sts != nil {
62+
if err == nil {
6363
return nil
6464
}
6565
// create the stateful set
@@ -95,7 +95,7 @@ func (s *StatefulSetManager) constructStatefulSet(component *common.CacheRuntime
9595
},
9696
},
9797
Spec: appsv1.StatefulSetSpec{
98-
ServiceName: component.Name,
98+
ServiceName: component.Service.Name,
9999
Replicas: &component.Replicas,
100100
Template: podTemplateSpec,
101101
PodManagementPolicy: appsv1.ParallelPodManagement,
@@ -114,12 +114,12 @@ func (s *StatefulSetManager) reconcileService(ctx context.Context, component *co
114114
logger.Info("start to reconciling headless service")
115115

116116
svc := &corev1.Service{}
117-
err := s.client.Get(ctx, types.NamespacedName{Name: component.Name, Namespace: component.Namespace}, svc)
117+
err := s.client.Get(ctx, types.NamespacedName{Name: component.Service.Name, Namespace: component.Namespace}, svc)
118118
if err != nil && !apierrors.IsNotFound(err) {
119119
return err
120120
}
121121
// return if already created
122-
if svc != nil {
122+
if err == nil {
123123
return nil
124124
}
125125
svc = s.constructService(component)

pkg/ddc/cache/engine/cm.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/fluid-cloudnative/fluid/pkg/common"
2323
"github.com/fluid-cloudnative/fluid/pkg/utils"
2424
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
25+
"github.com/pkg/errors"
2526
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
)
@@ -66,7 +67,7 @@ func (e *CacheEngine) createConfigMapInRuntimeClass(extraResources *datav1alpha1
6667
if err != nil {
6768
return err
6869
}
69-
if cm != nil {
70+
if cm == nil {
7071
err = kubeclient.CreateConfigMapWithOwner(e.Client, configMap.Name, e.namespace, configMap.Data, owner)
7172
if err != nil {
7273
return err
@@ -88,6 +89,9 @@ func (e *CacheEngine) createRuntimeValueConfigMap(runtime *datav1alpha1.CacheRun
8889
return nil
8990
}
9091
data, err := e.generateRuntimeConfigData(runtime)
92+
if err != nil {
93+
return errors.Wrap(err, "failed to generate runtime config")
94+
}
9195

9296
return kubeclient.CreateConfigMapWithOwner(e.Client, e.getRuntimeConfigConfigMapName(), e.namespace, data, owner)
9397
}
@@ -113,6 +117,7 @@ func (e *CacheEngine) generateRuntimeConfigData(runtime *datav1alpha1.CacheRunti
113117
Shared: m.Shared,
114118
Path: m.Path,
115119
}
120+
// TODO: 默认的加密项的处理?(挂载的形式到 Master 等 Pod 中?)安全性该如何考虑
116121
options, err := e.generateDatasetMountOptions(&m, dataset.Spec.SharedEncryptOptions, dataset.Spec.SharedOptions)
117122
if err != nil {
118123
return nil, err
@@ -153,8 +158,8 @@ func (e *CacheEngine) generateRuntimeConfigData(runtime *datav1alpha1.CacheRunti
153158
Options: utils.UnionMapsWithOverride(
154159
utils.UnionMapsWithOverride(runtimeClass.Topology.Worker.Options, runtime.Spec.Options), runtime.Spec.Worker.Options),
155160
}
156-
if runtimeClass.Topology.Master.Service.Headless != nil {
157-
config.Master.Service = common.CacheRuntimeComponentServiceConfig{
161+
if runtimeClass.Topology.Worker.Service.Headless != nil {
162+
config.Worker.Service = common.CacheRuntimeComponentServiceConfig{
158163
Name: GetComponentServiceName(e.name, common.ComponentTypeWorker),
159164
}
160165
}
@@ -167,8 +172,8 @@ func (e *CacheEngine) generateRuntimeConfigData(runtime *datav1alpha1.CacheRunti
167172
Options: utils.UnionMapsWithOverride(
168173
utils.UnionMapsWithOverride(runtimeClass.Topology.Client.Options, runtime.Spec.Options), runtime.Spec.Client.Options),
169174
}
170-
if runtimeClass.Topology.Master.Service.Headless != nil {
171-
config.Master.Service = common.CacheRuntimeComponentServiceConfig{
175+
if runtimeClass.Topology.Client.Service.Headless != nil {
176+
config.Client.Service = common.CacheRuntimeComponentServiceConfig{
172177
Name: GetComponentServiceName(e.name, common.ComponentTypeClient),
173178
}
174179
}
@@ -177,7 +182,8 @@ func (e *CacheEngine) generateRuntimeConfigData(runtime *datav1alpha1.CacheRunti
177182
b, _ := json.Marshal(config)
178183
data := map[string]string{
179184
// key can not be modified, will be mounted as a file using by runtime.
180-
"config.json": string(b),
185+
"runtime.json": string(b),
181186
}
182187
return data, nil
183188
}
189+

pkg/ddc/cache/engine/transform.go

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package engine
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2223
"github.com/fluid-cloudnative/fluid/pkg/common"
@@ -42,8 +43,11 @@ type TargetPathVolumeConfig struct {
4243
}
4344

4445
type RuntimeConfigVolumeConfig struct {
46+
// runtime config's config map defined by fluid
4547
RuntimeConfigVolume corev1.Volume
4648
RuntimeConfigVolumeMount corev1.VolumeMount
49+
// config map names defined in ClassRuntimeClass
50+
ExtraConfigMapNames map[string]bool
4751
}
4852

4953
func (e *CacheEngine) transform(dataset *datav1alpha1.Dataset, runtime *datav1alpha1.CacheRuntime, runtimeClass *datav1alpha1.CacheRuntimeClass) (*common.CacheRuntimeValue, error) {
@@ -61,7 +65,7 @@ func (e *CacheEngine) transform(dataset *datav1alpha1.Dataset, runtime *datav1al
6165
}
6266

6367
// get common config for transform components
64-
runtimeCommonConfig, err := e.transformComponentCommonConfig(runtime)
68+
runtimeCommonConfig, err := e.transformComponentCommonConfig(runtime, runtimeClass)
6569
if err != nil {
6670
return nil, err
6771
}
@@ -83,16 +87,16 @@ func (e *CacheEngine) transform(dataset *datav1alpha1.Dataset, runtime *datav1al
8387
return runtimeValue, nil
8488
}
8589

86-
func (e *CacheEngine) transformComponentCommonConfig(runtime *datav1alpha1.CacheRuntime) (*CacheRuntimeComponentCommonConfig, error) {
90+
func (e *CacheEngine) transformComponentCommonConfig(runtime *datav1alpha1.CacheRuntime, runtimeClass *datav1alpha1.CacheRuntimeClass) (*CacheRuntimeComponentCommonConfig, error) {
8791
config := &CacheRuntimeComponentCommonConfig{
8892
Owner: transformer.GenerateOwnerReferenceFromObject(runtime),
8993
}
90-
e.transformRuntimeConfigVolume(config)
94+
e.transformRuntimeConfigVolume(config, runtimeClass)
9195

9296
return config, nil
9397
}
9498

95-
func (e *CacheEngine) transformRuntimeConfigVolume(config *CacheRuntimeComponentCommonConfig) {
99+
func (e *CacheEngine) transformRuntimeConfigVolume(config *CacheRuntimeComponentCommonConfig, runtimeClass *datav1alpha1.CacheRuntimeClass) {
96100
// create the runtime config mount info
97101
volumeName := e.getRuntimeConfigVolumeName()
98102
config.RuntimeConfigs = &RuntimeConfigVolumeConfig{
@@ -112,9 +116,56 @@ func (e *CacheEngine) transformRuntimeConfigVolume(config *CacheRuntimeComponent
112116
ReadOnly: true,
113117
},
114118
}
119+
120+
if len(runtimeClass.ExtraResources.ConfigMaps) == 0 {
121+
return
122+
}
123+
config.RuntimeConfigs.ExtraConfigMapNames = map[string]bool{}
124+
// TODO: 当前,这些 configmap 当前需要 component 中定义使用,是否对于所有 component 是通用的?
125+
for _, cm := range runtimeClass.ExtraResources.ConfigMaps {
126+
config.RuntimeConfigs.ExtraConfigMapNames[cm.Name] = true
127+
}
115128
}
116129

117-
func (e *CacheEngine) addCommonConfigForComponent(commonConfig *CacheRuntimeComponentCommonConfig, component *common.CacheRuntimeComponentValue) {
118-
component.PodTemplateSpec.Spec.Volumes = append(component.PodTemplateSpec.Spec.Volumes, commonConfig.RuntimeConfigs.RuntimeConfigVolume)
119-
component.PodTemplateSpec.Spec.Containers[0].VolumeMounts = append(component.PodTemplateSpec.Spec.Containers[0].VolumeMounts, commonConfig.RuntimeConfigs.RuntimeConfigVolumeMount)
130+
func (e *CacheEngine) addCommonConfigForComponent(commonConfig *CacheRuntimeComponentCommonConfig, componentValue *common.CacheRuntimeComponentValue,
131+
componentDefinition *datav1alpha1.RuntimeComponentDefinition) error {
132+
componentValue.PodTemplateSpec.Spec.Volumes = append(componentValue.PodTemplateSpec.Spec.Volumes, commonConfig.RuntimeConfigs.RuntimeConfigVolume)
133+
134+
// assume the first container uses the runtime config
135+
componentValue.PodTemplateSpec.Spec.InitContainers[0].VolumeMounts = append(componentValue.PodTemplateSpec.Spec.InitContainers[0].VolumeMounts, commonConfig.RuntimeConfigs.RuntimeConfigVolumeMount)
136+
componentValue.PodTemplateSpec.Spec.Containers[0].VolumeMounts = append(componentValue.PodTemplateSpec.Spec.Containers[0].VolumeMounts, commonConfig.RuntimeConfigs.RuntimeConfigVolumeMount)
137+
138+
// other config maps defined in CacheRuntimeClass
139+
if componentDefinition.Dependencies.ExtraResources == nil {
140+
return nil
141+
}
142+
names := commonConfig.RuntimeConfigs.ExtraConfigMapNames
143+
for _, cm := range componentDefinition.Dependencies.ExtraResources.ConfigMaps {
144+
if names[cm.Name] == false {
145+
e.Log.Error(errors.New("component has undefined config map extra resource"), "type", componentValue.ComponentType, "configMapName", cm.Name)
146+
}
147+
componentValue.PodTemplateSpec.Spec.Volumes = append(componentValue.PodTemplateSpec.Spec.Volumes, corev1.Volume{
148+
Name: e.getRuntimeClassExtraConfigMapVolumeName(cm.Name),
149+
VolumeSource: corev1.VolumeSource{
150+
ConfigMap: &corev1.ConfigMapVolumeSource{
151+
LocalObjectReference: corev1.LocalObjectReference{
152+
Name: cm.Name,
153+
},
154+
},
155+
},
156+
})
157+
componentValue.PodTemplateSpec.Spec.InitContainers[0].VolumeMounts = append(componentValue.PodTemplateSpec.Spec.InitContainers[0].VolumeMounts,
158+
corev1.VolumeMount{
159+
Name: e.getRuntimeClassExtraConfigMapVolumeName(cm.Name),
160+
MountPath: cm.MountPath,
161+
ReadOnly: true,
162+
})
163+
componentValue.PodTemplateSpec.Spec.Containers[0].VolumeMounts = append(componentValue.PodTemplateSpec.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
164+
Name: e.getRuntimeClassExtraConfigMapVolumeName(cm.Name),
165+
MountPath: cm.MountPath,
166+
ReadOnly: true,
167+
})
168+
}
169+
return nil
120170
}
171+

0 commit comments

Comments
 (0)