1717package engine
1818
1919import (
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
4445type 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
4953func (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